Version: 0.6.0
axis.h
1 // Name: axis.h
3 // Purpose: axis base class declarations
4 // Author: Moskvichev Andrey V.
5 // Created: 2008/11/07
6 // Copyright: (c) 2008-2010 Moskvichev Andrey V.
7 // Licence: wxWidgets licence
9 
10 #ifndef AXIS_H_
11 #define AXIS_H_
12 
13 #include <wx/wxfreechartdefs.h>
14 #include <wx/dataset.h>
15 
16 #include <wx/dynarray.h>
17 
18 #include <wx/drawobject.h>
19 #include <wx/observable.h>
20 
21 enum AXIS_LOCATION {
22  AXIS_LEFT = 1,
23  AXIS_RIGHT,
24  AXIS_TOP,
25  AXIS_BOTTOM,
26 };
27 
28 class WXDLLIMPEXP_FREECHART Axis;
29 
33 class WXDLLIMPEXP_FREECHART AxisObserver
34 {
35 public:
36  AxisObserver();
37  virtual ~AxisObserver();
38 
43  virtual void AxisChanged(Axis *axis) = 0;
44 
49  virtual void BoundsChanged(Axis *axis) = 0;
50 };
51 
62 class WXDLLIMPEXP_FREECHART Axis : public wxObject, public Observable<AxisObserver>
63 {
64  DECLARE_CLASS(Axis)
65 
66  friend class Plot;
67  friend class AxisShare;
68 public:
73  Axis(AXIS_LOCATION location);
74  virtual ~Axis();
75 
80  AXIS_LOCATION GetLocation()
81  {
82  return m_location;
83  }
84 
89  bool IsVertical()
90  {
91  return (m_location == AXIS_LEFT) || (m_location == AXIS_RIGHT);
92  }
93 
98  bool IsHorizontal()
99  {
100  return !IsVertical();
101  }
102 
109  void SetMargins(wxCoord marginMin, wxCoord marginMax);
110 
111  //
112  // Dataset functions.
113  //
118  size_t GetDatasetCount();
119 
125  Dataset *GetDataset(size_t index);
126 
127  //
128  // Mouse drag behavior
129  //
130  void SetZoomPanMode();
131 
132  //
133  // Window functions.
134  //
135 
140  void SetWindowWidth(double winWidth)
141  {
142  SetWindow(m_winPos, winWidth);
143  }
144 
149  double GetWindowWidth()
150  {
151  return m_winWidth;
152  }
153 
158  void SetWindowPosition(double winPos)
159  {
160  SetWindow(winPos, m_winWidth);
161  }
162 
168  {
169  return m_winPos;
170  }
171 
176  void SetUseWindow(bool useWin)
177  {
178  if (m_useWin != useWin) {
179  m_useWin = useWin;
180  FireAxisChanged();
181  }
182  }
183 
189  void SetWindow(double winPos, double winWidth)
190  {
191  if (m_winPos != winPos || m_winWidth != winWidth) {
192  m_winPos = winPos;
193  m_winWidth = winWidth;
194  FireAxisChanged();
195  }
196  }
197 
204  bool IntersectsWindow(double v0, double v1);
205 
212  void GetWindowBounds(double &winMin, double &winMax)
213  {
214  double minValue, maxValue;
215  GetDataBounds(minValue, maxValue);
216 
217  if (m_useWin) {
218  winMin = m_winPos;
219  winMax = wxMin(maxValue, winMin + m_winWidth);
220  }
221  else {
222  winMin = minValue;
223  winMax = maxValue;
224  }
225  }
226 
230  void AddDataset(Dataset *dataset)
231  {
232  if (AcceptDataset(dataset)) {
233  m_datasets.Add(dataset);
234  }
235  }
236 
242  virtual void GetDataBounds(double &minValue, double &maxValue) const = 0;
243 
250  virtual wxCoord GetExtent(wxDC &dc) = 0;
251 
257  virtual bool IsVisible(double value);
258 
264  virtual double BoundValue(double value);
265 
274  virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value);
275 
284  virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g);
285 
289  virtual void UpdateBounds() = 0;
290 
296  virtual void Draw(wxDC &dc, wxRect rc) = 0;
297 
303  virtual void DrawGridLines(wxDC &dc, wxRect rcData) = 0;
304 
305 protected:
313  virtual bool AcceptDataset(Dataset *dataset) = 0;
314 
315  DatasetArray m_datasets;
316  wxPen m_gridLinesPen;
317 
318  wxCoord m_marginMin;
319  wxCoord m_marginMax;
320 
321  double m_winPos;
322  double m_winWidth;
323  bool m_useWin;
324 
325  FIRE_WITH_THIS(AxisChanged);
326  FIRE_WITH_THIS(BoundsChanged);
327 
328 private:
329  AXIS_LOCATION m_location;
330 
331  size_t m_shareCount;
332 };
333 
334 WX_DECLARE_USER_EXPORTED_OBJARRAY(Axis *, AxisArray, WXDLLIMPEXP_FREECHART);
335 
340 class WXDLLIMPEXP_FREECHART AxisShare : public Axis
341 {
342 public:
343  AxisShare(Axis *axis);
344  virtual ~AxisShare();
345 
351  void SetShareVisible(bool shareVisible);
352 
353  //
354  // Axis
355  //
356 
357  virtual void GetDataBounds(double &minValue, double &maxValue) const;
358 
359  virtual wxCoord GetExtent(wxDC &dc);
360 
361  virtual bool IsVisible(double value);
362 
363  virtual double BoundValue(double value);
364 
365  virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value);
366 
367  virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g);
368 
369  virtual void UpdateBounds();
370 
371  virtual void Draw(wxDC &dc, wxRect rc);
372 
373  virtual void DrawGridLines(wxDC &dc, wxRect rcData);
374 
375 protected:
376  virtual bool AcceptDataset(Dataset *dataset);
377 
378 private:
379  bool m_shareVisible;
380 
381  Axis *m_axis;
382 };
383 
384 wxCoord ToGraphics(int minCoord, int gRange, double minValue, double maxValue, wxCoord margin, bool vertical, double value);
385 double ToData(int minCoord, int gRange, double minValue, double maxValue, wxCoord margin, bool vertical, wxCoord g);
386 
387 #endif /*AXIS_H_*/
virtual void DrawGridLines(wxDC &dc, wxRect rcData)
Definition: axis.cpp:225
virtual void GetDataBounds(double &minValue, double &maxValue) const
Definition: axis.cpp:180
virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g)
Definition: axis.cpp:208
virtual void UpdateBounds()=0
virtual bool IsVisible(double value)
Definition: axis.cpp:65
void SetWindowPosition(double winPos)
Definition: axis.h:158
size_t GetDatasetCount()
Definition: axis.cpp:55
virtual void UpdateBounds()
Definition: axis.cpp:213
virtual double BoundValue(double value)
Definition: axis.cpp:89
virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value)
Definition: axis.cpp:111
virtual void DrawGridLines(wxDC &dc, wxRect rcData)=0
virtual double BoundValue(double value)
Definition: axis.cpp:198
virtual bool AcceptDataset(Dataset *dataset)=0
virtual wxCoord GetExtent(wxDC &dc)
Definition: axis.cpp:185
void AddDataset(Dataset *dataset)
Definition: axis.h:230
Definition: dataset.h:189
Axis(AXIS_LOCATION location)
Definition: axis.cpp:25
virtual void GetDataBounds(double &minValue, double &maxValue) const =0
virtual bool IsVisible(double value)
Definition: axis.cpp:193
AXIS_LOCATION GetLocation()
Definition: axis.h:80
Definition: axis.h:62
Definition: observable.h:14
virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value)
Definition: axis.cpp:203
double GetWindowPosition()
Definition: axis.h:167
Definition: axis.h:340
bool IsHorizontal()
Definition: axis.h:98
void SetWindow(double winPos, double winWidth)
Definition: axis.h:189
double GetWindowWidth()
Definition: axis.h:149
Dataset * GetDataset(size_t index)
Definition: axis.cpp:60
bool IsVertical()
Definition: axis.h:89
virtual void Draw(wxDC &dc, wxRect rc)
Definition: axis.cpp:218
Definition: plot.h:42
Definition: axis.h:33
virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g)
Definition: axis.cpp:130
bool IntersectsWindow(double v0, double v1)
Definition: axis.cpp:78
Definition: dataset.h:50
void SetMargins(wxCoord marginMin, wxCoord marginMax)
Definition: axis.cpp:46
void SetWindowWidth(double winWidth)
Definition: axis.h:140
virtual void Draw(wxDC &dc, wxRect rc)=0
void GetWindowBounds(double &winMin, double &winMax)
Definition: axis.h:212
void SetUseWindow(bool useWin)
Definition: axis.h:176
virtual wxCoord GetExtent(wxDC &dc)=0
virtual bool AcceptDataset(Dataset *dataset)
Definition: axis.cpp:230