graph: bump prio end value by ytick delta, if all zeroes
[fio.git] / graph.c
diff --git a/graph.c b/graph.c
index 0dae510afe8186b5e2b1cf76a1ad89573dc61643..a61ce4bc0db9268884a1a8008f4354f9daffe944 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -682,28 +682,23 @@ void graph_add_label(struct graph *bg, const char *label)
        INIT_PRIO_TREE_ROOT(&i->prio_tree);
 }
 
-static void graph_label_add_value(struct graph_label *i, void *value,
-                                 const char *tooltip)
+static void graph_label_add_value(struct graph *g, struct graph_label *i,
+                                 void *value, const char *tooltip)
 {
        struct graph_value *x;
 
        x = malloc(sizeof(*x));
        memset(x, 0, sizeof(*x));
        x->value = value;
-       if (tooltip)
-               x->tooltip = strdup(tooltip);
-       else
-               x->tooltip = NULL;
        x->next = NULL;
-       if (!i->tail) {
+       if (!i->tail)
                i->values = x;
-       } else {
+       else
                i->tail->next = x;
-       }
        i->tail = x;
        i->value_count++;
 
-       if (x->tooltip) {
+       if (tooltip) {
                double yval = gety(x);
                double miny = yval / TOOLTIP_DELTA;
                double maxy = yval * TOOLTIP_DELTA;
@@ -712,19 +707,20 @@ static void graph_label_add_value(struct graph_label *i, void *value,
                INIT_PRIO_TREE_NODE(&x->node);
                x->node.start = miny;
                x->node.last = maxy;
-               if (x->node.last == x->node.start)
-                       x->node.last++;
+               if (x->node.last == x->node.start) {
+                       x->node.last += fabs(g->ytick_delta);
+                       printf("last bumped to %lu\n", x->node.last);
+               }
 
                /*
                 * If ret != &x->node, we have an alias. Since the values
                 * should be identical, we can drop it
                 */
                ret = prio_tree_insert(&i->prio_tree, &x->node);
-               if (ret != &x->node) {
-                       free(x->tooltip);
-                       x->tooltip = NULL;
-               } else
+               if (ret == &x->node) {
+                       x->tooltip = strdup(tooltip);
                        i->tooltip_count++;
+               }
        }
 
        if (i->parent->per_label_limit != -1 &&
@@ -766,7 +762,7 @@ int graph_add_data(struct graph *bg, const char *label, const double value)
        i = graph_find_label(bg, label);
        if (!i)
                return -1;
-       graph_label_add_value(i, d, NULL);
+       graph_label_add_value(bg, i, d, NULL);
        return 0;
 }
 
@@ -784,7 +780,7 @@ int graph_add_xy_data(struct graph *bg, const char *label,
        if (!i)
                return -1;
 
-       graph_label_add_value(i, xy, tooltip);
+       graph_label_add_value(bg, i, xy, tooltip);
        return 0;
 }