24 #ifndef COM_DAFER45_TBTK_CANVAS_2D
25 #define COM_DAFER45_TBTK_CANVAS_2D
27 #include "TBTK/Canvas.h"
35 class Canvas2D :
public Canvas{
44 void setBoundsX(
double minX,
double maxX);
47 void setBoundsY(
double minY,
double maxY);
50 void setBounds(
double minX,
double maxX,
double minY,
double maxY);
53 double getMinX()
const;
56 double getMaxX()
const;
59 double getMinY()
const;
62 double getMaxY()
const;
65 void setLabelX(
const std::string &labelX);
68 void setLabelY(
const std::string &labelY);
71 const std::string& getLabelX()
const;
74 const std::string& getLabelY()
const;
77 void setHold(
bool hold);
81 const std::vector<double> &y,
82 const std::string &title =
"",
83 const std::vector<unsigned char> &color = {0, 0, 0},
89 const std::vector<double> &x,
90 const std::vector<double> &y,
91 const std::string &title =
"",
92 const std::vector<unsigned char> &color = {0, 0, 0},
102 unsigned int getNumDataSets()
const;
109 const std::vector<double>& getX(
unsigned int dataSet)
const;
116 const std::vector<double>& getY(
unsigned int dataSet)
const;
123 const std::string& getTitle(
unsigned int dataSet)
const;
130 const std::vector<unsigned char>& getColor(
unsigned int dataSet)
const;
137 unsigned int getSize(
unsigned int dataSet)
const;
140 double minX, maxX, minY, maxY;
143 std::string labelX, labelY;
155 std::vector<unsigned char>,
161 inline void Canvas2D::setBoundsX(
167 "Canvas2D::setBoundsX()",
168 "minX has to be smaller than maxX.",
173 this->minX = minX - 1e-10;
174 this->maxX = maxX + 1e-10;
182 inline void Canvas2D::setBoundsY(
188 "Canvas2D::setBoundsY()",
189 "minY has to be smaller than maxY.",
194 this->minY = minY - 1e-10;
195 this->maxY = maxY + 1e-10;
203 inline void Canvas2D::setBounds(
209 setBoundsX(minX, maxX);
210 setBoundsY(minY, maxY);
213 inline double Canvas2D::getMinX()
const{
217 inline double Canvas2D::getMaxX()
const{
221 inline double Canvas2D::getMinY()
const{
225 inline double Canvas2D::getMaxY()
const{
229 inline void Canvas2D::setLabelX(
const std::string &labelX){
230 this->labelX = labelX;
233 inline void Canvas2D::setLabelY(
const std::string &labelY){
234 this->labelY = labelY;
237 inline const std::string& Canvas2D::getLabelX()
const{
241 inline const std::string& Canvas2D::getLabelY()
const{
245 inline void Canvas2D::setHold(
bool hold){
249 inline void Canvas2D::plot(
250 const std::vector<double> &y,
251 const std::string &title,
252 const std::vector<unsigned char> &color,
255 std::vector<double> x;
256 for(
unsigned int n = 0; n < y.size(); n++)
259 plot(x, y, title, color, size);
262 inline void Canvas2D::plot(
263 const std::vector<double> &x,
264 const std::vector<double> &y,
265 const std::string &title,
266 const std::vector<unsigned char> &color,
270 x.size() == y.size(),
272 "'x' and 'y' must have the same size, but x has size '"
273 << x.size() <<
"' while y has size'" << y.size() <<
"'.",
279 "The color must have three components but have '"
280 << color.size() <<
"'.",
287 dataSets.push_back(std::make_tuple(x, y, title, color, size));
290 inline void Canvas2D::clear(){
294 inline unsigned int Canvas2D::getNumDataSets()
const{
295 return dataSets.size();
298 inline const std::vector<double>& Canvas2D::getX(
unsigned int dataSet)
const{
299 return std::get<0>(dataSets[dataSet]);
302 inline const std::vector<double>& Canvas2D::getY(
unsigned int dataSet)
const{
303 return std::get<1>(dataSets[dataSet]);
306 inline const std::string& Canvas2D::getTitle(
unsigned int dataSet)
const{
307 return std::get<2>(dataSets[dataSet]);
310 inline const std::vector<unsigned char>& Canvas2D::getColor(
313 return std::get<3>(dataSets[dataSet]);
316 inline unsigned int Canvas2D::getSize(
unsigned int dataSet)
const{
317 return std::get<4>(dataSets[dataSet]);