wxFreeChart
labelaxis.h
1 // Name: labelaxis.h
3 // Purpose: label axis 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 LABELAXIS_H_
11 #define LABELAXIS_H_
12 
13 #include <wx/axis/axis.h>
14 
18 class WXDLLIMPEXP_FREECHART LabelColourer
19 {
20 public:
21  // IY: Virtual destructor needed otherwise behaviour is undefined.
22  virtual ~LabelColourer() {}
23  virtual wxColor GetColour(int step) = 0;
24 };
25 
29 class WXDLLIMPEXP_FREECHART LabelAxis : public Axis
30 {
31  DECLARE_CLASS(LabelAxis)
32 public:
33  LabelAxis(AXIS_LOCATION location);
34  virtual ~LabelAxis();
35 
40  void SetTitle(const wxString &title)
41  {
42  m_title = title;
43  }
44 
49  const wxString &GetTitle()
50  {
51  return m_title;
52  }
53 
60  void SetTitleLocation(int location)
61  {
62  if (m_titleLocation != location)
63  m_titleLocation = location;
64  }
65 
71  {
72  return m_titleLocation;
73  }
74 
79  void SetTitleFont(wxFont &font)
80  {
81  m_titleFont = font;
82  }
83 
88  const wxFont &GetTitleFont()
89  {
90  return m_titleFont;
91  }
92 
97  void SetTitleColour(wxColour &colour)
98  {
99  if (m_titleColour != colour) {
100  m_titleColour = colour;
101  }
102  }
103 
108  wxColour GetTitleColour()
109  {
110  return m_titleColour;
111  }
112 
117  void SetLabelPen(wxPen labelPen)
118  {
119  m_labelPen = labelPen;
120  }
121 
126  void SetLabelTextColour(wxColour labelTextColour)
127  {
128  m_labelTextColour = labelTextColour;
129  }
130 
136  {
137  return m_labelTextColour;
138  }
139 
144  void SetLabelTextFont(wxFont labelTextFont)
145  {
146  m_labelTextFont = labelTextFont;
147  }
148 
153  const wxFont& GetLabelTextFont()
154  {
155  return m_labelTextFont;
156  }
157 
162  void SetVerticalLabelText(bool verticalLabelText)
163  {
164  if (m_verticalLabelText != verticalLabelText)
165  m_verticalLabelText = verticalLabelText;
166  }
167 
173  {
174  return m_verticalLabelText;
175  }
176 
181  wxDEPRECATED_MSG("Use SetMinorIntervalCount instead.")
182  void SetMajorLabelSteps(size_t step)
183  {
184  if (m_majorLabelStep != step)
185  m_majorLabelStep = step;
186  }
187 
192  void SetMinorIntervalCount(size_t count)
193  {
194  m_minorIntervalCount = count;
195  }
196 
202  {
203  return m_minorIntervalCount;
204  }
205 
206  void SetLabelSkip(int blankLabels);
207 
208  int GetLabelSkip();
209 
210  void SetLabelColourer(LabelColourer *labelColourer)
211  {
212  wxREPLACE(m_labelColourer, labelColourer);
213  }
214 
215  LabelColourer *GetLabelColourer()
216  {
217  return m_labelColourer;
218  }
219 
224  void SetAxisVisible(bool bVisible);
225 
226  //
227  // Axis
228  //
229  virtual void Draw(wxDC &dc, wxRect rc);
230 
231  virtual void DrawGridLines(wxDC &dc, wxRect rc);
232 
233  virtual wxCoord GetExtent(wxDC &dc);
234 
235 protected:
236  //
237  // Functions that must be implemented by derivative classes
238  //
239 
245  virtual double GetValue(size_t step) = 0;
246 
252  virtual void GetLabel(size_t step, wxString &label) = 0;
253 
259  virtual bool IsEnd(size_t step) = 0;
260 
261  virtual wxSize GetLongestLabelExtent(wxDC &dc) = 0;
262 
263  virtual bool HasLabels();
264 
265 private:
266  void DrawLabels(wxDC &dc, wxRect rc);
267 
268  void DrawLabel(wxDC &dc, wxRect rc, const wxString &label, double value, bool isMajorLabel);
269 
270  void DrawBorderLine(wxDC &dc, wxRect rc);
271 
272  void DrawGridLine(wxDC& dc, const wxRect& rc, double value);
273 
274  wxCoord m_labelLineSize;
275  wxCoord m_labelGap;
276 
277  // labels properties
278  wxFont m_labelTextFont;
279  wxColour m_labelTextColour;
280  wxPen m_labelPen;
281  bool m_verticalLabelText;
282  size_t m_majorLabelStep;
283  size_t m_minorIntervalCount;
284 
285  // label title properties
286  wxString m_title;
287  wxFont m_titleFont;
288  wxColour m_titleColour;
289  int m_titleLocation;
290 
291  bool m_visible;
292  int m_blankLabels;
293 
294  LabelColourer *m_labelColourer;
295 };
296 
297 #endif /*LABELAXIS_H_*/
void SetLabelTextColour(wxColour labelTextColour)
Sets colour for labels.
Definition: labelaxis.h:126
void SetTitleColour(wxColour &colour)
Sets axis title colour.
Definition: labelaxis.h:97
void SetTitle(const wxString &title)
Sets axis title.
Definition: labelaxis.h:40
void SetTitleFont(wxFont &font)
Sets axis title font.
Definition: labelaxis.h:79
const wxFont & GetLabelTextFont()
Returns label font.
Definition: labelaxis.h:153
void SetVerticalLabelText(bool verticalLabelText)
Sets whether to draw labels text vertical.
Definition: labelaxis.h:162
wxColour GetTitleColour()
Returns axis title colour.
Definition: labelaxis.h:108
bool GetVerticalLabelText()
Returns whether to draw labels text vertical.
Definition: labelaxis.h:172
void SetLabelTextFont(wxFont labelTextFont)
Sets font for labels text.
Definition: labelaxis.h:144
wxDEPRECATED_MSG("Use SetMinorIntervalCount instead.") void SetMajorLabelSteps(size_t step)
Sets major label steps.
Definition: labelaxis.h:181
const wxString & GetTitle()
Returns axis title.
Definition: labelaxis.h:49
void SetLabelPen(wxPen labelPen)
Sets pen for label lines.
Definition: labelaxis.h:117
wxColour GetLabelTextColour()
Returns label colour.
Definition: labelaxis.h:135
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.
const wxFont & GetTitleFont()
Returns axis title font.
Definition: labelaxis.h:88
Base class for axes for displaying data labels.
Definition: labelaxis.h:29
Base class for all axes.
Definition: axis.h:39
Class that used to implement labels with different colours.
Definition: labelaxis.h:18
void SetTitleLocation(int location)
Sets axis title location.
Definition: labelaxis.h:60
void SetMinorIntervalCount(size_t count)
Set the number of ticks between each label (major interval).
Definition: labelaxis.h:192
size_t GetMinorIntervalCout()
Get the number of ticks between each label (major interval).
Definition: labelaxis.h:201
int GetTitleLocation()
Returns axis title location.
Definition: labelaxis.h:70
virtual void DrawGridLines(wxDC &dc, wxRect rcData)=0
Draws grid lines for axis.