wxFreeChart
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 {
58 public:
59  AxisPlot();
60  virtual ~AxisPlot();
61 
66  void AddAxis(Axis *axis);
67 
72  void AddDataset(Dataset *dataset);
73 
78  void RemoveDataset(Dataset *dataset);
79 
84  void RemoveDataset(size_t index);
85 
93  void AddObjects(Dataset *dataset, Axis *verticalAxis, Axis *horizontalAxis);
94 
99  size_t GetDatasetCount();
100 
106  Dataset *GetDataset(size_t index);
107 
113  void LinkDataHorizontalAxis(size_t nData, size_t nAxis);
114 
120  void LinkDataVerticalAxis(size_t nData, size_t nAxis);
121 
129  Axis *GetDatasetAxis(Dataset *dataset, size_t index, bool vertical);
130 
140  Axis *GetDatasetAxis(Dataset *dataset, bool vertical);
141 
150  {
151  return GetDatasetAxis(dataset, true);
152  }
153 
162  {
163  return GetDatasetAxis(dataset, false);
164  }
165 
172  Dataset *GetAxisDataset(Axis *axis, size_t index)
173  {
174  return axis->GetDataset(index);
175  }
176 
182  void SetDrawGrid(bool drawGridVertical, bool drawGridHorizontal);
183 
189  wxDEPRECATED_MSG("SetDataBackground is deprecated, use SetBackground instead")
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  virtual void DataChanged(wxCommandEvent& event);
223 
224  //
225  // DatasetObserver
226  //
227  virtual void DatasetChanged(Dataset *dataset);
228 
229  //
230  // AxisObserver
231  //
232  virtual void AxisChanged(Axis *axis);
233 
234  virtual void BoundsChanged(Axis *axis);
235 
236  //
237  // ChartPanelObserver
238  //
239  virtual void ChartMouseDown(wxPoint &pt, int key);
240 
241 protected:
242  //
243  // Methods to be implemented by derivative classes
244  //
245 
251  virtual bool AcceptAxis(Axis *axis) = 0;
252 
258  virtual bool AcceptDataset(Dataset *dataset) = 0;
259 
265  virtual void DrawDatasets(wxDC &dc, wxRect rc) = 0;
266 
267  wxCoord GetAxesExtent(wxDC &dc, AxisArray *axes);
268 
269  bool m_drawGridVertical;
270  bool m_drawGridHorizontal;
271 
272 private:
273  //
274  // Plot
275  //
276  virtual void DrawData(ChartDC& cdc, wxRect rc);
277 
278  virtual bool HasData();
279 
280  virtual void ChartPanelChanged(wxChartPanel *oldPanel, wxChartPanel *newPanel);
281 
282  bool UpdateAxis(Dataset *dataset = NULL);
283 
284  //
285  // Draw functions
286  //
287 
295  void CalcDataArea(wxDC &dc, wxRect rc, wxRect &rcData, wxRect &rcLegend);
296 
303  void DrawAxes(wxDC &dc, wxRect &rc, wxRect rcData);
304 
312  void DrawAxesArray(wxDC &dc, wxRect rc, AxisArray *axes, bool vertical);
313 
314 
320  void DrawGridLines(wxDC &dc, wxRect rcData);
321 
327  void DrawMarkers(wxDC &dc, wxRect rcData);
328 
334  virtual void DrawBackground(ChartDC& cdc, wxRect rcData) wxOVERRIDE;
335 
341  void DrawLegend(wxDC &dc, wxRect rcLegend);
342 
343  AxisArray m_leftAxes;
344  AxisArray m_rightAxes;
345  AxisArray m_topAxes;
346  AxisArray m_bottomAxes;
347 
348  AxisArray m_horizontalAxes;
349  AxisArray m_verticalAxes;
350 
351  DataAxisLinkArray m_links;
352 
353  DatasetArray m_datasets;
354  AreaDraw *m_dataBackground; // data area background
355 
356  wxCoord m_legendPlotGap; // distance between plot and legend
357 
358  Legend *m_legend;
359 
360  Crosshair *m_crosshair;
361 
362  wxBitmap m_plotBackgroundBitmap; // Bitmap to hold the static (background) part of the plot.
363  wxBitmap m_dataOverlayBitmap; // Bitmap on which the data (lines, bars etc.) is drawn.
364 
365  bool m_redrawDataArea; // Flag to indicate if the background needs to be redrawn.
366  wxRect m_drawRect; // Rectangle to see if the size changed.
367 };
368 
369 #endif /*AXISPLOT_H_*/
Dataset * GetDataset(size_t index)
Returns dataset, linked with this axis at specified index.
Base class for all plots.
Definition: plot.h:31
Axis * GetDatasetHorizontalAxis(Dataset *dataset)
Returns main horizontal dataset axis.
Definition: axisplot.h:161
Base class for objects drawn on chart or perform drawing of another objects (like renderers...
Definition: drawobject.h:22
ChartPanel is wxWidgets panel for displaying chart.
Definition: chartpanel.h:34
DC that includes a flag to indicate antialiased drawing should be used where appropriate.
Definition: chartdc.h:18
virtual void DrawBackground(ChartDC &cdc, wxRect rc)=0
Draw the plot&#39;s static items (e.g.
Dataset * GetAxisDataset(Axis *axis, size_t index)
Returns dataset, linked with axis at specified index.
Definition: axisplot.h:172
Base class for all axes.
Definition: axis.h:39
virtual bool HasData()=0
Checks whether plot has data.
virtual void ChartPanelChanged(wxChartPanel *oldPanel, wxChartPanel *newPanel)
Called when chart panel is changed.
Crosshair class.
Definition: crosshair.h:38
Legend.
Definition: legend.h:21
Base class for all datasets (XYDatasets, XYZDatasets, CategoryDatasets, OHLCDatasets, etc).
Definition: dataset.h:39
Base class for plots that supports axes.
Definition: axisplot.h:56
Base class for drawing area background.
Definition: areadraw.h:22
Axis * GetDatasetVerticalAxis(Dataset *dataset)
Returns main vertical dataset axis.
Definition: axisplot.h:149
virtual void DrawData(ChartDC &cdc, wxRect rc)=0
Draw the plot data, i.e.