Whiteboard
An interface and tools for visualizing large and complex datasets
Axes.h
Go to the documentation of this file.
1 
2 
3 #ifndef AXES_H
4 #define AXES_H
5 
6 #include "visual/Whiteboard.h"
7 #include "visual/TicMarks.h"
8 
9 
10 namespace ns_whiteboard
11 {
12 
13 
17 class axes : public graphic
18 {
19 
20 public:
21 
22 axes()
23  : m_xLine(NULL),
24  m_yLine(NULL),
25  m_xLabel(NULL),
26  m_yLabel(NULL),
27  m_ticking(NULL),
28  self_owned_lines(true) {}
29 
30 axes( line * x_line,
31  line * y_line )
32  : m_xLine(x_line),
33  m_yLine(y_line),
34  m_xLabel(NULL),
35  m_yLabel(NULL),
36  m_ticking(NULL),
37  self_owned_lines(false) {}
38 
42 void Draw( display_type *d );
43 
44 void CreateTics(const double x_scaling=1.0,
45  const double x_offset=0.0,
46  const double y_scaling=1.0,
47  const double y_offset=0.0,
48  const tic_style t = linear);
49 
50 
51 void SetXAxis( const xy_coords &startCoords,
52  const xy_coords &stopCoords,
53  const double width = 1.0,
54  const color &c = black );
55 
56 void SetYAxis( const xy_coords &startCoords,
57 
58  const xy_coords &stopCoords,
59  const double width = 1.0,
60  const color &c = black );
61 
62 
63 void RescaleAxes() {}
64 
65 void SetXAxisLabel( const string &label,
66  const color &c = black,
67  const double fontSize = 12.0,
68  const string &font = "Times-Roman");
69 
70 void SetYAxisLabel( const string &label,
71  const color &c = black,
72  const double fontSize = 12.0,
73  const string &font = "Times-Roman");
74 
75 
76 protected:
77 
79 
81 
83 
85 
86 public:
87 virtual ~axes()
88 {
89  if ( self_owned_lines )
90  {
91  delete m_xLine;
92  delete m_yLine;
93  }
94  delete m_xLabel;
95  delete m_yLabel;
96  delete m_ticking;
97 }
98 
99 
100 };
101 
102 
103 void axes::CreateTics(const double x_scaling,
104  const double x_offset,
105  const double y_scaling,
106  const double y_offset,
107  const tic_style t)
108 {
109 
110  if ( m_xLine == NULL || m_yLine == NULL )
111  {
112  cout << "Please set the axes first" << endl;
113  exit(-1);
114  }
115 
116  double tic_size = 8*m_xLine->GetWidth();
117 
118  switch ( t )
119  {
120  case linear:
122  m_yLine,
123  x_scaling,
124  x_offset,
125  y_scaling,
126  y_offset,
127  tic_size);
128  break;
129 
130  // to be implemented
131  case semilogx:
132  break;
133  case semilogy:
134  break;
135  case loglog:
136  break;
137 
138  }
139 
141 }
142 
143 
144 void axes::SetXAxisLabel( const string &label,
145  const color &c,
146  const double fontSize,
147  const string &font )
148 {
149 
150  if ( m_xLine == NULL )
151  {
152  cout << "SetXAxis first, please." << endl;
153  exit(-1);
154  }
155 
156  if ( m_ticking == NULL )
157  {
158  cout << "due to stupidity, please CreateTics(...) first" << endl;
159  exit(-1);
160  // CreateTics();
161  }
162 
163  xy_coords axis_start = m_xLine->StartCoords();
164  xy_coords axis_stop = m_xLine->StopCoords();
165 
166 
167  double label_x_pos = axis_start.first + (double) (axis_stop.first-axis_start.first)/2 - (double) label.size()/2;
168  double label_y_pos = axis_start.second - 2.0*m_ticking->GetSize() - 2.0*fontSize;
169 
170  xy_coords label_coords = make_pair(label_x_pos,label_y_pos);
171 
172  m_xLabel = new text( label_coords,
173  label,
174  c,
175  fontSize,
176  font);
177 
178 
179 }
180 
181 
182 void axes::SetYAxisLabel( const string &label,
183  const color &c,
184  const double fontSize,
185  const string &font )
186 {
187 
188  if ( m_yLine == NULL )
189  {
190  cout << "SetYAxis first, please." << endl;
191  exit(-1);
192  }
193 
194  if ( m_ticking == NULL )
195  {
196  cout << "due to stupidity, please CreateTics(...) first" << endl;
197  exit(-1);
198  // CreateTics();
199  }
200 
201 
202  xy_coords axis_start = m_yLine->StartCoords();
203  xy_coords axis_stop = m_yLine->StopCoords();
204 
205  double label_x_pos = axis_start.first - 1.0*m_ticking->GetSize() - 2.0*fontSize;
206  double label_y_pos = axis_start.second
207  + (double) (axis_stop.second - axis_start.second)/2 - (double) label.size()/2;
208 
209  xy_coords label_coords = make_pair(label_x_pos,label_y_pos);
210 
211  m_yLabel = new text( label_coords,
212  label,
213  c,
214  fontSize,
215  font,
216  90);
217 
218 
219 }
220 
221 void axes::SetXAxis( const xy_coords &startCoords,
222  const xy_coords &stopCoords,
223  const double width,
224  const color &c )
225 {
226  m_xLine = new line(startCoords,
227  stopCoords,
228  width,
229  c);
230 
231 }
232 
233 void axes::SetYAxis( const xy_coords &startCoords,
234  const xy_coords &stopCoords,
235  const double width,
236  const color &c)
237 {
238  m_yLine = new line(startCoords,
239  stopCoords,
240  width,
241  c);
242 
243 }
244 
245 
246 
248 {
249 
250  if ( m_xLine == NULL || m_yLine == NULL || m_xLabel == NULL || m_yLabel == NULL )
251  {
252  cout << "bad form" << endl;
253  exit(-1);
254  }
255 
256  vector<line> xtics = m_ticking->GetXLines();
257  vector<line> ytics = m_ticking->GetYLines();
258 
259  vector<text> xticlabs = m_ticking->GetXText();
260  vector<text> yticlabs = m_ticking->GetYText();
261 
262  if ( xtics.size() != xticlabs.size() )
263  {
264  cout << "xtic irregularity" << endl;
265  exit(-1);
266  }
267  if ( ytics.size() != yticlabs.size() )
268  {
269  cout << "ytic irregularity" << endl;
270  exit(-1);
271  }
272 
273 
274  m_xLine->Draw(d);
275  m_yLine->Draw(d);
276  m_xLabel->Draw(d);
277  m_yLabel->Draw(d);
278 
279 
280  for ( int i=0; i<(int) xtics.size(); ++i )
281  {
282  xtics[i].Draw(d);
283  xticlabs[i].Draw(d);
284  }
285 
286  for ( int i=0; i<(int) ytics.size(); ++i )
287  {
288  ytics[i].Draw(d);
289  yticlabs[i].Draw(d);
290  }
291 
292 
293 }
294 }
295 
296 
297 
298 #endif
Definition: Whiteboard.h:276
double GetSize()
Definition: TicMarks.h:37
text * m_yLabel
Definition: Axes.h:80
virtual ~axes()
Definition: Axes.h:87
line * m_xLine
Definition: Axes.h:78
void Draw(display_type *d)
Definition: Whiteboard.h:433
Definition: Whiteboard.h:394
vector< text > GetYText()
Definition: TicMarks.h:42
void SetYAxis(const xy_coords &startCoords, const xy_coords &stopCoords, const double width=1.0, const color &c=black)
Definition: Axes.h:233
TickingStrategyBase * m_ticking
Definition: Axes.h:82
The whiteboard namespace.
Definition: Axes.h:10
void SetXAxisLabel(const string &label, const color &c=black, const double fontSize=12.0, const string &font="Times-Roman")
Definition: Axes.h:144
vector< line > GetXLines()
Definition: TicMarks.h:39
void Draw(display_type *d)
Definition: Whiteboard.h:292
double GetWidth() const
Definition: Whiteboard.h:302
vector< line > GetYLines()
Definition: TicMarks.h:40
Definition: TicMarks.h:56
const color black(0, 0, 0)
axes(line *x_line, line *y_line)
Definition: Axes.h:30
Definition: Whiteboard.h:136
void Draw(display_type *d)
Definition: Axes.h:247
Definition: TicMarks.h:13
tic_style
Definition: TicMarks.h:13
Definition: TicMarks.h:13
void SetXAxis(const xy_coords &startCoords, const xy_coords &stopCoords, const double width=1.0, const color &c=black)
Definition: Axes.h:221
pair< double, double > xy_coords
Definition: Whiteboard.h:30
vector< text > GetXText()
Definition: TicMarks.h:41
bool self_owned_lines
Definition: Axes.h:84
Definition: Whiteboard.h:46
axes()
Definition: Axes.h:22
Definition: TicMarks.h:13
File holding the base drawing classes of the whiteboard.
text * m_xLabel
Definition: Axes.h:80
Definition: TicMarks.h:13
Definition: TicMarks.h:15
xy_coords StartCoords() const
Definition: Whiteboard.h:300
Definition: Axes.h:17
line * m_yLine
Definition: Axes.h:78
void SetYAxisLabel(const string &label, const color &c=black, const double fontSize=12.0, const string &font="Times-Roman")
Definition: Axes.h:182
void RescaleAxes()
Definition: Axes.h:63
Definition: Color.h:12
void CreateTics(const double x_scaling=1.0, const double x_offset=0.0, const double y_scaling=1.0, const double y_offset=0.0, const tic_style t=linear)
Definition: Axes.h:103
xy_coords StopCoords() const
Definition: Whiteboard.h:301