Tulip  5.2.0
Large graphs analysis and drawing
GlNominativeAxis.h
1 /*
2  *
3  * This file is part of Tulip (http://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 GLNOMINATIVEAXIS_H_
22 #define GLNOMINATIVEAXIS_H_
23 
24 #include <map>
25 
26 #include <tulip/GlAxis.h>
27 
28 namespace tlp {
29 
30 /**
31  * \brief A class to render an axis graduated with string values
32  *
33  * This class allow to draw a nominative axis (i.e. an axis graduated with string values)
34  */
35 class TLP_GL_SCOPE GlNominativeAxis : public GlAxis {
36 
37 public:
38  /**
39  * GlNominativeAxis constructor. Build a nominative axis with no graduations (need to call
40  * setAxisGraduationsLabels to build them)
41  *
42  * \param axisName the name of the axis
43  * \axisBaseCoord the base coord of the axis (if the axis is horizontal, it is the the left end,
44  * if vertical it is the down end)
45  * \axisLength the length of the axis
46  * \axisOrientation the orientation of the axis, 2 possible values (HORIZONTAL_AXIS or
47  * VERTICAL_AXIS)
48  * \axisColor the color of the axis
49  */
50  GlNominativeAxis(const std::string &axisName, const Coord &axisBaseCoord, const float axisLength,
51  const AxisOrientation &axisOrientation, const Color &axisColor);
52 
53  /**
54  * Method to set the axis graduations labels. A call to updateAxis has to be done after calling
55  * this method to build or update the axis graduations. The labels will be placed on the axis in
56  * the same order as the vector passed as parameter (from bottom to top if the axis is vertical,
57  * from left to right if it is horizontal).
58  *
59  * \param axisGradsLabels a vector of string containing the graduations labels
60  * \param labelsPosition the relative position of the axis graduations label. Two possible values
61  * : LEFT_OR_BELOW (if the axis is vertical, labels will be on the left of the axis, otherwise
62  * below) or RIGHT_OR_ABOVE
63  */
64  void setAxisGraduationsLabels(const std::vector<std::string> &axisGradsLabels,
65  const LabelPosition &labelsPosition);
66 
67  /**
68  * Method to update the axis drawing. It has to be called when one (or more) of the setters method
69  * above has been used.
70  * This method redraw the whole axis and the graduations.
71  */
72  void updateAxis() override;
73 
74  /**
75  * Method to get the axis point coordinates associated to string value
76  *
77  * \param value the string value we want to retrieve axis point coordinates
78  */
79  Coord getAxisPointCoordForValue(const std::string &value);
80 
81  /**
82  * Method to get the string value associated to an axis point. Return "" if there is not.
83  *
84  * \param axisPointCoord the axis point coordinates we want to retrieve the associated string
85  * value
86  */
87  std::string getValueAtAxisPoint(const Coord &axisPointCoord);
88 
89  void translate(const Coord &c) override;
90 
91 private:
92  void buildAxisGraduations();
93 
94  std::vector<std::string> labelsOrder;
95  std::map<std::string, Coord> labelsCoord;
96  LabelPosition axisLabelsPosition;
97 };
98 }
99 
100 #endif /* GLNOMINATIVEAXIS_H_ */
101 ///@endcond