From 9e6d2198155a7ac39d93386452ccc8102876c56c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Anders=20Bj=C3=B6rklund?= Date: Sun, 26 Jun 2016 13:53:02 +0200 Subject: [PATCH] Show legend coords in graphv, for making img map --- src/rrd_graph.c | 27 +++++++++++++++++++++++++++ tests/functions | 6 ++++++ tests/rpn1 | 7 +++++-- tests/rpn1.output | 12 ++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/rrd_graph.c b/src/rrd_graph.c index ba34e18a..898b301f 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -3085,6 +3085,7 @@ int grid_paint( int res = 0; double X0, Y0; /* points for filled graph and more */ struct gfx_color_t water_color; + int legend_cnt = 0; if (im->draw_3d_border > 0) { /* draw 3d border */ @@ -3251,6 +3252,32 @@ int grid_paint( [TEXT_PROP_LEGEND].font_desc, im->tabwidth, 0.0, GFX_H_LEFT, GFX_V_BOTTOM, im->gdes[i].legend); + { + rrd_infoval_t val; + double w, h; + + w = gfx_get_text_width(im, 0, + im-> + text_prop + [TEXT_PROP_LEGEND].font_desc, + im->tabwidth, im->gdes[i].legend); + h = gfx_get_text_height(im, 0, + im-> + text_prop + [TEXT_PROP_LEGEND].font_desc, + im->tabwidth, im->gdes[i].legend); + + val.u_str = sprintf_alloc("%s", im->gdes[i].legend); + grinfo_push(im, + sprintf_alloc("legend[%ld]", legend_cnt), + RD_I_STR, val); + val.u_str = sprintf_alloc("%.0f,%.0f,%.0f,%.0f", + X0, Y0 - h, X0 + w, Y0); + grinfo_push(im, + sprintf_alloc("coords[%ld]", legend_cnt), + RD_I_STR, val); + legend_cnt++; + } /* The legend for GRAPH items starts with "M " to have enough space for the box */ if (im->gdes[i].gf != GF_PRINT && diff --git a/tests/functions b/tests/functions index f12af726..6b9f9069 100644 --- a/tests/functions +++ b/tests/functions @@ -15,6 +15,12 @@ function seddif { perl -p -e 's/([-+]?\d\.\d+e[-+]\d+)/sprintf("%0.7e",$1)/ge' | $DIFF $@ } +BLANK=blank + +function blank { + perl -p -e 'm/(left|top|right|bottom|width|height|coords)/ && s/\d+/\#/g' $@ +} + # # because valgrind has trouble with glib memory handling # (see e.g. https://developer.gnome.org/glib/2.30/glib-running.html or diff --git a/tests/rpn1 b/tests/rpn1 index f000e6a7..2cbe05c8 100755 --- a/tests/rpn1 +++ b/tests/rpn1 @@ -12,7 +12,9 @@ $RRDTOOL update $RRD 920806500:12383 920806800:12393 920807100:12399 $RRDTOOL update $RRD 920807400:12405 920807700:12411 920808000:12415 $RRDTOOL update $RRD 920808300:12420 920808600:12422 920808900:12423 report "update" -$RRDTOOL graphv - \ +# blank out any absolute coordinates, as they might differ +$BLANK < $BASEDIR/rpn1.output > $BASEDIR/rpn1.output.out +$RRDTOOL graphv $BASEDIR/rpn1.out \ --start 920804400 --end 920808000 \ DEF:my-speed=$RRD:speed:AVERAGE \ CDEF:nonans01=my-speed,UN,0,my-speed,IF \ @@ -23,7 +25,8 @@ $RRDTOOL graphv - \ VDEF:f=fast123456789012345678901234567890,AVERAGE \ VDEF:g=good,MAXIMUM \ VDEF:o=over,MINIMUM \ + VRULE:920806500:"foo" \ PRINT:f:'%lf' \ PRINT:g:'%lf' \ - PRINT:o:'%lf' | $DIFF9 - $BASEDIR/rpn1.output + PRINT:o:'%lf' | $BLANK | $DIFF9 - $BASEDIR/rpn1.output.out report "graphv" diff --git a/tests/rpn1.output b/tests/rpn1.output index 4a7696db..211a76c9 100644 --- a/tests/rpn1.output +++ b/tests/rpn1.output @@ -1,3 +1,15 @@ print[0] = "30.769231" print[1] = "72.000000" print[2] = "0.000000" +graph_left = 51 +graph_top = 15 +graph_width = 400 +graph_height = 100 +image_width = 481 +image_height = 155 +graph_start = 920804400 +graph_end = 920808000 +value_min = 0.0000000e+00 +value_max = 1.0000000e+00 +legend[0] = " foo" +coords[0] = "16,135,51,148" -- 2.47.2