graph.c: Implement the "ShowZero" config option.
[collection4.git] / graph.c
diff --git a/graph.c b/graph.c
index c092482..1a8f327 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -28,6 +28,7 @@ struct graph_config_s /* {{{ */
 
   char *title;
   char *vertical_label;
+  _Bool show_zero;
 
   graph_def_t *defs;
 
@@ -154,6 +155,8 @@ int graph_config_add (const oconfig_item_t *ci) /* {{{ */
       graph_config_get_string (child, &cfg->title);
     else if (strcasecmp ("VerticalLabel", child->key) == 0)
       graph_config_get_string (child, &cfg->vertical_label);
+    else if (strcasecmp ("ShowZero", child->key) == 0)
+      graph_config_get_bool (child, &cfg->show_zero);
     else if (strcasecmp ("DEF", child->key) == 0)
       def_config (cfg, child);
   } /* for */
@@ -183,7 +186,7 @@ int graph_add_file (graph_config_t *cfg, const graph_ident_t *file) /* {{{ */
   return (inst_add_file (inst, file));
 } /* }}} int graph_add_file */
 
-int gl_graph_get_title (graph_config_t *cfg, /* {{{ */
+int graph_get_title (graph_config_t *cfg, /* {{{ */
     char *buffer, size_t buffer_size)
 {
   if ((cfg == NULL) || (buffer == NULL) || (buffer_size < 1))
@@ -199,7 +202,7 @@ int gl_graph_get_title (graph_config_t *cfg, /* {{{ */
   buffer[buffer_size - 1] = 0;
 
   return (0);
-} /* }}} int gl_graph_get_title */
+} /* }}} int graph_get_title */
 
 graph_ident_t *graph_get_selector (graph_config_t *cfg) /* {{{ */
 {
@@ -266,4 +269,31 @@ int graph_clear_instances (graph_config_t *cfg) /* {{{ */
   return (0);
 } /* }}} int graph_clear_instances */
 
+int graph_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
+    str_array_t *args)
+{
+  if ((cfg == NULL) || (inst == NULL) || (args == NULL))
+    return (EINVAL);
+
+  if (cfg->title != NULL)
+  {
+    array_append (args, "-t");
+    array_append (args, cfg->title);
+  }
+
+  if (cfg->vertical_label != NULL)
+  {
+    array_append (args, "-v");
+    array_append (args, cfg->vertical_label);
+  }
+
+  if (cfg->show_zero)
+  {
+    array_append (args, "-l");
+    array_append (args, "0");
+  }
+
+  return (0);
+} /* }}} int graph_get_rrdargs */
+
 /* vim: set sw=2 sts=2 et fdm=marker : */