TBTK
Need a break? Support the development by playing Polarity Puzzles
PlotParameters.h
Go to the documentation of this file.
1 /* Copyright 2019 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_VISUALIZATION_MAT_PLOT_LIB_PLOT_PARAMETERS
24 #define COM_DAFER45_TBTK_VISUALIZATION_MAT_PLOT_LIB_PLOT_PARAMETERS
25 
26 #include "TBTK/Visualization/MatPlotLib/matplotlibcpp.h"
27 
28 #include <string>
29 #include <utility>
30 
31 namespace TBTK{
32 namespace Visualization{
33 namespace MatPlotLib{
34 
36 public:
39 
41  void setTitle(const std::string &title, bool overwrite = true);
42 
44  void setLabelX(const std::string &labelX, bool overwrite = true);
45 
47  void setLabelY(const std::string &labelY, bool overwrite = true);
48 
50  void setBoundsX(double minX, double maxX, bool overwrite = true);
51 
53  void setBoundsY(double minY, double maxY, bool overwrite = true);
54 
56  void flush() const;
57 
59  void clear();
60 private:
61  std::pair<bool, std::string> title;
62  std::pair<bool, std::string> labelX;
63  std::pair<bool, std::string> labelY;
64  std::pair<bool, double> minX;
65  std::pair<bool, double> maxX;
66  std::pair<bool, double> minY;
67  std::pair<bool, double> maxY;
68 };
69 
71 ) :
72  title(false, ""),
73  labelX(false, ""),
74  labelY(false, ""),
75  minX(false, 0),
76  maxX(false, 1),
77  minY(false, 0),
78  maxY(false, 1)
79 {
80 }
81 
82 inline void PlotParameters::setTitle(const std::string &title, bool overwrite){
83  if(overwrite || !this->title.first)
84  this->title = {true, title};
85 }
86 
88  const std::string &labelX,
89  bool overwrite
90 ){
91  if(overwrite || !this->labelX.first)
92  this->labelX = {true, labelX};
93 }
94 
96  const std::string &labelY,
97  bool overwrite
98 ){
99  if(overwrite || !this->labelY.first)
100  this->labelY = {true, labelY};
101 }
102 
104  double minX,
105  double maxX,
106  bool overwrite
107 ){
108  if(overwrite || !this->minX.first)
109  this->minX = {true, minX};
110  if(overwrite || !this->maxX.first)
111  this->maxX = {true, maxX};
112 }
113 
115  double minY,
116  double maxY,
117  bool overwrite
118 ){
119  if(overwrite || !this->minY.first)
120  this->minY = {true, minY};
121  if(overwrite || !this->maxY.first)
122  this->maxY = {true, maxY};
123 }
124 
125 inline void PlotParameters::flush() const{
126  if(title.first)
127  matplotlibcpp::title(title.second);
128  if(labelX.first)
129  matplotlibcpp::xlabel(labelX.second);
130  if(labelY.first)
131  matplotlibcpp::ylabel(labelY.second);
132  if(minX.first)
133  matplotlibcpp::xlim(minX.second, maxX.second);
134  if(minY.first)
135  matplotlibcpp::ylim(minY.second, maxY.second);
136 }
137 
138 inline void PlotParameters::clear(){
139  title = {false, ""};
140  labelX = {false, ""};
141  labelY = {false, ""};
142  minX = {false, 0};
143  maxX = {false, 1};
144  minY = {false, 0};
145  maxY = {false, 1};
146 }
147 
148 }; //End namespace MatPlotLib
149 }; //End namespace Visualization
150 }; //End namespace TBTK
151 
152 #endif
TBTK::Visualization::MatPlotLib::PlotParameters::flush
void flush() const
Definition: PlotParameters.h:125
TBTK::Visualization::MatPlotLib::PlotParameters
Definition: PlotParameters.h:35
TBTK::Visualization::MatPlotLib::PlotParameters::setLabelY
void setLabelY(const std::string &labelY, bool overwrite=true)
Definition: PlotParameters.h:95
TBTK::Visualization::MatPlotLib::PlotParameters::setBoundsX
void setBoundsX(double minX, double maxX, bool overwrite=true)
Definition: PlotParameters.h:103
TBTK::Visualization::MatPlotLib::PlotParameters::clear
void clear()
Definition: PlotParameters.h:138
TBTK::Visualization::MatPlotLib::PlotParameters::PlotParameters
PlotParameters()
Definition: PlotParameters.h:70
TBTK::Visualization::MatPlotLib::PlotParameters::setLabelX
void setLabelX(const std::string &labelX, bool overwrite=true)
Definition: PlotParameters.h:87
TBTK::Visualization::MatPlotLib::PlotParameters::setTitle
void setTitle(const std::string &title, bool overwrite=true)
Definition: PlotParameters.h:82
TBTK::Visualization::MatPlotLib::PlotParameters::setBoundsY
void setBoundsY(double minY, double maxY, bool overwrite=true)
Definition: PlotParameters.h:114