2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
5 #include "bbwtPackage.h"
8 #include <Wt/WStandardItemModel>
9 #include <Wt/WContainerWidget>
17 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Chart)
18 BBTK_BLACK_BOX_IMPLEMENTATION(Chart,bbtk::WtBlackBox);
20 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
26 int lstSize = bbGetInputlstX().size();
27 Wt::WStandardItemModel *model = new Wt::WStandardItemModel(lstSize, 2, bbGetOutputWidget() );
28 model->setHeaderData(0, Wt::WString("X"));
29 model->setHeaderData(1, Wt::WString("Y = cos(X)"));
31 for (unsigned i = 0; i < lstSize; ++i) {
32 // double x = (static_cast<double>(i) - 20) / 4;
34 model->setData(i, 0, bbGetInputlstX()[i] );
35 model->setData(i, 1, bbGetInputlstY()[i]);
38 chart->setModel(model);
39 Wt::Chart::WDataSeries s(1, Wt::Chart::CurveSeries);
40 s.setShadow(Wt::WShadow(3, 3, Wt::WColor(0, 0, 0, 127), 3));
45 Wt::WStandardItemModel *model = new Wt::WStandardItemModel(40, 2, bbGetOutputWidget() );
46 model->setHeaderData(0, Wt::WString("X"));
47 model->setHeaderData(1, Wt::WString("Y = cos(X)"));
49 for (unsigned i = 0; i < 40; ++i) {
50 double x = (static_cast<double>(i) - 20) / 4;
52 model->setData(i, 0, x);
53 model->setData(i, 1, std::cos(x));
56 chart->setModel(model);
57 Wt::Chart::WDataSeries s(2, Wt::Chart::CurveSeries);
58 s.setShadow(Wt::WShadow(3, 3, Wt::WColor(0, 0, 255, 127), 3));
63 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
65 void Chart::CreateWidget(Wt::WContainerWidget* parent)
68 Wt::WContainerWidget *container = new Wt::WContainerWidget( parent );
71 Wt::WStandardItemModel *model = new Wt::WStandardItemModel(40, 2, container);
72 model->setHeaderData(0, Wt::WString("X"));
73 model->setHeaderData(1, Wt::WString("Y = sin(X)"));
75 for (unsigned i = 0; i < 40; ++i) {
76 double x = (static_cast<double>(i) - 20) / 4;
78 model->setData(i, 0, x);
79 model->setData(i, 1, std::sin(x));
83 * Create the scatter plot.
85 chart = new Wt::Chart::WCartesianChart(container);
86 chart->setModel(model); // Set the model.
87 chart->setXSeriesColumn(0); // Set the column that holds the X data.
88 chart->setLegendEnabled(true); // Enable the legend.
90 chart->setType(Wt::Chart::ScatterPlot); // Set type to ScatterPlot.
92 // Typically, for mathematical functions, you want the axes to cross
94 chart->axis(Wt::Chart::XAxis).setLocation(Wt::Chart::ZeroValue);
95 chart->axis(Wt::Chart::YAxis).setLocation(Wt::Chart::ZeroValue);
97 // Provide space for the X and Y axis and title.
98 chart->setPlotAreaPadding(80, Wt::Left);
99 chart->setPlotAreaPadding(40, Wt::Top | Wt::Bottom);
102 Wt::Chart::WDataSeries s(1, Wt::Chart::CurveSeries);
103 s.setShadow(Wt::WShadow(3, 3, Wt::WColor(0, 0, 0, 127), 3));
106 chart->resize(800, 300); // WPaintedWidget must be given explicit size.
108 chart->setMargin(10, Wt::Top | Wt::Bottom); // Add margin vertically
109 chart->setMargin(Wt::WLength::Auto, Wt::Left | Wt::Right); // Center horizontally
112 Wt::WTimer *t = new Wt::WTimer(chart);
116 double *phi = new double(0);
117 t->timeout().connect(std::bind([=] () {
120 for (unsigned i = 0; i < 40; ++i) {
121 double x = (static_cast<double>(i) - 20) / 4;
123 model->setData(i, 0, x);
124 model->setData(i, 1, std::sin(x + *phi));
129 bbSetOutputWidget( container );
136 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
138 void Chart::bbUserSetDefaultValues()
143 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
145 void Chart::bbUserInitializeProcessing()
150 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
152 void Chart::bbUserFinalizeProcessing()