12 #include "classdesc.h" 19 #include <cairo_base.h> 33 extern const int paletteSz;
44 XFY():logy(
false), scale(1), o(0), o1(0) {}
45 XFY(
bool logy,
double scale,
double o,
double o1):
46 logy(logy), scale(scale), o(logy? log10(o): o), o1(o1) {
48 double operator()(
double y)
const {
49 return scale*((logy? log10(y): y)-o)+o1;
54 std::vector<std::vector<double> > x;
55 std::vector<std::vector<double> > y;
57 cairo::SurfacePtr surface;
64 void addNew(cairo::Surface& surf,
bool doRedraw,
65 const unsigned *startPen,
const unsigned *finishPen,
int numPt);
67 double iflogx(
double x)
const {
return logx? log10(x): x;}
68 double iflogy(
double y)
const {
return logy? log10(y): y;}
73 void drawGrid(cairo_t* cairo,
double tick,
double increment,
bool vertical,
const XFY&)
const;
75 void drawLegend(cairo_t*,
double width,
double height)
const;
77 void labelAxes(cairo_t*,
double width,
double height)
const;
79 bool inBounds(
float x,
float y)
const {
80 return x>=minx && x<=maxx && y>=miny && y<=maxy;
83 bool displayRHSscale()
const {
84 return !penSide.empty() && miny1<maxy1;
87 enum Side {left, right};
88 enum PlotType {line, bar};
90 Plot(): nxTicks(30), nyTicks(30), fontScale(1),
91 offx(0), offy(0), logx(
false), logy(
false),
92 grid(
false), subgrid(
false),
93 leadingMarker(
false), autoscale(
true),
94 legend(
false), legendSide(right), plotType(line),
95 minx(-1), maxx(1), miny(-1), maxy(1), miny1(1), maxy1(-1)
114 double lh(
double width,
double height)
const;
116 cairo_surface_t* cairoSurface()
const;
120 double minx, maxx, miny, maxy, miny1, maxy1;
126 string Image()
const {
return m_image;}
127 string Image(
const string& im,
bool transparency=
true);
131 string imgName=args.str();
132 bool transparency=
true;
133 if (args.count) transparency=args;
134 return Image(imgName,transparency);
143 virtual void draw(cairo::Surface&);
144 void draw(cairo_t*,
double width,
double height)
const;
149 void add(
unsigned pen,
double x,
double y)
150 {
if (surface) add(*surface,pen,x,y);}
151 void add(cairo::Surface&,
unsigned pen,
double x,
double y);
154 void add(
unsigned pen,
const C& x,
const C& y)
155 {
if (surface) add(*surface,pen,x,y);}
157 void add(cairo::Surface& surf,
unsigned pen,
const C& x1,
const C& y1)
159 assert(x1.size()==y1.size());
166 for (
size_t i=0; i<x1.size(); ++i)
168 doRedraw|=x1[i]<minx||x1[i]>maxx || y1[i]<miny||y1[i]>maxy;
169 x[pen].push_back(x1[i]);
170 y[pen].push_back(y1[i]);
172 addNew(surf,doRedraw,&pen,&pen+1,x1.size());
178 {
if (surface) add(*surface,pens,x,y);}
179 void add(cairo::Surface& surf,
185 void labelPen(
unsigned pen,
const string& label);
187 void LabelPen(
unsigned pen,
const cairo::SurfacePtr& label);
190 void AssignSide(
unsigned pen, Side);
194 AssignSide(args[0], args[1].get<Side>());
199 penLabel.clear(); penTextLabel.clear(); penSide.clear();
206 void pack(
classdesc::pack_t& p)
const {p<<m_image<<x<<y<<minx<<maxx<<miny<<maxy;}
209 p>>m_image>>x>>y>>minx>>maxx>>miny>>maxy;
214 void addPt(
unsigned pen,
double x,
double y);
217 std::vector<cairo::SurfacePtr> penLabel;
218 std::vector<string> penTextLabel;
220 std::vector<Side> penSide;
243 #pragma omit pack ecolab::Plot 244 #pragma omit unpack ecolab::Plot
descriptor access to a class's privates
void add(unsigned pen, const C &x, const C &y)
add multiple points (C=container - eg vector/array)
Definition: plot.h:154
double minx
plot bounding box. y1 refers to the right hand scale
Definition: plot.h:120
bool legend
add a legend to the plot
Definition: plot.h:106
double offy
origin of plot within image
Definition: plot.h:101
bool subgrid
draw grid options
Definition: plot.h:103
string xlabel
axis labels
Definition: plot.h:110
class to allow access to private members
Definition: classdesc_access.h:21
void add(unsigned pen, double x, double y)
add a datapoint
Definition: plot.h:149
double labelheight() const
height (or width) of an axis label in pixels
Definition: plot.h:113
class to allow access to private members
Definition: classdesc_access.h:22
#define CLASSDESC_ACCESS(type)
add friend statements for each accessor function
Definition: classdesc_access.h:36
void clearPenAttributes()
remove all pen labels and side associations
Definition: plot.h:198
Represent arguments to TCL commands.
Definition: TCL_obj_base.h:138
bool autoscale
autoscale plot to data
Definition: plot.h:105
Side legendSide
legend drawn towards the left or right
Definition: plot.h:107
string Image() const
set/get the Tk image that this class writes to.
Definition: plot.h:126
Definition: pack_base.h:124
Definition: TCL_obj_base.h:124
void add(const array_ns::array< unsigned > &pens, double x, const array_ns::array< double > &y)
add multiple pens worth of data in one hit
Definition: plot.h:176
_OPENMP
Definition: accessor.h:16
bool leadingMarker
draw a leading marker on the curve (full draw only)
Definition: plot.h:104
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
bool logy
logarithmic plots (x/y axes)
Definition: plot.h:102
int nyTicks
number of x/y-axis ticks
Definition: plot.h:99
double fontScale
scale tick labels
Definition: plot.h:100