Skip to content

Commit

Permalink
Added pen labels to interactive marker. For ravel #512.
Browse files Browse the repository at this point in the history
Modulo arithmetic when acessing pen style incorrectly uses the fixed paletteSz rather than palette.size(). For ravel #553.
  • Loading branch information
highperformancecoder committed May 8, 2024
1 parent 793c3df commit 653d0a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions include/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ namespace ecolab

protected: // only protected because of TCL_obj problems
/// default formatter suitable for plots of numeric data
static std::string defaultFormatter(double,double);
using Formatter=std::function<std::string(double,double)>;
/// @param label - pen label
/// @param x x coordinate of point to be labelled
/// @param y y coordinate of point to be labelled
static std::string defaultFormatter(const string& label,double x,double y);
using Formatter=std::function<std::string(const string&,double,double)>;
/// if \a (x,y) within ([0,1],[0,1]), then paint a value box corresponding to closest curve
/// @param tolerance - how close in user relative coordinates the mouse needs to be to a data point
/// @param formatter - produce text label given (x,y) values
Expand Down
12 changes: 7 additions & 5 deletions src/plot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ namespace ecolab
for (size_t i=0; i<x.size(); ++i)
{
if (x[i].empty()) continue;
const LineStyle& ls=palette[i%paletteSz];
const LineStyle& ls=palette[i%palette.size()];

// transform y coordinates (handles RHS being a different scale)
XFY xfy=aff;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ namespace ecolab
}
auto my=xfy(mouseY);
// put a marker where the found location is (mouse can be slightly different)
const LineStyle& ls=palette[mousePen%paletteSz];
const LineStyle& ls=palette[mousePen%palette.size()];
cairo_set_source_rgba(cairo, ls.colour.r, ls.colour.g, ls.colour.b, 0.5*ls.colour.a);
{
cairo::CairoSave cs(cairo);
Expand Down Expand Up @@ -1274,11 +1274,11 @@ namespace ecolab
throw error("exporting to %s failed",filename.c_str());
}

string Plot::defaultFormatter(double x, double y)
string Plot::defaultFormatter(const string& label, double x, double y)
{
ostringstream r;
r.precision(3);
r<<"("<<x<<","<<y<<")";
r<<label<<":("<<x<<","<<y<<")";
return r.str();
}

Expand Down Expand Up @@ -1316,6 +1316,7 @@ namespace ecolab

double xp=std::numeric_limits<double>::max(), yp=xp;
double mind=std::numeric_limits<double>::max();
string penLabel;
assert(x.size()==y.size());
for (size_t pen=0; pen<x.size(); ++pen)
{
Expand All @@ -1333,14 +1334,15 @@ namespace ecolab
{
xp=x[pen][i];
yp=y[pen][i];
penLabel=penTextLabel[pen];
mousePen=pen;
mind=d;
}
}
}
string valueString1;
if (xp<maxx)
valueString1=formatter(xp,yp);
valueString1=formatter(penLabel,xp,yp);
if (valueString1!=valueString)
{
valueString=valueString1;
Expand Down

0 comments on commit 653d0a1

Please sign in to comment.