Plot2d
 All Classes Functions
plot2d.h
1 #include <nana/gui.hpp>
2 #include <nana/gui/widgets/label.hpp>
3 #include <nana/gui.hpp>
4 
5 namespace nana
6 {
7 namespace plot
8 {
9 class plot;
10 
12 class trace
13 {
14 public:
15 
22  : myType( eType::plot )
23  {
24 
25  }
31  void realTime( int w )
32  {
33  myType = eType::realtime;
34  myRealTimeNext = 0;
35  myY.clear();
36  myY.resize( w );
37  }
38 
40  void points()
41  {
42  myType = eType::point;
43  myY.clear();
44  myX.clear();
45  }
46 
54  void set( const std::vector< double >& y );
55 
62  void add( double y );
63 
72  void add( double x, double y );
73 
75  void color( const colors & clr )
76  {
77  myColor = clr;
78  }
79 
81  void Plot( plot * p )
82  {
83  myPlot = p;
84  }
85 
86  int size()
87  {
88  return (int) myY.size();
89  }
90 
91  void bounds( int& min, int& max );
92 
94  void update( paint::graphics& graph );
95 
96 private:
97  plot * myPlot;
98  std::vector< double > myX;
99  std::vector< double > myY;
100  colors myColor;
101  int myRealTimeNext;
102  enum class eType
103  {
104  plot,
105  realtime,
106  point
107  } myType;
108 };
114 class axis
115 {
116 public:
117  axis( plot * p );
118 
119  ~axis()
120  {
121  delete myLabelMin;
122  delete myLabelMax;
123  }
124 
126  void update( paint::graphics& graph );
127 
128 private:
129  plot * myPlot;
130  label * myLabelMin;
131  label * myLabelMax;
132 };
133 
134 
136 class plot
137 {
138 public:
139 
143  plot( window parent );
144 
145  ~plot()
146  {
147  delete myAxis;
148  }
149 
157  {
158  trace * t = new trace();
159  t->Plot( this );
160  myTrace.push_back( t );
161  return *t;
162  }
163 
173  {
174  trace * t = new trace();
175  t->Plot( this );
176  t->realTime( w );
177  myTrace.push_back( t );
178  return *t;
179  }
180 
187  trace& AddPointTrace();
188 
189  int Y2Pixel( double y ) const
190  {
191  return myYOffset - myScale * y;
192  }
193 
194  float xinc()
195  {
196  return myXinc;
197  }
198  int minY()
199  {
200  return myMinY;
201  }
202  int maxY()
203  {
204  return myMaxY;
205  }
206  double Scale()
207  {
208  return myScale;
209  }
210  int XOffset()
211  {
212  return myXOffset;
213  }
214  int YOffset()
215  {
216  return myYOffset;
217  }
218  window parent()
219  {
220  return myParent;
221  }
222 
223  void update()
224  {
225  API::refresh_window( myParent );
226  }
227 
228  void debug()
229  {
230  for( auto t : myTrace )
231  {
232  std::cout << "debugtsize " << t->size() << "\n";
233  }
234  }
235 
236 private:
237 
239  window myParent;
240 
241  axis * myAxis;
242 
244  std::vector< trace* > myTrace;
245 
246  float myXinc;
247  int myMinY, myMaxY;
248  double myScale;
249  int myXOffset;
250  int myYOffset;
251 
256  void CalcScale( int w, int h );
257 
259  void RegisterDrawingFunction();
260 
261 };
262 
263 }
264 }
Draw decorated vertical line on LHS of plot for Y-axis.
Definition: plot2d.h:114
Single trace to be plotted.
Definition: plot2d.h:12
void update(paint::graphics &graph)
draw
Definition: plot2d.cpp:241
void points()
Definition: plot2d.h:40
Draw a 2D plot.
Definition: plot2d.h:136
void realTime(int w)
Definition: plot2d.h:31
void color(const colors &clr)
set color
Definition: plot2d.h:75
void update(paint::graphics &graph)
draw
Definition: plot2d.cpp:135
void add(double y)
Definition: plot2d.cpp:99
void set(const std::vector< double > &y)
Definition: plot2d.cpp:87
plot(window parent)
Definition: plot2d.cpp:9
trace & AddStaticTrace()
Add static trace.
Definition: plot2d.h:156
trace()
Definition: plot2d.h:21
trace & AddPointTrace()
Add point trace.
Definition: plot2d.cpp:17
trace & AddRealTimeTrace(int w)
Add real time trace.
Definition: plot2d.h:172
void Plot(plot *p)
set plot where this trace will appear
Definition: plot2d.h:81