Tulip  5.0.0
Large graphs analysis and drawing
GlQuantitativeAxis.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 
22 #ifndef GLQUANTITATIVEAXIS_H_
23 #define GLQUANTITATIVEAXIS_H_
24 
25 #include <tulip/GlAxis.h>
26 
27 namespace tlp {
28 
29 /**
30  * \brief A class to render an axis graduated with numerical values for a given range
31  *
32  * This class allows to draw a quantitative axis (i.e. an axis axis graduated with numerical values for a given range)
33  */
34 class TLP_GL_SCOPE GlQuantitativeAxis : public GlAxis {
35 
36 public :
37 
38  /**
39  * GlQuantitativeAxis constructor. Create an quantitative axis without graduations (need to call 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, if vertical it is the down end)
43  * \axisLength the length of the axis
44  * \axisOrientation the orientation of the axis, 2 possible values (HORIZONTAL_AXIS or VERTICAL_AXIS)
45  * \axisColor the color of the axis
46  * \addArrow If true, an arrow will be added to one end of the axis according to the axis order (ascending or descending)
47  * \ascendingOrder If true, the min value will be at the bottom end and the max will be at the top end if the axis is vertical (min at the left and max at the right if it is horizontal). If false this positions are switched
48  */
49  GlQuantitativeAxis(const std::string &axisName, const Coord &axisBaseCoord, const float axisLength,
50  const AxisOrientation &axisOrientation, const Color &axisColor,
51  const bool addArrow = true, const bool ascendingOrder = true);
52 
53  /**
54  * Method to set the quantitative axis parameters. A call to updateAxis has to be done after calling this method to build or update the axis graduations
55  *
56  * \param min the min value of the range the axis represents
57  * \param max the max value of the range the axis represents
58  * \param nbGraduations the number of graduations to build
59  * \param axisGradsLabelsPosition the relative position of the axis graduations label. Two possible values : LEFT_OR_BELOW (if the axis is vertical, labels will be on the left of the axis, otherwise below) or RIGHT_OR_ABOVE
60  * \param drawFirstLabel If false, the first graduation label will not be drawn (usefull when some axis have the same base coord to avoid labels overlapping)
61  */
62  void setAxisParameters(const double min, const double max, const unsigned int nbGraduations,
63  const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW, const bool drawFirstLabel = true);
64 
65 
66  void setAxisParameters(const long long min, const long long max, const unsigned long long incrementStep,
67  const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW, const bool drawFirstLabel = true);
68 
69  void setAxisParameters(const int min, const int max, const unsigned int incrementStep,
70  const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW, const bool drawFirstLabel = true) {
71  setAxisParameters((long long) min, (long long) max, (unsigned long long) incrementStep, axisGradsLabelsPosition, drawFirstLabel);
72  }
73 
74  void setNbGraduations(const unsigned int nbGraduations) {
75  this->nbGraduations = nbGraduations;
76  }
77 
78 
79  /**
80  * Method to set a logarithmic scale on the axis. A call to updateAxis has to be done after calling this method to build or update the axis graduations
81  *
82  * \param logScale If true, activate the logarithmic scale on the axis
83  * \param logBase If filled, set the logarithm base
84  */
85  void setLogScale(const bool logScale, const unsigned int logBase = 10);
86 
87  /**
88  * Method to set the order of the values on the axis (ascending or descending). A call to updateAxis has to be done after calling this method to build or update the axis graduations
89  */
90  void setAscendingOrder(const bool ascendingOrder) {
91  this->ascendingOrder = ascendingOrder;
92  }
93 
94  /**
95  * Method to update the axis drawing. It has to be called when one (or more) of the setters method above has been used.
96  * This method redraw the whole axis and the graduations.
97  */
98  void updateAxis();
99 
100  /**
101  * Method to get the axis point coordinates for a given value
102  *
103  * \param value the value we want to retrieve axis point coordinates
104  */
105  Coord getAxisPointCoordForValue(double value) const;
106 
107  /**
108  * Method to get the value associated to an axis point
109  *
110  * \param axisPointCoord the axis point coordinates we want to retrieve associated value
111  */
112  double getValueForAxisPoint(const Coord &axisPointCoord);
113 
114  /**
115  * Method to get the order of the values on the axis (ascending or descending)
116  */
117  bool hasAscendingOrder() const {
118  return ascendingOrder;
119  }
120 
121  double getAxisMinValue() const {
122  return min;
123  }
124 
125  double getAxisMaxValue() const {
126  return max;
127  }
128 
129 private :
130 
131  void buildAxisGraduations();
132  void addArrowDrawing();
133 
134  double min, max, scale;
135  double minLog, maxLog;
136  unsigned int nbGraduations;
137  LabelPosition axisGradsLabelsPosition;
138  bool drawFistLabel;
139  bool ascendingOrder;
140  bool addArrow;
141  Coord captionCenterCoord;
142  bool logScale;
143  unsigned int logBase;
144  bool integerScale;
145  unsigned long long incrementStep;
146  bool minMaxSet;
147 
148 };
149 
150 }
151 
152 #endif /* GLQUANTITATIVEAXIS_H_ */
153 ///@endcond