sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
FrameSpecsOf.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/LineSpecsOf.hpp>
31 #include <sciplot/Utils.hpp>
32 
33 namespace sciplot {
34 
36 template <typename DerivedSpecs>
37 class FrameSpecsOf : virtual public Specs<DerivedSpecs>
38 {
39  public:
42 
44  auto frameShow(bool value=true) -> DerivedSpecs&;
45 
47  auto frameHide() -> DerivedSpecs&;
48 
50  auto frameLineStyle(int value) -> DerivedSpecs&;
51 
53  auto frameLineType(int value) -> DerivedSpecs&;
54 
56  auto frameLineWidth(int value) -> DerivedSpecs&;
57 
59  auto frameLineColor(std::string value) -> DerivedSpecs&;
60 
62  auto frameDashType(int value) -> DerivedSpecs&;
63 
65  auto repr() const -> std::string;
66 
67  private:
69  bool m_show;
70 
72  LineSpecs m_line_specs;
73 };
74 
76 class FrameSpecs : public FrameSpecsOf<FrameSpecs> {};
77 
78 template <typename DerivedSpecs>
80 {
81  frameShow(internal::DEFAULT_LEGEND_FRAME_SHOW);
82  frameLineWidth(internal::DEFAULT_LEGEND_FRAME_LINEWIDTH);
83  frameLineColor(internal::DEFAULT_LEGEND_FRAME_LINECOLOR);
84  frameLineType(internal::DEFAULT_LEGEND_FRAME_LINETYPE);
85 }
86 
87 template <typename DerivedSpecs>
88 auto FrameSpecsOf<DerivedSpecs>::frameShow(bool value) -> DerivedSpecs&
89 {
90  m_show = value;
91  return static_cast<DerivedSpecs&>(*this);
92 }
93 
94 template <typename DerivedSpecs>
96 {
97  return frameShow(false);
98 }
99 
100 template <typename DerivedSpecs>
101 auto FrameSpecsOf<DerivedSpecs>::frameLineStyle(int value) -> DerivedSpecs&
102 {
103  m_line_specs.lineStyle(value);
104  return static_cast<DerivedSpecs&>(*this);
105 }
106 
107 template <typename DerivedSpecs>
108 auto FrameSpecsOf<DerivedSpecs>::frameLineType(int value) -> DerivedSpecs&
109 {
110  m_line_specs.lineType(value);
111  return static_cast<DerivedSpecs&>(*this);
112 }
113 
114 template <typename DerivedSpecs>
115 auto FrameSpecsOf<DerivedSpecs>::frameLineWidth(int value) -> DerivedSpecs&
116 {
117  m_line_specs.lineWidth(value);
118  return static_cast<DerivedSpecs&>(*this);
119 }
120 
121 template <typename DerivedSpecs>
122 auto FrameSpecsOf<DerivedSpecs>::frameLineColor(std::string value) -> DerivedSpecs&
123 {
124  m_line_specs.lineColor(value);
125  return static_cast<DerivedSpecs&>(*this);
126 }
127 
128 template <typename DerivedSpecs>
129 auto FrameSpecsOf<DerivedSpecs>::frameDashType(int value) -> DerivedSpecs&
130 {
131  m_line_specs.dashType(value);
132  return static_cast<DerivedSpecs&>(*this);
133 }
134 
135 template <typename DerivedSpecs>
136 auto FrameSpecsOf<DerivedSpecs>::repr() const -> std::string
137 {
138  if(m_show == false)
139  return "nobox";
140 
141  std::stringstream ss;
142  ss << "box " << m_line_specs.repr();
143  return internal::removeExtraWhitespaces(ss.str());
144 }
145 
146 } // namespace sciplot
auto frameLineWidth(int value) -> DerivedSpecs &
Set the line width of the legend frame.
Definition: FrameSpecsOf.hpp:115
The class used to specify frame options.
Definition: FrameSpecsOf.hpp:76
auto lineWidth(int value) -> DerivedSpecs &
Set the line width of the underlying line object.
Definition: LineSpecsOf.hpp:101
auto frameDashType(int value) -> DerivedSpecs &
Set the dash type of the legend frame.
Definition: FrameSpecsOf.hpp:129
auto repr() const -> std::string
Convert this LineSpecsOf object into a gnuplot formatted string.
Definition: LineSpecsOf.hpp:122
auto lineColor(std::string value) -> DerivedSpecs &
Set the line color of the underlying line object.
Definition: LineSpecsOf.hpp:108
auto lineType(int value) -> DerivedSpecs &
Set the line type of the underlying line object.
Definition: LineSpecsOf.hpp:94
The class used to specify line options.
Definition: LineSpecsOf.hpp:79
auto frameLineType(int value) -> DerivedSpecs &
Set the line type of the legend frame.
Definition: FrameSpecsOf.hpp:108
auto frameLineStyle(int value) -> DerivedSpecs &
Set the line style of the legend frame.
Definition: FrameSpecsOf.hpp:101
FrameSpecsOf()
Construct a default FrameSpecsOf instance.
Definition: FrameSpecsOf.hpp:79
auto repr() const -> std::string
Convert this FrameSpecsOf object into a gnuplot formatted string.
Definition: FrameSpecsOf.hpp:136
The base class for other specs classes (e.g., LineSpecsOf, DrawSpecs, BorderSpecs,...
Definition: Specs.hpp:36
auto frameLineColor(std::string value) -> DerivedSpecs &
Set the line color of the legend frame.
Definition: FrameSpecsOf.hpp:122
auto lineStyle(int value) -> DerivedSpecs &
Set the line style of the underlying line object.
Definition: LineSpecsOf.hpp:87
auto frameHide() -> DerivedSpecs &
Set the visibility of the legend frame to a hidden status.
Definition: FrameSpecsOf.hpp:95
auto dashType(int value) -> DerivedSpecs &
Set the dash type of the underlying line object.
Definition: LineSpecsOf.hpp:115
auto frameShow(bool value=true) -> DerivedSpecs &
Set the visibility of the legend frame to a shown or hidden status.
Definition: FrameSpecsOf.hpp:88
The class used to attach frame options to a type.
Definition: FrameSpecsOf.hpp:38