]> Creatis software - creaWT.git/blob - wt/bbtk_wt_PKG/src/bbwtChart.cxx
bugs wt xtk
[creaWT.git] / wt / bbtk_wt_PKG / src / bbwtChart.cxx
1 //===== 
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)
3 //===== 
4 #include "bbwtChart.h"
5 #include "bbwtPackage.h"
6
7
8 #include <Wt/WStandardItemModel>
9 #include <Wt/WContainerWidget>
10 #include <Wt/WTimer>
11 #include <cmath>
12
13
14 namespace bbwt
15 {
16
17 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,Chart)
18 BBTK_BLACK_BOX_IMPLEMENTATION(Chart,bbtk::WtBlackBox);
19 //===== 
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)
21 //===== 
22 void Chart::Process()
23 {
24
25 /*
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)"));
30
31         for (unsigned i = 0; i < lstSize; ++i) {
32 //          double x = (static_cast<double>(i) - 20) / 4;
33
34             model->setData(i, 0,  bbGetInputlstX()[i] );
35             model->setData(i, 1, bbGetInputlstY()[i]);
36         }
37
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));
41         chart->addSeries(s);
42 */
43
44
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)"));
48
49         for (unsigned i = 0; i < 40; ++i) {
50             double x = (static_cast<double>(i) - 20) / 4;
51
52             model->setData(i, 0, x);
53             model->setData(i, 1, std::cos(x));
54         }
55
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));
59         chart->addSeries(s);
60
61 }
62 //===== 
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)
64 //===== 
65 void Chart::CreateWidget(Wt::WContainerWidget* parent)
66 {
67
68    Wt::WContainerWidget *container = new Wt::WContainerWidget( parent );
69    
70
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)"));
74
75         for (unsigned i = 0; i < 40; ++i) {
76             double x = (static_cast<double>(i) - 20) / 4;
77
78             model->setData(i, 0, x);
79             model->setData(i, 1, std::sin(x));
80         }
81
82         /*
83          * Create the scatter plot.
84          */
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.
89
90         chart->setType(Wt::Chart::ScatterPlot);   // Set type to ScatterPlot.
91
92         // Typically, for mathematical functions, you want the axes to cross
93         // at the 0 mark:
94         chart->axis(Wt::Chart::XAxis).setLocation(Wt::Chart::ZeroValue);
95         chart->axis(Wt::Chart::YAxis).setLocation(Wt::Chart::ZeroValue);
96
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);
100
101         // Add the curves
102         Wt::Chart::WDataSeries s(1, Wt::Chart::CurveSeries);
103         s.setShadow(Wt::WShadow(3, 3, Wt::WColor(0, 0, 0, 127), 3));
104         chart->addSeries(s);
105
106         chart->resize(800, 300); // WPaintedWidget must be given explicit size.
107
108         chart->setMargin(10, Wt::Top | Wt::Bottom);            // Add margin vertically
109         chart->setMargin(Wt::WLength::Auto, Wt::Left | Wt::Right); // Center horizontally
110 /*
111
112         Wt::WTimer *t = new Wt::WTimer(chart);
113         t->setInterval(25);
114         t->start();
115
116         double *phi = new double(0);
117         t->timeout().connect(std::bind([=] () {
118           *phi += 0.1;
119
120           for (unsigned i = 0; i < 40; ++i) {
121             double x = (static_cast<double>(i) - 20) / 4;
122
123             model->setData(i, 0, x);
124             model->setData(i, 1, std::sin(x + *phi));
125           }      
126             }));
127 */
128
129    bbSetOutputWidget( container );
130   // Process();
131
132
133   
134 }
135 //===== 
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)
137 //===== 
138 void Chart::bbUserSetDefaultValues()
139 {
140
141 }
142 //===== 
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)
144 //===== 
145 void Chart::bbUserInitializeProcessing()
146 {
147
148 }
149 //===== 
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)
151 //===== 
152 void Chart::bbUserFinalizeProcessing()
153 {
154
155 }
156 }
157 // EO namespace bbwt
158
159