Minsky
plotOptions.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2023
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef PLOTOPTIONS_H
21 #define PLOTOPTIONS_H
22 #include "optional.h"
23 #include "plotWidget.h"
24 
25 namespace minsky
26 {
28  {
29  double legendLeft=0.9, legendTop=0.95, legendFontSz=0.03;
30  LegendGeometry()=default;
31  LegendGeometry(const ecolab::Plot& plot):
33  void setLegendGeometry(ecolab::Plot& plot) const {
34  plot.legendLeft=legendLeft;
35  plot.legendTop=legendTop;
36  plot.legendFontSz=legendFontSz;
37  }
38  };
39 
40  struct DummyBase {};
41 
42  // template used to stack inheritance, as a fake multiple
43  // inheritance feature. XML doesn't support multiple inheritance
44  template <class Base=DummyBase>
45  struct PlotOptions: public Base
46  {
47  PlotOptions()=default;
48  PlotOptions(const Base& x): Base(x) {}
49  Optional<std::string> name; //name, description or title
55  double xmin=nan(""), xmax=nan(""), ymin=nan(""), ymax=nan(""), y1min=nan(""), y1max=nan("");
56  unsigned symbolEvery=1;
62  name=plot.title;
63  logx=plot.logx;
64  logy=plot.logy;
65  ypercent=plot.percent;
66  grid=plot.grid;
67  subgrid=plot.subgrid;
68  plotType=plot.plotType;
69  xlabel=plot.xlabel();
70  ylabel=plot.ylabel();
71  y1label=plot.y1label();
72  nxTicks=plot.nxTicks;
73  nyTicks=plot.nyTicks;
74  xtickAngle=plot.xtickAngle;
75  exp_threshold=plot.exp_threshold;
76  xmin=plot.xmin;
77  xmax=plot.xmax;
78  ymin=plot.ymin;
79  ymax=plot.ymax;
80  y1min=plot.y1min;
81  y1max=plot.y1max;
82  symbolEvery=plot.symbolEvery;
83  if (plot.legend) legend=plot.legendSide;
85  palette=plot.palette;
86  horizontalMarkers=plot.horizontalMarkers;
87  verticalMarkers=plot.verticalMarkers;
88  return *this;
89  }
91  {
92  if (name) plot.title=*name;
93  if (logx) plot.logx=*logx;
94  if (logy) plot.logy=*logy;
95  if (ypercent) plot.percent=*ypercent;
96  if (grid) plot.grid=*grid;
97  if (subgrid) plot.subgrid=*subgrid;
98  if (plotType) plot.plotType=*plotType;
99  if (xlabel) plot.xlabel(*xlabel);
100  if (ylabel) plot.ylabel(*ylabel);
101  if (y1label) plot.y1label(*y1label);
102  if (nxTicks) plot.nxTicks=*nxTicks;
103  if (nyTicks) plot.nyTicks=*nyTicks;
104  if (xtickAngle) plot.xtickAngle=*xtickAngle;
105  if (exp_threshold) plot.exp_threshold=*exp_threshold;
106  plot.xmin=xmin;
107  plot.xmax=xmax;
108  plot.ymin=ymin;
109  plot.ymax=ymax;
110  plot.y1min=y1min;
111  plot.y1max=y1max;
112  plot.symbolEvery=symbolEvery;
113  plot.legend=legend.get();
114  if (legend) plot.legendSide=*legend;
115  if (legendGeometry)
116  legendGeometry->setLegendGeometry(plot);
117  if (palette) plot.palette=*palette;
118  if (horizontalMarkers) plot.horizontalMarkers=*horizontalMarkers;
119  if (verticalMarkers) plot.verticalMarkers=*verticalMarkers;
120  }
121  };
122 }
123 
124 #include "plotOptions.cd"
125 #include "plotOptions.xcd"
126 #endif
LegendGeometry(const ecolab::Plot &plot)
Definition: plotOptions.h:31
Optional< ecolab::Plot::Side > legend
Definition: plotOptions.h:57
Optional< std::string > name
Definition: plotOptions.h:49
PlotOptions & operator=(const PlotWidget &plot)
Definition: plotOptions.h:61
Optional< bool > grid
Definition: plotOptions.h:50
Optional< std::vector< std::string > > verticalMarkers
Definition: plotOptions.h:60
unsigned symbolEvery
Definition: plotOptions.h:56
Optional< minsky::PlotWidget::PlotType > plotType
Definition: plotOptions.h:51
Optional< int > nyTicks
Definition: plotOptions.h:53
Optional< double > xtickAngle
Definition: plotOptions.h:54
void setLegendGeometry(ecolab::Plot &plot) const
Definition: plotOptions.h:33
Optional< double > exp_threshold
Definition: plotOptions.h:54
Optional< std::string > xlabel
Definition: plotOptions.h:52
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
Optional< bool > subgrid
Definition: plotOptions.h:50
Optional< bool > logx
Definition: plotOptions.h:50
PlotOptions(const Base &x)
Definition: plotOptions.h:48
void applyPlotOptions(PlotWidget &plot) const
Definition: plotOptions.h:90
Optional< LegendGeometry > legendGeometry
Definition: plotOptions.h:58
Optional< std::string > y1label
Definition: plotOptions.h:52
Optional< std::string > ylabel
Definition: plotOptions.h:52
Optional< int > nxTicks
Definition: plotOptions.h:53
Optional< std::vector< std::string > > horizontalMarkers
Definition: plotOptions.h:60
Optional< std::vector< ecolab::Plot::LineStyle > > palette
Definition: plotOptions.h:59
a container item for a plot widget
Definition: plotWidget.h:46
Optional< bool > ypercent
Definition: plotOptions.h:50
Optional< bool > logy
Definition: plotOptions.h:50