]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix vertical legend alignment for --legend-direction=bottomup
authorChristoph Biedl <github.bsoj@manchmal.in-ulm.de>
Sun, 6 Oct 2013 21:37:40 +0000 (23:37 +0200)
committerChristoph Biedl <github.bsoj@manchmal.in-ulm.de>
Sun, 6 Oct 2013 21:37:40 +0000 (23:37 +0200)
Issue 419

src/rrd_graph.c

index 4d91793a0271a08a212cf6d3730b531b8d8004ee..45995949799d82bc4b0983e58c1713aa4492e2a4 100644 (file)
@@ -2767,12 +2767,27 @@ void grid_paint(
 
     /* graph labels */
     if (!(im->extra_flags & NOLEGEND) && !(im->extra_flags & ONLY_GRAPH)) {
+        /* get smallest and biggest leg_y values. Assumes
+         * im->gdes[i].leg_y is in order. */
+        double min = 0, max = 0;
+        for (i = 0; i < im->gdes_c; i++) {
+            if (im->gdes[i].legend[0] == '\0')
+                continue;
+            min = im->gdes[i].leg_y;
+            break;
+        }
+        for (i = im->gdes_c - 1; i >= 0; i--) {
+            if (im->gdes[i].legend[0] == '\0')
+                continue;
+            max = im->gdes[i].leg_y;
+            break;
+        }
         for (i = 0; i < im->gdes_c; i++) {
             if (im->gdes[i].legend[0] == '\0')
                 continue;
             /* im->gdes[i].leg_y is the bottom of the legend */
             X0 = im->xOriginLegend + im->gdes[i].leg_x;
-            Y0 = im->legenddirection == TOP_DOWN ? im->yOriginLegend + im->gdes[i].leg_y : im->yOriginLegend + im->legendheight - im->gdes[i].leg_y;
+            Y0 = im->legenddirection == TOP_DOWN ? im->yOriginLegend + im->gdes[i].leg_y : im->yOriginLegend + max + min - im->gdes[i].leg_y;
             gfx_text(im, X0, Y0,
                      im->graph_col[GRC_FONT],
                      im->