wxFreeChart
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 
20 enum AXIS_LOCATION {
21  AXIS_LEFT = 1,
22  AXIS_RIGHT,
23  AXIS_TOP,
24  AXIS_BOTTOM,
25 };
26 
27 class WXDLLIMPEXP_FREECHART Axis;
28 
39 class WXDLLIMPEXP_FREECHART Axis : public wxObject
40 {
41  DECLARE_CLASS(Axis)
42 
43  friend class Plot;
44  friend class AxisShare;
45 public:
50  Axis(AXIS_LOCATION location);
51  virtual ~Axis();
52 
57  AXIS_LOCATION GetLocation()
58  {
59  return m_location;
60  }
61 
66  bool IsVertical()
67  {
68  return (m_location == AXIS_LEFT) || (m_location == AXIS_RIGHT);
69  }
70 
75  bool IsHorizontal()
76  {
77  return !IsVertical();
78  }
79 
86  void SetMargins(wxCoord marginMin, wxCoord marginMax);
87 
93  void SetMajorGridlinePen(const wxPen& pen)
94  {
95  m_majorGridlinePen = pen;
96  }
97 
103  void SetMinorGridlinePen(const wxPen& pen)
104  {
105  m_minorGridlinePen = pen;
106  }
107 
112  const wxPen& GetMajorGridlinePen()
113  {
114  return m_majorGridlinePen;
115  }
116 
121  const wxPen& GetMinorGridlinePen()
122  {
123  return m_minorGridlinePen;
124  }
125 
126  //
127  // Dataset functions.
128  //
133  size_t GetDatasetCount();
134 
140  Dataset *GetDataset(size_t index);
141 
142  //
143  // Mouse drag behavior
144  //
145  void SetZoomPanMode();
146 
147  //
148  // Window functions.
149  //
150 
155  void SetWindowWidth(double winWidth)
156  {
157  SetWindow(m_winPos, winWidth);
158  }
159 
164  double GetWindowWidth()
165  {
166  return m_winWidth;
167  }
168 
173  void SetWindowPosition(double winPos)
174  {
175  SetWindow(winPos, m_winWidth);
176  }
177 
183  {
184  return m_winPos;
185  }
186 
191  void SetUseWindow(bool useWin)
192  {
193  if (m_useWin != useWin) {
194  m_useWin = useWin;
195  }
196  }
197 
203  void SetWindow(double winPos, double winWidth)
204  {
205  if (m_winPos != winPos || m_winWidth != winWidth) {
206  m_winPos = winPos;
207  m_winWidth = winWidth;
208  }
209  }
210 
217  bool IntersectsWindow(double v0, double v1);
218 
225  void GetWindowBounds(double &winMin, double &winMax)
226  {
227  double minValue, maxValue;
228  GetDataBounds(minValue, maxValue);
229 
230  if (m_useWin) {
231  winMin = m_winPos;
232  winMax = wxMin(maxValue, winMin + m_winWidth);
233  }
234  else {
235  winMin = minValue;
236  winMax = maxValue;
237  }
238  }
239 
243  void AddDataset(Dataset *dataset)
244  {
245  if (AcceptDataset(dataset)) {
246  m_datasets.Add(dataset);
247  }
248  }
249 
255  virtual void GetDataBounds(double &minValue, double &maxValue) const = 0;
256 
263  virtual wxCoord GetExtent(wxDC &dc) = 0;
264 
270  virtual bool IsVisible(double value);
271 
277  virtual double BoundValue(double value);
278 
287  virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value);
288 
297  virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g);
298 
302  virtual bool UpdateBounds() = 0;
303 
309  virtual void Draw(wxDC &dc, wxRect rc) = 0;
310 
316  virtual void DrawGridLines(wxDC &dc, wxRect rcData) = 0;
317 
318 protected:
326  virtual bool AcceptDataset(Dataset *dataset) = 0;
327 
328  DatasetArray m_datasets;
329  wxPen m_majorGridlinePen;
330  wxPen m_minorGridlinePen;
331 
332  wxCoord m_marginMin;
333  wxCoord m_marginMax;
334 
335  double m_winPos;
336  double m_winWidth;
337  bool m_useWin;
338 
339 private:
340  AXIS_LOCATION m_location;
341 
342  size_t m_shareCount;
343 };
344 
345 WX_DECLARE_USER_EXPORTED_OBJARRAY(Axis *, AxisArray, WXDLLIMPEXP_FREECHART);
346 
351 class WXDLLIMPEXP_FREECHART AxisShare : public Axis
352 {
353 public:
354  AxisShare(Axis *axis);
355  virtual ~AxisShare();
356 
362  void SetShareVisible(bool shareVisible);
363 
364  //
365  // Axis
366  //
367 
368  virtual void GetDataBounds(double &minValue, double &maxValue) const;
369 
370  virtual wxCoord GetExtent(wxDC &dc);
371 
372  virtual bool IsVisible(double value);
373 
374  virtual double BoundValue(double value);
375 
376  virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value);
377 
378  virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g);
379 
380  virtual bool UpdateBounds() wxOVERRIDE;
381 
382  virtual void Draw(wxDC &dc, wxRect rc);
383 
384  virtual void DrawGridLines(wxDC &dc, wxRect rcData);
385 
386 protected:
387  virtual bool AcceptDataset(Dataset *dataset);
388 
389 private:
390  bool m_shareVisible;
391 
392  Axis *m_axis;
393 };
394 
395 wxCoord ToGraphics(int minCoord, int gRange, double minValue, double maxValue, wxCoord margin, bool vertical, double value);
396 double ToData(int minCoord, int gRange, double minValue, double maxValue, wxCoord margin, bool vertical, wxCoord g);
397 
398 #endif /*AXIS_H_*/
double GetWindowPosition()
Returns window position.
Definition: axis.h:182
virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value)
Transforms coordinate from data space to graphics space.
bool IsVertical()
Checks whether axis is vertical.
Definition: axis.h:66
virtual wxCoord ToGraphics(wxDC &dc, int minCoord, int gRange, double value)
Transforms coordinate from data space to graphics space.
Dataset * GetDataset(size_t index)
Returns dataset, linked with this axis at specified index.
bool IntersectsWindow(double v0, double v1)
Checks whether line in data space intersects window.
virtual wxCoord GetExtent(wxDC &dc)=0
Used to determine minimal size needed to draw axis contents, minimal width for vertical axes...
virtual void Draw(wxDC &dc, wxRect rc)=0
Performs axis drawing.
Base class for all plots.
Definition: plot.h:31
virtual bool AcceptDataset(Dataset *dataset)
Checks whether dataset can be accepted by this axis.
void SetWindowWidth(double winWidth)
Sets window width.
Definition: axis.h:155
bool IsHorizontal()
Checks whether axis is horizontal.
Definition: axis.h:75
virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g)
Transforms coordinate from graphics space to data space.
void SetWindowPosition(double winPos)
Sets window position.
Definition: axis.h:173
virtual wxCoord GetExtent(wxDC &dc)
Used to determine minimal size needed to draw axis contents, minimal width for vertical axes...
void SetMajorGridlinePen(const wxPen &pen)
Sets the pen to be used for drawing major gridlines.
Definition: axis.h:93
void SetMargins(wxCoord marginMin, wxCoord marginMax)
Sets minimal/maximal margins for axis.
virtual void GetDataBounds(double &minValue, double &maxValue) const =0
Returns data bounds.
double GetWindowWidth()
Returns window width.
Definition: axis.h:164
const wxPen & GetMajorGridlinePen()
Gets the pen that is currently used to draw major gridlines on this axis.
Definition: axis.h:112
Axis(AXIS_LOCATION location)
Constructs new axis.
void SetUseWindow(bool useWin)
Sets whether to use window.
Definition: axis.h:191
const wxPen & GetMinorGridlinePen()
Gets the pen that is currently used to draw minor gridlines on this axis.
Definition: axis.h:121
Base class for all axes.
Definition: axis.h:39
virtual double BoundValue(double value)
Returns nearest boundary value.
virtual void Draw(wxDC &dc, wxRect rc)
Performs axis drawing.
void GetWindowBounds(double &winMin, double &winMax)
Returns window bounds.
Definition: axis.h:225
virtual double BoundValue(double value)
Returns nearest boundary value.
virtual bool IsVisible(double value)
Checks whether data value is visible.
virtual bool UpdateBounds()=0
Performs axis bounds update after dataset/s change.
Base class for all datasets (XYDatasets, XYZDatasets, CategoryDatasets, OHLCDatasets, etc).
Definition: dataset.h:39
void SetMinorGridlinePen(const wxPen &pen)
Sets the pen to be used for drawing minor gridlines.
Definition: axis.h:103
virtual bool AcceptDataset(Dataset *dataset)=0
Checks whether dataset can be accepted by this axis.
virtual void DrawGridLines(wxDC &dc, wxRect rcData)
Draws grid lines for axis.
AXIS_LOCATION GetLocation()
Returns axis location.
Definition: axis.h:57
void AddDataset(Dataset *dataset)
internal.
Definition: axis.h:243
size_t GetDatasetCount()
Returns dataset counts, linked with this axis.
virtual bool UpdateBounds() wxOVERRIDE
Performs axis bounds update after dataset/s change.
void SetWindow(double winPos, double winWidth)
Sets window params (position and width).
Definition: axis.h:203
virtual void GetDataBounds(double &minValue, double &maxValue) const
Returns data bounds.
Used to combine axes.
Definition: axis.h:351
virtual void DrawGridLines(wxDC &dc, wxRect rcData)=0
Draws grid lines for axis.
virtual double ToData(wxDC &dc, int minCoord, int gRange, wxCoord g)
Transforms coordinate from graphics space to data space.
virtual bool IsVisible(double value)
Checks whether data value is visible.