sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
TicsSpecsMinor.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 // C++ includes
29 #include <vector>
30 
31 // sciplot includes
32 #include <sciplot/Default.hpp>
33 #include <sciplot/Utils.hpp>
34 #include <sciplot/specs/ShowSpecsOf.hpp>
35 
36 namespace sciplot
37 {
38 
40 class TicsSpecsMinor : public ShowSpecsOf<TicsSpecsMinor>
41 {
42  public:
44  TicsSpecsMinor(std::string axis);
45 
47  auto automatic() -> TicsSpecsMinor&;
48 
50  auto number(int value) -> TicsSpecsMinor&;
51 
53  auto repr() const -> std::string;
54 
55  private:
57  const std::string m_axis;
58 
60  std::string m_frequency;
61 };
62 
63 inline TicsSpecsMinor::TicsSpecsMinor(std::string axis)
64  : m_axis(axis)
65 {
66  if (axis.empty())
67  throw std::runtime_error(
68  "You have provided an empty string "
69  "in `axis` argument of constructor TicsSpecsMinor(axis).");
70 }
71 
73 {
74  m_frequency = "";
75  return *this;
76 }
77 
78 inline auto TicsSpecsMinor::number(int value) -> TicsSpecsMinor&
79 {
80  value = std::max<decltype(value)>(value, 0);
81  m_frequency = internal::str(value + 1);
82  return *this;
83 }
84 
85 inline auto TicsSpecsMinor::repr() const -> std::string
86 {
87  if (isHidden())
88  return "unset m" + m_axis + "tics";
89 
90  std::stringstream ss;
91  ss << "set m" << m_axis << "tics"
92  << " ";
93  ss << m_frequency;
94  return internal::removeExtraWhitespaces(ss.str());
95 }
96 
97 } // namespace sciplot
The class used to specify options for minor tics of a specific axis.
Definition: TicsSpecsMinor.hpp:41
auto repr() const -> std::string
Convert this TicsSpecsMinor object into a gnuplot formatted string.
Definition: TicsSpecsMinor.hpp:85
The class used to attach visibility options to a type.
Definition: ShowSpecsOf.hpp:36
auto isHidden() const -> bool
Return true if the underlying plot element is hidden.
Definition: ShowSpecsOf.hpp:81
auto automatic() -> TicsSpecsMinor &
Set the number of minor tics between major tics to be identified automatically.
Definition: TicsSpecsMinor.hpp:72
auto number(int value) -> TicsSpecsMinor &
Set the number of minor tics between major tics.
Definition: TicsSpecsMinor.hpp:78
TicsSpecsMinor(std::string axis)
Construct a default TicsSpecsMinor instance.
Definition: TicsSpecsMinor.hpp:63