Skip to content

Commit

Permalink
Support scatter and line+scatter plot types
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Mar 1, 2024
1 parent c372dcf commit 238919a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 3 additions & 2 deletions include/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ecolab
bool logy;
double scale, o, o1;
XFY():logy(false), scale(1), o(0), o1(0) {}
XFY(bool logy, double scale, double o, double o1):
XFY(bool logy, double scale, double o, double o1):
logy(logy), scale(scale), o(logy? (o>0? log10(o): 0): o), o1(o1) {
}
double operator()(double y) const {
Expand All @@ -51,7 +51,7 @@ namespace ecolab
};
/// boundingBox is used explictly specify legend sizing via a bounding box relative to plot size
enum Side {left, right, boundingBox};
enum PlotType {line, bar};
enum PlotType {line, bar, scatter, line_scatter};

struct LineStyle
{
Expand Down Expand Up @@ -140,6 +140,7 @@ namespace ecolab
double xtickAngle; ///< angle (in degrees) at which xtick labels are drawn
/// if |log_10 (x)| < exp_threshold, do not rescale tick value
unsigned exp_threshold;
unsigned symbolEvery=1; ///< every symbolEvery data points, a symbol is plotted.

/// height (or width) of an axis label in pixels
double labelheight() const {return lh(width(), height());}
Expand Down
27 changes: 23 additions & 4 deletions src/plot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ namespace ecolab
switch (plotType)
{
case line:
case line_scatter:
if (x[i].size()>1)
{
cairo_set_source_rgba(cairo, ls.colour.r, ls.colour.g, ls.colour.b, ls.colour.a);
Expand Down Expand Up @@ -953,10 +954,30 @@ namespace ecolab
cairo_fill(cairo);
}
}
default: break;
}
// now handle scatter options
switch (plotType)
{
case scatter: case line_scatter:
{
cairo::CairoSave cs(cairo);
cairo_scale(cairo,1/sx,1);
cairo_set_source_rgba(cairo, ls.colour.r, ls.colour.g, ls.colour.b, ls.colour.a);
for (size_t j=0; j<x[i].size(); j+=symbolEvery)
if (inBounds(iflogx(x[i][j]), y[i][j], side))
{
cairo_arc(cairo, sx*iflogx(x[i][j]), xfy(y[i][j]), 1.5*ls.width, 0, 2*M_PI);
cairo_fill(cairo);
}
}
break;
default: break;
}
}
// display value near mouse pointer
if (!valueString.empty())

// display value near mouse pointer
if (!valueString.empty())
{
cairo::CairoSave cs(cairo);
cairo_set_source_rgb(cairo,0,0,0);
Expand Down Expand Up @@ -984,15 +1005,13 @@ namespace ecolab
// slight offsets to avoid obscuring the marker
mx+=0.1*pango.width()/sx;
if (mouseX>0.5*(minx+maxx)) mx-=1.2*pango.width()/sx;
//if (logx) mx=(mx);
cairo_rectangle(cairo,mx,my,pango.width()/sx,pango.height());
cairo_set_source_rgb(cairo,1,1,1);
cairo_fill(cairo);
cairo_set_source_rgb(cairo,0,0,0);
cairo_move_to(cairo,mx,my+pango.height());
pango.show();
}

}

if (legend) drawLegend(cairo,width,height);
Expand Down

0 comments on commit 238919a

Please sign in to comment.