sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
GridSpecs.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/GridSpecsBase.hpp>
31 #include <sciplot/Utils.hpp>
32 
33 namespace sciplot {
34 
36 class GridSpecs : public GridSpecsBase
37 {
38  public:
40  GridSpecs();
41 
43  auto xtics() -> GridSpecsBase& { return xticsMajorBottom(); }
44 
46  auto ytics() -> GridSpecsBase& { return yticsMajorLeft(); }
47 
49  auto ztics() -> GridSpecsBase& { return zticsMajor(); }
50 
52  auto rtics() -> GridSpecsBase& { return rticsMajor(); }
53 
55  auto xticsMajorBottom() -> GridSpecsBase& { return _gridmajor("xtics"); }
56 
58  auto xticsMajorTop() -> GridSpecsBase& { return _gridmajor("x2tics"); }
59 
61  auto xticsMinorBottom() -> GridSpecsBase& { return _gridminor("mxtics"); }
62 
64  auto xticsMinorTop() -> GridSpecsBase& { return _gridminor("mx2tics"); }
65 
67  auto yticsMajorLeft() -> GridSpecsBase& { return _gridmajor("ytics"); }
68 
70  auto yticsMajorRight() -> GridSpecsBase& { return _gridmajor("y2tics"); }
71 
73  auto yticsMinorLeft() -> GridSpecsBase& { return _gridminor("mytics"); }
74 
76  auto yticsMinorRight() -> GridSpecsBase& { return _gridminor("my2tics"); }
77 
79  auto zticsMajor() -> GridSpecsBase& { return _gridmajor("ztics"); }
80 
82  auto zticsMinor() -> GridSpecsBase& { return _gridminor("mztics"); }
83 
85  auto rticsMajor() -> GridSpecsBase& { return _gridmajor("rtics"); }
86 
88  auto rticsMinor() -> GridSpecsBase& { return _gridminor("mrtics"); }
89 
91  auto repr() const -> std::string;
92 
93  private:
95  auto _gridmajor(std::string tics) -> GridSpecsBase&
96  {
97  m_gridticsspecs.emplace_back(tics, true);
98  return m_gridticsspecs.back();
99  }
100 
102  auto _gridminor(std::string tics) -> GridSpecsBase&
103  {
104  m_gridticsspecs.emplace_back(tics, false);
105  return m_gridticsspecs.back();
106  }
107 
108  private:
110  std::vector<GridSpecsBase> m_gridticsspecs;
111 };
112 
114 : GridSpecsBase("", true)
115 {
116  show(false);
117  back();
118 }
119 
120 inline auto GridSpecs::repr() const -> std::string
121 {
122  std::stringstream ss;
123  ss << GridSpecsBase::repr();
124  for (auto specs : m_gridticsspecs)
125  ss << '\n'
126  << specs.repr();
127  return ss.str();
128 }
129 
130 } // namespace sciplot
auto yticsMajorLeft() -> GridSpecsBase &
Return the specifications of the grid lines along major ytics on the left axis.
Definition: GridSpecs.hpp:67
The class used to specify options for grid.
Definition: GridSpecs.hpp:37
auto ztics() -> GridSpecsBase &
Return the specifications of the grid lines along major ztics.
Definition: GridSpecs.hpp:49
The class used to specify options for grid lines along axis tics (major or minor).
Definition: GridSpecsBase.hpp:39
auto show(bool value=true) -> GridSpecsBase &
Set the visibility status of the plot element.
Definition: ShowSpecsOf.hpp:68
auto xtics() -> GridSpecsBase &
Return the specifications of the grid lines along major xtics on the bottom axis.
Definition: GridSpecs.hpp:43
auto xticsMajorTop() -> GridSpecsBase &
Return the specifications of the grid lines along major xtics on the top axis.
Definition: GridSpecs.hpp:58
GridSpecs()
Construct a default GridSpecs instance.
Definition: GridSpecs.hpp:113
auto xticsMinorTop() -> GridSpecsBase &
Return the specifications of the grid lines along minor xtics on the top axis.
Definition: GridSpecs.hpp:64
auto zticsMajor() -> GridSpecsBase &
Return the specifications of the grid lines along major ztics.
Definition: GridSpecs.hpp:79
auto xticsMajorBottom() -> GridSpecsBase &
Return the specifications of the grid lines along major xtics on the bottom axis.
Definition: GridSpecs.hpp:55
auto rtics() -> GridSpecsBase &
Return the specifications of the grid lines along major rtics.
Definition: GridSpecs.hpp:52
auto repr() const -> std::string
Convert this GridSpecsBase object into a gnuplot formatted string.
Definition: GridSpecsBase.hpp:66
auto repr() const -> std::string
Convert this GridSpecs object into a gnuplot formatted string.
Definition: GridSpecs.hpp:120
auto rticsMinor() -> GridSpecsBase &
Return the specifications of the grid lines along minor rtics.
Definition: GridSpecs.hpp:88
auto back() -> GridSpecsBase &
Set the underlying plot element to be displayed on the back of all plot elements.
Definition: DepthSpecsOf.hpp:77
auto xticsMinorBottom() -> GridSpecsBase &
Return the specifications of the grid lines along minor xtics on the bottom axis.
Definition: GridSpecs.hpp:61
auto zticsMinor() -> GridSpecsBase &
Return the specifications of the grid lines along minor ztics.
Definition: GridSpecs.hpp:82
GridSpecsBase(std::string tics="", bool majortics=true)
Construct a default GridSpecsBase instance.
Definition: GridSpecsBase.hpp:55
auto yticsMinorLeft() -> GridSpecsBase &
Return the specifications of the grid lines along minor ytics on the left axis.
Definition: GridSpecs.hpp:73
auto ytics() -> GridSpecsBase &
Return the specifications of the grid lines along major ytics on the left axis.
Definition: GridSpecs.hpp:46
auto yticsMajorRight() -> GridSpecsBase &
Return the specifications of the grid lines along major ytics on the right axis.
Definition: GridSpecs.hpp:70
auto rticsMajor() -> GridSpecsBase &
Return the specifications of the grid lines along minor rtics.
Definition: GridSpecs.hpp:85
auto yticsMinorRight() -> GridSpecsBase &
Return the specifications of the grid lines along minor ytics on the right axis.
Definition: GridSpecs.hpp:76