sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
TitleSpecsOf.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/specs/OffsetSpecsOf.hpp>
32 #include <sciplot/Utils.hpp>
33 
34 namespace sciplot {
35 
37 template <typename DerivedSpecs>
38 class TitleSpecsOf : virtual public Specs<DerivedSpecs>
39 {
40  public:
43 
45  auto title(std::string title) -> DerivedSpecs&;
46 
48  auto titleShiftAlongX(double chars) -> DerivedSpecs&;
49 
51  auto titleShiftAlongY(double chars) -> DerivedSpecs&;
52 
54  auto titleShiftAlongGraphX(double val) -> DerivedSpecs&;
55 
57  auto titleShiftAlongGraphY(double val) -> DerivedSpecs&;
58 
60  auto titleShiftAlongScreenX(double val) -> DerivedSpecs&;
61 
63  auto titleShiftAlongScreenY(double val) -> DerivedSpecs&;
64 
66  auto titleTextColor(std::string color) -> DerivedSpecs&;
67 
69  auto titleFontName(std::string name) -> DerivedSpecs&;
70 
72  auto titleFontSize(int size) -> DerivedSpecs&;
73 
75  auto repr() const -> std::string;
76 
77  private:
79  std::string m_title;
80 
82  TextSpecs m_text_specs;
83 
85  OffsetSpecs m_offset_specs;
86 };
87 
89 class TitleSpecs : public TitleSpecsOf<TitleSpecs> {};
90 
91 template <typename DerivedSpecs>
93 {
94  title("");
95 }
96 
97 template <typename DerivedSpecs>
98 auto TitleSpecsOf<DerivedSpecs>::title(std::string title) -> DerivedSpecs&
99 {
100  m_title = "'" + title + "'";
101  return static_cast<DerivedSpecs&>(*this);
102 }
103 
104 template <typename DerivedSpecs>
105 auto TitleSpecsOf<DerivedSpecs>::titleShiftAlongX(double chars) -> DerivedSpecs&
106 {
107  m_offset_specs.shiftAlongX(chars);
108  return static_cast<DerivedSpecs&>(*this);
109 }
110 
111 template <typename DerivedSpecs>
112 auto TitleSpecsOf<DerivedSpecs>::titleShiftAlongY(double chars) -> DerivedSpecs&
113 {
114  m_offset_specs.shiftAlongY(chars);
115  return static_cast<DerivedSpecs&>(*this);
116 }
117 
118 template <typename DerivedSpecs>
119 auto TitleSpecsOf<DerivedSpecs>::titleShiftAlongGraphX(double val) -> DerivedSpecs&
120 {
121  m_offset_specs.shiftAlongGraphX(val);
122  return static_cast<DerivedSpecs&>(*this);
123 }
124 
125 template <typename DerivedSpecs>
126 auto TitleSpecsOf<DerivedSpecs>::titleShiftAlongGraphY(double val) -> DerivedSpecs&
127 {
128  m_offset_specs.shiftAlongGraphY(val);
129  return static_cast<DerivedSpecs&>(*this);
130 }
131 
132 template <typename DerivedSpecs>
133 auto TitleSpecsOf<DerivedSpecs>::titleShiftAlongScreenX(double val) -> DerivedSpecs&
134 {
135  m_offset_specs.shiftAlongScreenX(val);
136  return static_cast<DerivedSpecs&>(*this);
137 }
138 
139 template <typename DerivedSpecs>
140 auto TitleSpecsOf<DerivedSpecs>::titleShiftAlongScreenY(double val) -> DerivedSpecs&
141 {
142  m_offset_specs.shiftAlongScreenY(val);
143  return static_cast<DerivedSpecs&>(*this);
144 }
145 
146 template <typename DerivedSpecs>
147 auto TitleSpecsOf<DerivedSpecs>::titleTextColor(std::string color) -> DerivedSpecs&
148 {
149  m_text_specs.textColor(color);
150  return static_cast<DerivedSpecs&>(*this);
151 }
152 
153 template <typename DerivedSpecs>
154 auto TitleSpecsOf<DerivedSpecs>::titleFontName(std::string name) -> DerivedSpecs&
155 {
156  m_text_specs.fontName(name);
157  return static_cast<DerivedSpecs&>(*this);
158 }
159 
160 template <typename DerivedSpecs>
161 auto TitleSpecsOf<DerivedSpecs>::titleFontSize(int size) -> DerivedSpecs&
162 {
163  m_text_specs.fontSize(size);
164  return static_cast<DerivedSpecs&>(*this);
165 }
166 
167 template <typename DerivedSpecs>
168 auto TitleSpecsOf<DerivedSpecs>::repr() const -> std::string
169 {
170  if(m_title == "''")
171  return "";
172 
173  std::stringstream ss;
174  ss << "title " << m_title << " ";
175  ss << m_text_specs.repr() << " ";
176  ss << m_offset_specs.repr();
177  return internal::removeExtraWhitespaces(ss.str());
178 }
179 
180 } // namespace sciplot
auto titleShiftAlongGraphY(double val) -> DerivedSpecs &
Shift the title element along the y direction within the graph coordinate system.
Definition: TitleSpecsOf.hpp:126
The class used to specify offset options.
Definition: OffsetSpecsOf.hpp:73
auto textColor(std::string color) -> DerivedSpecs &
Set the color of the text (e.g., "blue", "#404040")
Definition: TextSpecsOf.hpp:75
auto titleShiftAlongY(double chars) -> DerivedSpecs &
Shift the title element along the y direction by given number of characters (can be fraction).
Definition: TitleSpecsOf.hpp:112
auto shiftAlongY(double chars) -> DerivedSpecs &
Shift the underlying plot element along the y direction by given number of characters (can be fractio...
Definition: OffsetSpecsOf.hpp:88
auto shiftAlongX(double chars) -> DerivedSpecs &
Shift the underlying plot element along the x direction by given number of characters (can be fractio...
Definition: OffsetSpecsOf.hpp:81
The class used to attach title options to a type.
Definition: TitleSpecsOf.hpp:39
auto fontSize(std::size_t size) -> DerivedSpecs &
Set the point size of the font (e.g., 10, 12, 16).
Definition: FontSpecsOf.hpp:74
auto title(std::string title) -> DerivedSpecs &
Set the text of the title.
Definition: TitleSpecsOf.hpp:98
auto titleShiftAlongGraphX(double val) -> DerivedSpecs &
Shift the title element along the x direction within the graph coordinate system.
Definition: TitleSpecsOf.hpp:119
auto shiftAlongScreenY(double val) -> DerivedSpecs &
Shift the underlying plot element along the y direction within the screen coordinate system.
Definition: OffsetSpecsOf.hpp:116
auto repr() const -> std::string
Convert this OffsetSpecsOf object into a gnuplot formatted string.
Definition: OffsetSpecsOf.hpp:123
auto repr() const -> std::string
Convert this TextSpecsOf object into a gnuplot formatted string.
Definition: TextSpecsOf.hpp:89
auto titleShiftAlongX(double chars) -> DerivedSpecs &
Shift the title element along the x direction by given number of characters (can be fraction).
Definition: TitleSpecsOf.hpp:105
The class used to specify text options.
Definition: TextSpecsOf.hpp:65
auto titleShiftAlongScreenY(double val) -> DerivedSpecs &
Shift the title element along the y direction within the screen coordinate system.
Definition: TitleSpecsOf.hpp:140
The base class for other specs classes (e.g., LineSpecsOf, DrawSpecs, BorderSpecs,...
Definition: Specs.hpp:36
auto fontName(std::string name) -> DerivedSpecs &
Set the name of the font (e.g., Helvetica, Georgia, Times).
Definition: FontSpecsOf.hpp:67
auto titleTextColor(std::string color) -> DerivedSpecs &
Set the color of the title text (e.g., "blue", "#404040")
Definition: TitleSpecsOf.hpp:147
auto repr() const -> std::string
Convert this TitleSpecsOf object into a gnuplot formatted string.
Definition: TitleSpecsOf.hpp:168
auto shiftAlongScreenX(double val) -> DerivedSpecs &
Shift the underlying plot element along the x direction within the screen coordinate system.
Definition: OffsetSpecsOf.hpp:109
TitleSpecsOf()
Construct a default TitleSpecsOf instance.
Definition: TitleSpecsOf.hpp:92
auto shiftAlongGraphX(double val) -> DerivedSpecs &
Shift the underlying plot element along the x direction within the graph coordinate system.
Definition: OffsetSpecsOf.hpp:95
auto titleShiftAlongScreenX(double val) -> DerivedSpecs &
Shift the title element along the x direction within the screen coordinate system.
Definition: TitleSpecsOf.hpp:133
The class used to specify title options.
Definition: TitleSpecsOf.hpp:89
auto shiftAlongGraphY(double val) -> DerivedSpecs &
Shift the underlying plot element along the y direction within the graph coordinate system.
Definition: OffsetSpecsOf.hpp:102
auto titleFontSize(int size) -> DerivedSpecs &
Set the font point size of the title text (e.g., 10, 12, 16).
Definition: TitleSpecsOf.hpp:161
auto titleFontName(std::string name) -> DerivedSpecs &
Set the font name of the title text (e.g., Helvetica, Georgia, Times).
Definition: TitleSpecsOf.hpp:154