Related projects¶
xplot if the C++ backend for the bqplot 2-D plotting library
C++ code
#include <algorithm>
#include <random>
#include <vector>
#include "xwidgets/xbox.hpp"
#include "xplot/xtoolbar.hpp"
#include "xplot/xfigure.hpp"
#include "xplot/xmarks.hpp"
#include "xplot/xaxes.hpp"
auto randn(std::size_t n)
{
std::vector<double> output(n);
std::random_device rd;
std::mt19937 gen(rd());
std::normal_distribution<> dis(5, 2);
std::for_each(output.begin(), output.end(), [&dis, &gen](auto& v){v = dis(gen);});
return output;
}
std::size_t data_size = 200;
std::vector<double> data_x(data_size);
std::iota(data_x.begin(), data_x.end(), 0);
std::vector<double> data_y = randn(data_size);
std::vector<double> data_c = randn(data_size);
xpl::linear_scale scale_x, scale_y;
xpl::linear_scale scale_size;
auto scatter = xpl::scatter::initialize(scale_x, scale_y, scale_size)
.x(data_x)
.y(data_y)
.size(data_c)
.stroke("black")
.default_size(128)
.enable_move(true)
.colors(std::vector<xtl::xoptional<std::string>>{"orangered"})
.finalize();
xpl::axis axis_x(scale_x), axis_y(scale_y);
axis_x.label = "x";
axis_y.label = "y";
axis_y.orientation = "vertical";
axis_y.side = "left";
xpl::figure fig;
fig.padding_x = 0.025;
fig.add_mark(scatter);
fig.add_axis(axis_x);
fig.add_axis(axis_y);
xpl::toolbar tb(fig);
xw::vbox b = xw::vbox::initialize()
.children({fig, tb})
.finalize();
b
Output
xleaflet is the C++ backend for the leaflet maps visualization library. The Python reference implementation is available in the ipyleaflet project
C++ code
#include "xwidgets/xhtml.hpp"
#include "xleaflet/xmap.hpp"
#include "xleaflet/xmarker.hpp"
auto html = xw::html::initialize()
.value("Hello from an <b>xwidget</b> in an <b>xmarker</b>!")
.finalize();
std::array<double, 2> center = {52.204793, 360.121558};
auto map = xlf::map::initialize()
.center(center)
.zoom(15)
.finalize();
auto marker = xlf::marker::initialize()
.location(center)
.draggable(false)
.popup(html)
.finalize();
map.add_layer(marker);
map
Output
xproperty is the C++ implementation of the observer pattern underlying
xwidgets
. It is to xwidgets
what the traitlets project is to
ipywidgets
.