Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 int min, const int max, const unsigned int incrementStep,
67  const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW, const bool drawFirstLabel = true);
68 
69 
70  void setNbGraduations(const unsigned int nbGraduations) {
71  this->nbGraduations = nbGraduations;
72  }
73 
74 
75  /**
76  * 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
77  *
78  * \param logScale If true, activate the logarithmic scale on the axis
79  * \param logBase If filled, set the logarithm base
80  */
81  void setLogScale(const bool logScale, const unsigned int logBase = 10);
82 
83  /**
84  * 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
85  */
86  void setAscendingOrder(const bool ascendingOrder) {
87  this->ascendingOrder = ascendingOrder;
88  }
89 
90  /**
91  * Method to update the axis drawing. It has to be called when one (or more) of the setters method above has been used.
92  * This method redraw the whole axis and the graduations.
93  */
94  void updateAxis();
95 
96  /**
97  * Method to get the axis point coordinates for a given value
98  *
99  * \param value the value we want to retrieve axis point coordinates
100  */
101  Coord getAxisPointCoordForValue(double value) const;
102 
103  /**
104  * Method to get the value associated to an axis point
105  *
106  * \param axisPointCoord the axis point coordinates we want to retrieve associated value
107  */
108  double getValueForAxisPoint(const Coord &axisPointCoord);
109 
110  /**
111  * Method to get the order of the values on the axis (ascending or descending)
112  */
113  bool hasAscendingOrder() const {
114  return ascendingOrder;
115  }
116 
117  double getAxisMinValue() const {
118  return min;
119  }
120 
121  double getAxisMaxValue() const {
122  return max;
123  }
124 
125 private :
126 
127  void buildAxisGraduations();
128  void addArrowDrawing();
129 
130  double min, max, scale;
131  double minLog, maxLog;
132  unsigned int nbGraduations;
133  LabelPosition axisGradsLabelsPosition;
134  bool drawFistLabel;
135  bool ascendingOrder;
136  bool addArrow;
137  Coord captionCenterCoord;
138  bool logScale;
139  unsigned int logBase;
140  bool integerScale;
141  unsigned int incrementStep;
142  bool minMaxSet;
143 
144 };
145 
146 }
147 
148 #endif /* GLQUANTITATIVEAXIS_H_ */
149 ///@endcond