Axis.hh
6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* Axis.hh
*
* Created on: 20 nov. 2013
* Author: guillaume
*/
#ifndef AXIS_HH_
#define AXIS_HH_
#include "Color.hh"
#include "PlotCommon.hh"
#include "Range.hh"
#include "Tick.hh"
#include "Label.hh"
#include "ConstantLine.hh"
#include "ContextFileWriter.hh"
#include <boost/shared_ptr.hpp>
#include <list>
namespace plot {
typedef void (*LabelGeneratorFunction)(PLINT, PLFLT, char *, PLINT, void *);
struct LabelGenerator {
LabelGenerator() :
_function(nullptr), _data(nullptr) {
}
virtual ~LabelGenerator() {
}
LabelGeneratorFunction _function;
PLPointer _data;
};
class DefaultPlotConfiguration;
class Axis {
public:
enum Scale {
LOGARITHMIC, LINEAR
};
Axis(bool isZAxis = false);
Axis(const Axis& axis);
virtual ~Axis();
virtual Range getRange() {
if (_reverse) {
Range lRange(_range.getMax(), _range.getMin());
lRange._extend = _range._extend;
return lRange;
} else {
return _range;
}
}
void setRange(Range const& pRange) {
_range = pRange;
}
void setRange(double pMin, double pMax) {
_range.setMin(pMin);
_range.setMax(pMax);
}
void setRequestedRange(double pMin, double pMax) {
setRange(pMin, pMax);
_requestedRange.setMin(pMin);
_requestedRange.setMax(pMax);
}
void setExtended(bool pExtend) {
_range._extend = pExtend;
}
bool isExtended() {
return _range._extend;
}
bool isZAxis() {
return _isZAxis;
}
/**
* @brief Write axis context
*/
void writeContext(ContextFileWriter& writer);
/**
* @brief axis identifier (associated to parameter)
*/
std::string _id;
/**
* @brief _color Color of axis and so color used to plot parameter(s)
*/
Color _color;
/**
* @brief _origin, to draw y axis on origin (must be 0)
*/
double _origin;
/**
* @brief _position left, right for abscissa axis and top, bottom for ordinate axis.
*/
PlotCommon::Position _position;
/**
* @brief _reverse Tell if axis is in reversed orientation [0;100] => [100;0]
*/
bool _reverse;
/**
* @brief _tick Define graduation for minor and major tick
*/
Tick _tick;
/**
* @brief Is axis virtual or not
*/
bool _visible;
/**
* @brief Axis is used for the plot or not
*/
bool _used;
/**
* @brief Axis draw thickness
*/
int _thickness;
/**
* @brief Axis label
*/
Label _legend;
/**
* @brief _drawn Define if axis is already drawn (true) or not (false).
*/
bool _drawn;
/**
* @brief _additionalObjDrawn Define if additional objects were already drawn (true) or not (false).
*/
bool _additionalObjDrawn;
/**
* @brief _isZAxis Define if it's a ZAxis.
*/
bool _isZAxis;
/**
* @brief Set axis scale (linear or logarithmic).
*/
void setScale(const std::string& value) {
if (value == "linear") {
_scale = Scale::LINEAR;
} else if (value == "logarithmic") {
_scale = Scale::LOGARITHMIC;
}
}
Scale _scale;
/**
* @brief Set Legend visibility flag for an axis
*/
void setShowLegend(bool showLegend) {
_showLegend = showLegend;
}
bool _showLegend;
/**
* @brief Set TickMark visibility flag for an axis
*/
void setShowTickMark(bool showTickMark) {
_showTickMark = showTickMark;
}
bool _showTickMark;
/**
* @brief For TU
*/
virtual void dump(std::ostream& out);
/**
* @brief Gets string options for the current axis according to previous properties.
*/
virtual std::string getPlotOpt();
/**
* @brief Gets automatically calculated major tick space, default is 0
* to let plplot do it itself
*/
virtual double getAutoMajorTickSpace(double /*min*/, double /*max*/) {
return 0;
}
/**
* @brief Gets automatically calculated minor tick number between 2 major ticks, default is 0
* to let plplot do it itself
*/
virtual double getAutoMinorTickNumber(double /*min*/, double /*max*/) {
return 0;
}
/**
* @brief Gets adjusted value according to axis specifications as log scale, min, max.
* by default returns originalValues_.
* @param originalValues_ IN values
* @param size_ IN number of values
* @param min_ min value
* @param max_ max value
*/
virtual double* getComputedValues(double* originalValues_, int /*size_*/,
double /*min_*/, double /*max*/) {
return originalValues_;
}
/**
* @brief Get tick mark size.
* @note This is used to set sufficient space for tick mark to be visible
*/
virtual std::pair<int, int> getTickMarkSize();
/**
* gets the number of line for each tickMark. This information is used
* by Axis::getTickMarkSize to compute tick mark bounds.
* @return number of line for each tickMark.
*/
int getTickMarkLines() const {
return _tickMarkLines;
}
/**
* sets the number of line for each tickMark.
* @param tickMarkLines_ the number of lines to take into account.
*/
void setTickMarkLines(int tickMarkLines_) {
_tickMarkLines = tickMarkLines_;
}
double getAxisOffset() const {
return _axisOffset;
}
void setAxisOffset(double axisOffset) {
_axisOffset = axisOffset;
}
std::string getAxisUnits() const {
return _axisUnits;
}
void setAxisUnits(std::string units) {
_axisUnits = units;
}
/**
* @brief fixed tickMark width for the axe (-1 means tickmark width is computed)
*/
int _fixedTickMarkWidth;
void setFixedTickMarkWidth(int fixedTickMarkWidth) {
_fixedTickMarkWidth = fixedTickMarkWidth;
}
/**
* _labelFunc Function used to format label.
*/
boost::shared_ptr<LabelGenerator> _labelGenerator;
/**
* @brief constant lines on axis
*/
std::list<boost::shared_ptr<ConstantLine>> _constantLines;
/**
* @brief Reset for next time interval plot
*/
void reset()
{
_drawn = false;
_additionalObjDrawn = false;
_range = Range(_requestedRange);
for(auto constant : _constantLines)
constant.reset();
}
private:
/**
* @brief _range Limit of axis
*/
Range _range;
/*
* @brief Keep the range defined in the request
*/
Range _requestedRange;
/**
* @brief number of line for tickMark
*/
int _tickMarkLines;
/**
* @brief axe offset used for multi-axes
*/
double _axisOffset;
/*
* @brief axe units
*/
std::string _axisUnits;
};
std::ostream& operator <<(std::ostream& out, Axis& axis);
/**
* @brief Gets world coordinate space between 2 major ticks, returns 0 to let
* plplot do this it self.
*/
double getMajorTickSpace(Axis* axis, double min, double max);
/**
* @brief Gets number of minor tick between 2 major ones.
*/
int getMinorTickNumber(Axis* xAxis, double min, double max,
double majorTickSpace);
/**
* @brief Calculates major tick number on given axis.
*/
double getMajorTickNumber(Axis* axis, double min, double max);
} /* namespace plot */
#endif /* AXIS_HH_ */