sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
AxisLabelSpecs.hpp
1 // sciplot - a modern C++ scientific plotting library powered by gnuplot
2 // https://github.com/sciplot/sciplot
3 //
4 // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
5 //
6 // Copyright (c) 2018-2021 Allan Leal
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 // sciplot includes
29 #include <sciplot/Default.hpp>
30 #include <sciplot/specs/TextSpecsOf.hpp>
31 #include <sciplot/Utils.hpp>
32 
33 namespace sciplot {
34 
36 class AxisLabelSpecs : public TextSpecsOf<AxisLabelSpecs>
37 {
38  public:
40  AxisLabelSpecs(std::string axis);
41 
43  auto text(std::string text) -> AxisLabelSpecs&;
44 
46  auto rotateBy(int degrees) -> AxisLabelSpecs&;
47 
50 
52  auto rotateNone() -> AxisLabelSpecs&;
53 
55  auto repr() const -> std::string;
56 
57  private:
59  std::string m_axis;
60 
62  std::string m_text;
63 
65  std::string m_rotate;
66 };
67 
68 inline AxisLabelSpecs::AxisLabelSpecs(std::string axis)
69 : m_axis(axis)
70 {
71 }
72 
73 inline auto AxisLabelSpecs::text(std::string text) -> AxisLabelSpecs&
74 {
75  m_text = "'" + text + "'";
76  return *this;
77 }
78 
79 inline auto AxisLabelSpecs::rotateBy(int degrees) -> AxisLabelSpecs&
80 {
81  m_rotate = "rotate by " + std::to_string(degrees);
82  return *this;
83 }
84 
86 {
87  m_rotate = "rotate parallel";
88  return *this;
89 }
90 
92 {
93  m_rotate = "norotate";
94  return *this;
95 }
96 
97 inline auto AxisLabelSpecs::repr() const -> std::string
98 {
99  if(m_text.empty() && m_rotate.empty())
100  return "";
101 
102  std::stringstream ss;
103  ss << "set " + m_axis + "label ";
104  ss << m_text << " ";
105  ss << TextSpecsOf<AxisLabelSpecs>::repr() + " ";
106  ss << gnuplot::optionStr(m_rotate);
107  return internal::removeExtraWhitespaces(ss.str());
108 }
109 
110 } // namespace sciplot
auto rotateAxisParallel() -> AxisLabelSpecs &
Specify that the axis label should be rotated to be in parallel to the corresponding axis (for 3D plo...
Definition: AxisLabelSpecs.hpp:85
The specifications for an axis label (e.g., xlabel, ylabel, etc.)
Definition: AxisLabelSpecs.hpp:37
The class used to attach text options to a type.
Definition: TextSpecsOf.hpp:38
auto rotateNone() -> AxisLabelSpecs &
Specify that the axis label should not be rotated.
Definition: AxisLabelSpecs.hpp:91
auto text(std::string text) -> AxisLabelSpecs &
Set the text of the axis label.
Definition: AxisLabelSpecs.hpp:73
auto repr() const -> std::string
Convert this AxisLabelSpecs object into a gnuplot formatted string.
Definition: AxisLabelSpecs.hpp:97
AxisLabelSpecs(std::string axis)
Construct a default AxisLabelSpecs instance.
Definition: AxisLabelSpecs.hpp:68
auto rotateBy(int degrees) -> AxisLabelSpecs &
Specify that the axis label should be rotated by a given angle in degrees.
Definition: AxisLabelSpecs.hpp:79