Whiteboard
An interface and tools for visualizing large and complex datasets
TicMarks.h
Go to the documentation of this file.
1 
2 
3 #ifndef TICMARKS_H
4 #define TICMARKS_H
5 
6 #include "visual/Whiteboard.h"
7 #include <cmath>
8 #include <sstream>
9 
10 namespace ns_whiteboard
11 {
12 
14 
16 {
17 public:
19  line * y_axis,
20  const double x_scaling = 1.0,
21  const double x_offset = 0.0,
22  const double y_scaling = 1.0,
23  const double y_offset = 0.0,
24  const double size = 5.0)
25  : m_xAxis(x_axis),
26  m_yAxis(y_axis),
27  m_size(size),
28  m_xScale(x_scaling),
29  m_xOffset(x_offset),
30  m_yScale(y_scaling),
31  m_yOffset(y_offset) {}
32 
33 virtual void CreateTicking() = 0;
34 
36 
37 double GetSize() { return m_size; }
38 
39 vector<line> GetXLines() { return m_xAxisTics; }
40 vector<line> GetYLines() { return m_yAxisTics; }
41 vector<text> GetXText() { return m_xTxt; }
42 vector<text> GetYText() { return m_yTxt; }
43 
44 protected:
47 double m_size;
49 
50 vector<line> m_xAxisTics, m_yAxisTics;
51 vector<text> m_xTxt, m_yTxt;
52 
53 
54 };
55 
57 {
58 public:
59 LinearTicking( line * x_axis,
60  line * y_axis,
61  const double x_scaling = 1.0,
62  const double x_offset = 0.0,
63  const double y_scaling = 1.0,
64  const double y_offset = 0.0,
65  const double size = 5.0)
66  : TickingStrategyBase(x_axis,
67  y_axis,
68  x_scaling,
69  x_offset,
70  y_scaling,
71  y_offset,
72  size) {}
73 
74 virtual ~LinearTicking() {}
75 
76 void CreateTicking();
77 
78 };
79 
80 
82 {
83 
84  // in pixels
85  double x_tic_width = m_xAxis->GetWidth();
86  double y_tic_width = m_yAxis->GetWidth();
87 
88  // in pixels
89  xy_coords x_start = m_xAxis->StartCoords();
90  xy_coords x_stop = m_xAxis->StopCoords();
91 
92  xy_coords y_start = m_yAxis->StartCoords();
93  xy_coords y_stop = m_yAxis->StopCoords();
94 
95  // in pixels
96  double x_len = x_stop.first-x_start.first;
97  double y_len = y_stop.second-y_start.second;
98 
99  // in data units
100  double max_pos_x = m_xScale*x_stop.first + m_xOffset;
101  double max_pos_y = m_yScale*y_stop.second + m_yOffset;
102 
103  // in data units
104  double x_fac(0), y_fac(0), tic_x_spacing(0), tic_y_spacing(0);
105  x_fac = std::floor(std::log10(max_pos_x));
106  y_fac = std::floor(std::log10(max_pos_y));
107 
108  if ( max_pos_x > 1 )
109  tic_x_spacing = x_fac*std::pow(10,x_fac-1);
110  else
111  tic_x_spacing = -1*x_fac*std::pow(10,x_fac);
112 
113  if ( max_pos_y > 1 )
114  tic_y_spacing = y_fac*std::pow(10,y_fac-1);
115  else
116  tic_y_spacing = -1*y_fac*std::pow(10,y_fac);
117 
118 
119  if (tic_x_spacing <= 0)
120  tic_x_spacing = 0.1;
121  if (tic_y_spacing <= 0)
122  tic_y_spacing = 0.1;
123 
124  // in data units
125  double x_start_x = m_xScale*x_start.first + m_xOffset;
126  double x_start_y = m_yScale*x_start.second + m_yOffset;
127 
128  double x_stop_x = m_xScale*x_stop.first + m_xOffset;
129  double x_stop_y = m_yScale*x_stop.second + m_yOffset;
130 
131  double y_start_x = m_xScale*y_start.first + m_xOffset;
132  double y_start_y = m_yScale*y_start.second + m_yOffset;
133 
134  double y_stop_x = m_xScale*y_stop.first + m_xOffset;
135  double y_stop_y = m_yScale*y_stop.second + m_yOffset;
136 
137 
138 
139  // get the tic marks for the x-axis
140  double pos(x_start_x+tic_x_spacing);
141  while ( pos <= m_xScale*x_len+x_start_x )
142  {
143  // in pixels
144  double pos_pix = (pos-m_xOffset)/m_xScale;
145 
146  xy_coords start = make_pair(pos_pix-x_tic_width/2.0, y_start.second-m_size/2.0);
147  xy_coords stop = make_pair(pos_pix-x_tic_width/2.0, y_start.second+m_size/2.0);
148 
149  line l( start,
150  stop,
151  x_tic_width );
152 
153  m_xAxisTics.push_back(l);
154 
155  ostringstream ost;
156  ost << (pos-x_start_x);
157 
158  string tic_label(ost.str());
159  double font_size = 10.0;
160  string font("Times-Roman");
161  color c(black);
162 
163  xy_coords txt_start = make_pair(start.first,start.second-2.0*m_size);
164 
165  text t(txt_start,
166  tic_label,
167  c,
168  font_size,
169  font);
170 
171  m_xTxt.push_back(t);
172 
173  pos += tic_x_spacing;
174 
175  }
176 
177 
178  // get the tic marks for the y-axis
179  pos = y_start_y+tic_y_spacing;
180  while ( pos <= m_yScale*y_len+y_start_y )
181  {
182  double pos_pix = (pos-m_yOffset)/m_yScale;
183  xy_coords start = make_pair( x_start.first-m_size/2.0, pos_pix-y_tic_width/2.0);
184  xy_coords stop = make_pair( x_start.first+m_size/2.0, pos_pix-y_tic_width/2.0);
185 
186  line l( start,
187  stop,
188  y_tic_width );
189 
190  m_yAxisTics.push_back(l);
191 
192 
193  ostringstream ost;
194  ost << (pos-y_start_y);
195 
196  string tic_label(ost.str());
197  double font_size = 10.0;
198  string font("Times-Roman");
199  color c(black);
200 
201  xy_coords txt_start = make_pair(start.first-1.5*m_size,start.second);
202 
203  text t(txt_start,
204  tic_label,
205  c,
206  font_size,
207  font,
208  90);
209 
210  m_yTxt.push_back(t);
211 
212 
213  pos += tic_y_spacing;
214 
215 
216 
217 
218  }
219 
220 }
221 
222 }
223 
224 
225 #endif
Definition: Whiteboard.h:276
double GetSize()
Definition: TicMarks.h:37
virtual ~TickingStrategyBase()
Definition: TicMarks.h:35
vector< text > m_yTxt
Definition: TicMarks.h:51
Definition: Whiteboard.h:394
vector< text > GetYText()
Definition: TicMarks.h:42
double m_xOffset
Definition: TicMarks.h:48
double m_yScale
Definition: TicMarks.h:48
virtual ~LinearTicking()
Definition: TicMarks.h:74
line * m_yAxis
Definition: TicMarks.h:46
The whiteboard namespace.
Definition: Axes.h:10
vector< line > GetXLines()
Definition: TicMarks.h:39
double GetWidth() const
Definition: Whiteboard.h:302
double m_yOffset
Definition: TicMarks.h:48
vector< line > GetYLines()
Definition: TicMarks.h:40
Definition: TicMarks.h:56
vector< line > m_xAxisTics
Definition: TicMarks.h:50
const color black(0, 0, 0)
Definition: TicMarks.h:13
tic_style
Definition: TicMarks.h:13
Definition: TicMarks.h:13
pair< double, double > xy_coords
Definition: Whiteboard.h:30
vector< text > GetXText()
Definition: TicMarks.h:41
Definition: TicMarks.h:13
File holding the base drawing classes of the whiteboard.
line * m_xAxis
Definition: TicMarks.h:45
double m_size
Definition: TicMarks.h:47
Definition: TicMarks.h:13
LinearTicking(line *x_axis, line *y_axis, 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 double size=5.0)
Definition: TicMarks.h:59
Definition: TicMarks.h:15
vector< text > m_xTxt
Definition: TicMarks.h:51
xy_coords StartCoords() const
Definition: Whiteboard.h:300
TickingStrategyBase(line *x_axis, line *y_axis, 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 double size=5.0)
Definition: TicMarks.h:18
Definition: Color.h:12
void CreateTicking()
Definition: TicMarks.h:81
double m_xScale
Definition: TicMarks.h:48
vector< line > m_yAxisTics
Definition: TicMarks.h:50
xy_coords StopCoords() const
Definition: Whiteboard.h:301