Version: 0.6.0
axisplot.h
1 // Name: axisplot.h
3 // Purpose: axis plot declaration
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 AXISPLOT_H_
11 #define AXISPLOT_H_
12 
13 #include <wx/plot.h>
14 #include <wx/axis/axis.h>
15 
16 #include <wx/areadraw.h>
17 #include <wx/legend.h>
18 #include <wx/marker.h>
19 #include <wx/crosshair.h>
20 #include <wx/chartpanel.h>
21 
22 #include <wx/dynarray.h>
23 
24 
28 class WXDLLIMPEXP_FREECHART DataAxisLink
29 {
30 public:
31  DataAxisLink(Dataset *dataset, Axis *axis)
32  {
33  m_dataset = dataset;
34  m_axis = axis;
35  }
36 
37  DataAxisLink(const DataAxisLink &o)
38  {
39  m_dataset = o.m_dataset;
40  m_axis = o.m_axis;
41  }
42 
43  ~DataAxisLink()
44  {
45  }
46 
47  Dataset *m_dataset;
48  Axis *m_axis;
49 };
50 
51 WX_DECLARE_USER_EXPORTED_OBJARRAY(DataAxisLink, DataAxisLinkArray, WXDLLIMPEXP_FREECHART);
52 
56 class WXDLLIMPEXP_FREECHART AxisPlot : public Plot,
57  public DrawObserver, public DatasetObserver, public AxisObserver,
58  public ChartPanelObserver
59 {
60 public:
61  AxisPlot();
62  virtual ~AxisPlot();
63 
68  void AddAxis(Axis *axis);
69 
74  void AddDataset(Dataset *dataset);
75 
80  void RemoveDataset(Dataset *dataset);
81 
86  void RemoveDataset(size_t index);
87 
95  void AddObjects(Dataset *dataset, Axis *verticalAxis, Axis *horizontalAxis);
96 
101  size_t GetDatasetCount();
102 
108  Dataset *GetDataset(size_t index);
109 
115  void LinkDataHorizontalAxis(size_t nData, size_t nAxis);
116 
122  void LinkDataVerticalAxis(size_t nData, size_t nAxis);
123 
131  Axis *GetDatasetAxis(Dataset *dataset, size_t index, bool vertical);
132 
142  Axis *GetDatasetAxis(Dataset *dataset, bool vertical);
143 
152  {
153  return GetDatasetAxis(dataset, true);
154  }
155 
164  {
165  return GetDatasetAxis(dataset, false);
166  }
167 
174  Dataset *GetAxisDataset(Axis *axis, size_t index)
175  {
176  return axis->GetDataset(index);
177  }
178 
184  void SetDrawGrid(bool drawGridVertical, bool drawGridHorizontal);
185 
190  void SetDataBackground(AreaDraw *dataBackground);
191 
196  void SetLegend(Legend *legend);
197 
202  void SetCrosshair(Crosshair *crosshair);
203 
215  bool ToDataCoords(size_t nData, wxDC &dc, wxRect rc, wxCoord gx, wxCoord gy, double *x, double *y);
216 
217  //
218  // DrawObserver
219  //
220  virtual void NeedRedraw(DrawObject *obj);
221 
222  //
223  // DatasetObserver
224  //
225  virtual void DatasetChanged(Dataset *dataset);
226 
227  //
228  // AxisObserver
229  //
230  virtual void AxisChanged(Axis *axis);
231 
232  virtual void BoundsChanged(Axis *axis);
233 
234  //
235  // ChartPanelObserver
236  //
237  virtual void ChartMouseDown(wxPoint &pt, int key);
238 
239 protected:
240  //
241  // Methods to be implemented by derivative classes
242  //
243 
249  virtual bool AcceptAxis(Axis *axis) = 0;
250 
256  virtual bool AcceptDataset(Dataset *dataset) = 0;
257 
263  virtual void DrawDatasets(wxDC &dc, wxRect rc) = 0;
264 
265  wxCoord GetAxesExtent(wxDC &dc, AxisArray *axes);
266 
267 private:
268  //
269  // Plot
270  //
271  virtual void DrawData(wxDC &dc, wxRect rc);
272 
273  virtual bool HasData();
274 
275  virtual void ChartPanelChanged(wxChartPanel *oldPanel, wxChartPanel *newPanel);
276 
277 
278  void UpdateAxis(Dataset *dataset = NULL);
279 
280  //
281  // Draw functions
282  //
283 
291  void CalcDataArea(wxDC &dc, wxRect rc, wxRect &rcData, wxRect &rcLegend);
292 
299  void DrawAxes(wxDC &dc, wxRect &rc, wxRect rcData);
300 
308  void DrawAxesArray(wxDC &dc, wxRect rc, AxisArray *axes, bool vertical);
309 
310 
316  void DrawGridLines(wxDC &dc, wxRect rcData);
317 
323  void DrawMarkers(wxDC &dc, wxRect rcData);
324 
330  void DrawDataArea(wxDC &dc, wxRect rcData);
331 
337  void DrawLegend(wxDC &dc, wxRect rcLegend);
338 
339  bool m_drawGridVertical;
340  bool m_drawGridHorizontal;
341 
342  AxisArray m_leftAxes;
343  AxisArray m_rightAxes;
344  AxisArray m_topAxes;
345  AxisArray m_bottomAxes;
346 
347  AxisArray m_horizontalAxes;
348  AxisArray m_verticalAxes;
349 
350  DataAxisLinkArray m_links;
351 
352  DatasetArray m_datasets;
353  AreaDraw *m_dataBackground; // data area background
354 
355  wxCoord m_legendPlotGap; // distance between plot and legend
356 
357  Legend *m_legend;
358 
359  Crosshair *m_crosshair;
360 };
361 
362 #endif /*AXISPLOT_H_*/
Definition: chartpanel.h:51
Axis * GetDatasetHorizontalAxis(Dataset *dataset)
Definition: axisplot.h:163
Definition: legend.h:21
virtual void DrawData(wxDC &dc, wxRect rc)=0
Definition: axisplot.h:56
Axis * GetDatasetVerticalAxis(Dataset *dataset)
Definition: axisplot.h:151
Definition: areadraw.h:22
Definition: dataset.h:189
Definition: axis.h:62
Definition: chartpanel.h:23
virtual bool HasData()=0
Dataset * GetDataset(size_t index)
Definition: axis.cpp:60
Definition: drawobject.h:23
virtual void AxisChanged(Axis *axis)=0
virtual void BoundsChanged(Axis *axis)=0
Definition: plot.h:42
Definition: axis.h:33
Definition: drawobject.h:45
virtual void ChartPanelChanged(wxChartPanel *oldPanel, wxChartPanel *newPanel)
Definition: plot.cpp:66
virtual void NeedRedraw(DrawObject *obj)=0
Definition: dataset.h:50
Dataset * GetAxisDataset(Axis *axis, size_t index)
Definition: axisplot.h:174
Definition: dataset.h:37
Definition: crosshair.h:38