Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
GlQuantitativeAxis.h
1/*
2 *
3 * This file is part of Tulip (https://tulip.labri.fr)
4 *
5 * Authors: David Auber and the Tulip development Team
6 * from LaBRI, University of Bordeaux
7 *
8 * Tulip is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * Tulip is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 */
19///@cond DOXYGEN_HIDDEN
20
21#ifndef GLQUANTITATIVEAXIS_H_
22#define GLQUANTITATIVEAXIS_H_
23
24#include <tulip/GlAxis.h>
25
26namespace tlp {
27
28/**
29 * \brief A class to render an axis graduated with numerical values for a given range
30 *
31 * This class allows to draw a quantitative axis (i.e. an axis axis graduated with numerical values
32 * for a given range)
33 */
34class TLP_GL_SCOPE GlQuantitativeAxis : public GlAxis {
35
36public:
37 /**
38 * GlQuantitativeAxis constructor. Create an quantitative axis without graduations (need to call
39 * setAxisParameters to build them)
40 *
41 * \param axisName the name of the axis
42 * \axisBaseCoord the base coord of the axis (if the axis is horizontal, it is the the left end,
43 * if vertical it is the down end)
44 * \axisLength the length of the axis
45 * \axisOrientation the orientation of the axis, 2 possible values (HORIZONTAL_AXIS or
46 * VERTICAL_AXIS)
47 * \axisColor the color of the axis
48 * \addArrow If true, an arrow will be added to one end of the axis according to the axis order
49 * (ascending or descending)
50 * \ascendingOrder If true, the min value will be at the bottom end and the max will be at the top
51 * end if the axis is vertical (min at the left and max at the right if it is horizontal). If
52 * false this positions are switched
53 */
54 GlQuantitativeAxis(const std::string &axisName, const Coord &axisBaseCoord,
55 const float axisLength, const AxisOrientation &axisOrientation,
56 const Color &axisColor, const bool addArrow = true,
57 const bool ascendingOrder = true);
58
59 /**
60 * Method to set the quantitative axis parameters. A call to updateAxis has to be done after
61 * calling this method to build or update the axis graduations
62 *
63 * \param min the min value of the range the axis represents
64 * \param max the max value of the range the axis represents
65 * \param nbGraduations the number of graduations to build
66 * \param axisGradsLabelsPosition the relative position of the axis graduations label. Two
67 * possible values : LEFT_OR_BELOW (if the axis is vertical, labels will be on the left of the
68 * axis, otherwise below) or RIGHT_OR_ABOVE
69 * \param drawFirstLabel If false, the first graduation label will not be drawn (useful when some
70 * axes have the same base coord to avoid labels overlapping)
71 */
72 void setAxisParameters(const double min, const double max, const unsigned int nbGraduations,
73 const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW,
74 const bool drawFirstLabel = true);
75
76 void setAxisParameters(const long long min, const long long max,
77 const unsigned long long incrementStep,
78 const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW,
79 const bool drawFirstLabel = true);
80
81 void setAxisParameters(const int min, const int max, const unsigned int incrementStep,
82 const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW,
83 const bool drawFirstLabel = true) {
84 setAxisParameters(static_cast<long long>(min), static_cast<long long>(max),
85 static_cast<unsigned long long>(incrementStep), axisGradsLabelsPosition,
86 drawFirstLabel);
87 }
88
89 void setNbGraduations(const unsigned int nbGraduations) {
90 this->nbGraduations = nbGraduations;
91 }
92
93 /**
94 * Method to set a logarithmic scale on the axis. A call to updateAxis has to be done after
95 * calling this method to build or update the axis graduations
96 *
97 * \param logScale If true, activate the logarithmic scale on the axis
98 * \param logBase If filled, set the logarithm base
99 */
100 void setLogScale(const bool logScale, const unsigned int logBase = 10);
101
102 /**
103 * Method to set the order of the values on the axis (ascending or descending). A call to
104 * updateAxis has to be done after calling this method to build or update the axis graduations
105 */
106 void setAscendingOrder(const bool ascendingOrder) {
107 this->ascendingOrder = ascendingOrder;
108 }
109
110 /**
111 * Method to update the axis drawing. It has to be called when one (or more) of the setters method
112 * above has been used.
113 * This method redraw the whole axis and the graduations.
114 */
115 void updateAxis() override;
116
117 /**
118 * Method to get the axis point coordinates for a given value
119 *
120 * \param value the value we want to retrieve axis point coordinates
121 */
122 Coord getAxisPointCoordForValue(double value) const;
123
124 /**
125 * Method to get the value associated to an axis point
126 *
127 * \param axisPointCoord the axis point coordinates we want to retrieve associated value
128 */
129 double getValueForAxisPoint(const Coord &axisPointCoord);
130
131 /**
132 * Method to get the order of the values on the axis (ascending or descending)
133 */
134 bool hasAscendingOrder() const {
135 return ascendingOrder;
136 }
137
138 double getAxisMinValue() const {
139 return min;
140 }
141
142 double getAxisMaxValue() const {
143 return max;
144 }
145
146private:
147 void buildAxisGraduations();
148 void addArrowDrawing();
149
150 double min, max, scale;
151 double minLog, maxLog;
152 unsigned int nbGraduations;
153 LabelPosition axisGradsLabelsPosition;
154 bool drawFistLabel;
155 bool ascendingOrder;
156 bool addArrow;
157 Coord captionCenterCoord;
158 bool logScale;
159 unsigned int logBase;
160 bool integerScale;
161 unsigned long long incrementStep;
162 bool minMaxSet;
163};
164} // namespace tlp
165
166#endif /* GLQUANTITATIVEAXIS_H_ */
167///@endcond