From ad947c85270f98c16d4ca48f9ebde4b04d45834d Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Wed, 20 Mar 2024 09:17:05 +1100 Subject: [PATCH] Expose more of legend placement parameters. --- include/plot.h | 7 ++-- src/plot.cc | 94 ++++++++++++++++++++++++++------------------------ 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/include/plot.h b/include/plot.h index 27a9b58..ccb8cab 100644 --- a/include/plot.h +++ b/include/plot.h @@ -58,7 +58,7 @@ namespace ecolab enum DashStyle {solid, dash, dot, dashDot}; cairo::Colour colour{0,0,0,1}; double width; - double barWidth=1; // bar width as a fraction of available space + double barWidth=1.5; // bar width as a fraction of available space DashStyle dashStyle; LineStyle(): width(1), dashStyle(solid) {} std::vector dashPattern() const; @@ -142,8 +142,6 @@ namespace ecolab /// height (or width) of an axis label in pixels double labelheight() const {return lh(width(), height());} double lh(double width, double height) const; - /// calculates the bounding box of the legend, given current font size settings, and the height of the plot - void legendSize(double& width, double& height, double plotHeight) const; cairo_surface_t* cairoSurface() const; int width() const; @@ -232,6 +230,9 @@ namespace ecolab /// @return true if the value label changes from previous, indicating that the plot needs repainting bool mouseMove(double x, double y, double tolerance, Plot::Formatter formatter=defaultFormatter); + /// calculates the bounding box of the legend, given current font size settings, and the height of the plot + void legendSize(double& xoff, double& yoff, double& width, double& height, double plotWidth, double plotHeight) const; + std::vector > xticks; void add(cairo::Surface&, unsigned pen, double x, double y); diff --git a/src/plot.cc b/src/plot.cc index 9b432e6..9cff0dd 100644 --- a/src/plot.cc +++ b/src/plot.cc @@ -397,7 +397,7 @@ namespace ecolab } cairo_save(cairo); - cairo_set_source_rgba(cairo,0.5,0.5,0.5,1); + cairo_set_source_rgba(cairo,0.5,0.5,0.5,0.5); cairo_identity_matrix(cairo); cairo_set_line_width(cairo,1); cairo_stroke(cairo); @@ -427,7 +427,7 @@ namespace ecolab cairo_save(cairo); - cairo_set_source_rgba(cairo,0.8,0.8,0.8,1); + cairo_set_source_rgba(cairo,0.8,0.8,0.8,0.5); cairo_identity_matrix(cairo); cairo_set_line_width(cairo,1); cairo_stroke(cairo); @@ -438,8 +438,24 @@ namespace ecolab } - void Plot::legendSize(double& width, double& height, double plotHeight) const + void Plot::legendSize(double& xoffs, double& yoffs, double& width, double& height, double plotWidth, double plotHeight) const { + yoffs=0.95*plotHeight; + switch (legendSide) + { + default: + case left: + xoffs=0.1*plotWidth; + break; + case right: + xoffs=0.9*plotWidth; + break; + case boundingBox: + xoffs=legendLeft*plotWidth; + yoffs=legendTop*plotHeight; + break; + } + width=0; height=0; double fy=legendFontSz*fontScale*plotHeight; for (size_t i=0; i0) { cairo::CairoSave cs(cairo); - cairo_rectangle(cairo,xoffs,yoffs+0.8*fy,width+legendOffset*w,-height); + cairo_rectangle(cairo,xoffs,yoffs,width+legendOffset*w,-height); cairo_set_source_rgb(cairo,0,0,0); cairo_stroke_preserve(cairo); cairo_set_source_rgba(cairo,1,1,1,0.7); cairo_fill(cairo); } - + yoffs-=0.8*fy; for (size_t i=0; i=fontSz*height) + if (aff(ytick)>=fontSz*h) { pango.setMarkup(logAxisLabel(ytick)); cairo_new_path(cairo); @@ -815,7 +817,7 @@ namespace ecolab LogScale ls(mm1, maxy1, nyTicks); int i=0; for (double ytick=ls(0); ytick=fontSz*height) + if (aff(ytick)>=fontSz*h) { pango.setMarkup(logAxisLabel(ytick)); @@ -843,7 +845,7 @@ namespace ecolab showOrderOfMag(pango, ytickIncrement, exp_threshold); for (; ytick=fontSz*height) + if (aff(ytick)>=fontSz*h) { pango.setMarkup(axisLabel(ytick,ytickIncrement,percent));