From 4f4a330557182d024ed5854bd9c79880b6fdaeb6 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 10 Sep 2010 11:22:26 +0200 Subject: [PATCH] show_instance action: Add a very simple first scetch of a JavaScript based graphing solution. --- share/collection.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++ share/style.css | 7 ++++ src/action_show_instance.c | 13 ++++--- src/utils_cgi.c | 6 +++ 4 files changed, 116 insertions(+), 5 deletions(-) diff --git a/share/collection.js b/share/collection.js index fdd9d30..86ba87d 100644 --- a/share/collection.js +++ b/share/collection.js @@ -1,3 +1,92 @@ +var c4 = +{ + graphs: [] +}; + +function json_graph_get_def (graph) +{ + if (!graph.def) + { + $.ajax({ + url: "collection.fcgi?action=graph_def_json;" + graph.params, + async: false, + dataType: 'json', + success: function (data) + { + if (!data) + return; + + graph.def = data; + }}); + } + + if (graph.def) + return (graph.def); + return; +} /* json_graph_get_def */ + +function json_graph_update(index) +{ + var graph; + var def; + + graph = c4.graphs[index]; + if (!graph) + return; + + def = json_graph_get_def (graph); + if (!def) + return; + + if (!graph.raphael) + { + graph.raphael = Raphael ("c4-graph" + index); + } + + $.getJSON ("collection.fcgi?action=graph_data_json;" + graph.params + ";begin=-3600;end=0", + function (data) + { + var x_data = []; + var y_data = []; + var i; + + if (!data) + return; + + for (i = 0; i < data.length; i++) + { + var ds = data[i]; + + var j; + var x = []; + var y = []; + + for (j = 0; j < ds.data.length; j++) + { + var dp = ds.data[j]; + var t = dp[0]; + var v = dp[1]; + + if (v == null) + continue; + + x.push (t); + y.push (v); + } + + x_data.push (x); + y_data.push (y); + } + + graph.raphael.clear (); + if (def.title) + graph.raphael.g.text (250, 15, def.title); + if (def.vertical_label) + graph.raphael.g.text (5, 100, def.vertical_label).rotate (270); + graph.raphael.g.linechart(50, 25, 500, 150, x_data, y_data, {axis: "0 0 1 1"}); + }); /* getJSON */ +} /* json_graph_update */ + function format_instance(inst) { return ("
  • " ); }); + + var i; + for (i = 0; i < c4.graphs.length; i++) + { + json_graph_update (i); + } }); /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/share/style.css b/share/style.css index 9e8668b..a9f7e15 100644 --- a/share/style.css +++ b/share/style.css @@ -235,6 +235,13 @@ div.graph-img:hover div.graph-buttons margin-bottom: 1px; } +.graph-json +{ + clear: both; + width: 600px; + height: 200px; +} + div.footer { margin-left: auto; diff --git a/src/action_show_instance.c b/src/action_show_instance.c index c6a8918..0d6b5e2 100644 --- a/src/action_show_instance.c +++ b/src/action_show_instance.c @@ -227,19 +227,22 @@ static int show_instance_cb (graph_config_t *cfg, /* {{{ */ show_breadcrump (cfg, inst); if (data->graph_count < MAX_SHOW_GRAPHS) - { printf ("
    \n", script_name (), params, time_params, title, descr); - printf ("
    " - "Get graph data as JSON
    \n", - script_name (), params, time_params); - } else printf ("Show graph " ""%s / %s"\n", script_name (), params, title, descr); + printf ("
    \n", data->graph_count); + printf ("\n", + data->graph_count, params, (long) begin, (long) end); + + printf ("
    " + "Get graph data as JSON
    \n", + script_name (), params, time_params); + data->graph_count++; return (0); diff --git a/src/utils_cgi.c b/src/utils_cgi.c index eb9d593..7995e3f 100644 --- a/src/utils_cgi.c +++ b/src/utils_cgi.c @@ -690,6 +690,12 @@ int html_print_page (const char *title, /* {{{ */ " \n" " \n" + " \n" + " \n" + " \n" " \n" " \n", -- 2.11.0