sciplot  0.3.1
A modern C++ plotting library powered by gnuplot
HistogramStyleSpecs.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/specs/Specs.hpp>
30 #include <sciplot/Utils.hpp>
31 
32 namespace sciplot {
33 
35 class HistogramStyleSpecs : virtual public Specs<HistogramStyleSpecs>
36 {
37  public:
40 
42  auto clustered() -> HistogramStyleSpecs&;
43 
45  auto clusteredWithGap(double value) -> HistogramStyleSpecs&;
46 
49 
52 
54  auto errorBars() -> HistogramStyleSpecs&;
55 
57  auto errorBarsWithGap(double value) -> HistogramStyleSpecs&;
58 
60  auto errorBarsWithLineWidth(double value) -> HistogramStyleSpecs&;
61 
63  auto repr() const -> std::string;
64 
65  private:
67  std::string m_type;
68 
70  std::string m_gap_clustered;
71 
73  std::string m_gap_errorbars;
74 
76  std::string m_linewidth;
77 };
78 
80 {
81 }
82 
84 {
85  m_type = "clustered";
86  return *this;
87 }
88 
90 {
91  m_type = "clustered";
92  m_gap_clustered = "gap " + internal::str(value);
93  return *this;
94 }
95 
97 {
98  m_type = "rowstacked";
99  return *this;
100 }
101 
103 {
104  m_type = "columnstacked";
105  return *this;
106 }
107 
109 {
110  m_type = "errorbars";
111  return *this;
112 }
113 
115 {
116  m_type = "errorbars";
117  m_gap_errorbars = "gap " + internal::str(value);
118  return *this;
119 }
120 
122 {
123  m_type = "errorbars";
124  m_linewidth = "linewidth " + internal::str(value);
125  return *this;
126 }
127 
128 inline auto HistogramStyleSpecs::repr() const -> std::string
129 {
130  [[maybe_unused]] const auto supports_gap = (m_type == "clustered" || m_type == "errorbars");
131  [[maybe_unused]] const auto supports_linewidth = (m_type == "errorbars");
132 
133  std::stringstream ss;
134  ss << "set style histogram" << " ";
135  ss << m_type << " ";
136  if(m_type == "clustered") ss << m_gap_clustered << " ";
137  if(m_type == "errorbars") ss << m_gap_errorbars << " ";
138  if(m_type == "errorbars") ss << m_linewidth << " ";
139  return internal::removeExtraWhitespaces(ss.str());
140 }
141 
142 } // namespace sciplot
auto repr() const -> std::string
Convert this HistogramStyleSpecs object into a gnuplot formatted string.
Definition: HistogramStyleSpecs.hpp:128
auto rowStacked() -> HistogramStyleSpecs &
Set the histogram style to be stacked with groups formed using data along rows.
Definition: HistogramStyleSpecs.hpp:96
auto errorBarsWithLineWidth(double value) -> HistogramStyleSpecs &
Set the histogram style to be with error bars and also set its line width.
Definition: HistogramStyleSpecs.hpp:121
auto columnStacked() -> HistogramStyleSpecs &
Set the histogram style to be stacked with groups formed using data along columns.
Definition: HistogramStyleSpecs.hpp:102
auto errorBars() -> HistogramStyleSpecs &
Set the histogram style to be with error bars.
Definition: HistogramStyleSpecs.hpp:108
The class used to specify histogram style options.
Definition: HistogramStyleSpecs.hpp:36
HistogramStyleSpecs()
Construct a default HistogramStyleSpecs instance.
Definition: HistogramStyleSpecs.hpp:79
The base class for other specs classes (e.g., LineSpecsOf, DrawSpecs, BorderSpecs,...
Definition: Specs.hpp:36
auto clustered() -> HistogramStyleSpecs &
Set the histogram style to be clustered.
Definition: HistogramStyleSpecs.hpp:83
auto clusteredWithGap(double value) -> HistogramStyleSpecs &
Set the histogram style to be clustered with a given gap size.
Definition: HistogramStyleSpecs.hpp:89
auto errorBarsWithGap(double value) -> HistogramStyleSpecs &
Set the histogram style to be with error bars and also set its gap size.
Definition: HistogramStyleSpecs.hpp:114