src/graph_def.c: Make it possible for one "DEF" to handle multiple files correctly.
[collection4.git] / src / graph_def.c
index bcef8cf..9aba1ce 100644 (file)
@@ -182,11 +182,11 @@ graph_def_t *def_create (graph_config_t *cfg, graph_ident_t *ident, /* {{{ */
     return (NULL);
   }
 
-  ret->color = get_random_color ();
+  ret->color = UINT32_MAX;
   ret->next = NULL;
 
   ret->select = ident_copy_with_selector (selector, ident,
-      IDENT_FLAG_REPLACE_ALL);
+      IDENT_FLAG_REPLACE_ANY);
   if (ret->select == NULL)
   {
     ident_destroy (selector);
@@ -315,6 +315,8 @@ int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
   char *file;
   int index;
   char draw_def[64];
+  char legend[256];
+  uint32_t color;
 
   if ((def == NULL) || (ident == NULL) || (args == NULL))
     return (EINVAL);
@@ -328,6 +330,27 @@ int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
 
   DEBUG ("gl_ident_get_rrdargs: file = %s;\n", file);
 
+  if (def->legend != NULL)
+  {
+    strncpy (legend, def->legend, sizeof (legend));
+    legend[sizeof (legend) - 1] = 0;
+  }
+  else
+  {
+    ident_describe (ident, def->select,
+        legend, sizeof (legend));
+
+    if ((legend[0] == 0) || (strcmp ("default", legend) == 0))
+    {
+      strncpy (legend, def->ds_name, sizeof (legend));
+      legend[sizeof (legend) - 1] = 0;
+    }
+  }
+
+  color = def->color;
+  if (color > 0x00ffffff)
+    color = get_random_color ();
+
   index = args->index;
   args->index++;
 
@@ -368,7 +391,7 @@ int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
 
   if (def->area)
     array_prepend_format (args->areas, "AREA:%s#%06"PRIx32,
-        draw_def, fade_color (def->color));
+        draw_def, fade_color (color));
 
   /* Graph part */
   array_prepend_format (args->lines, "GPRINT:vdef_%04i_lst:%s last\\l",
@@ -380,8 +403,7 @@ int def_get_rrdargs (graph_def_t *def, graph_ident_t *ident, /* {{{ */
   array_prepend_format (args->lines, "GPRINT:vdef_%04i_min:%s min,",
       index, (def->format != NULL) ? def->format : "%6.2lf");
   array_prepend_format (args->lines, "LINE1:%s#%06"PRIx32":%s",
-      draw_def, def->color,
-      (def->legend != NULL) ? def->legend : def->ds_name);
+      draw_def, color, legend);
 
   free (file);