diff --git a/share/collection.js b/share/collection.js
index 86ba87d36a1d11ea1fc7613334448751d86a31e6..63bfd0857993bd098ce42ed82554f71161785e69 100644 (file)
--- a/share/collection.js
+++ b/share/collection.js
+/**
+ * collection4 - collection.js
+ * Copyright (C) 2010 Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <ff at octo.it>
+ **/
+
var c4 =
{
var c4 =
{
- graphs: []
+ instances: []
};
};
-function json_graph_get_def (graph)
+function instance_get_params (graph) /* {{{ */
+{
+ var graph_selector = graph.graph_selector;
+ var inst_selector = graph.instance_selector;
+ var selector = {};
+
+ if (graph_selector.host == inst_selector.host)
+ {
+ selector.host = graph_selector.host;
+ }
+ else
+ {
+ selector.graph_host = graph_selector.host;
+ selector.inst_host = inst_selector.host;
+ }
+
+ if (graph_selector.plugin == inst_selector.plugin)
+ {
+ selector.plugin = graph_selector.plugin;
+ }
+ else
+ {
+ selector.graph_plugin = graph_selector.plugin;
+ selector.inst_plugin = inst_selector.plugin;
+ }
+
+ if (graph_selector.plugin_instance == inst_selector.plugin_instance)
+ {
+ selector.plugin_instance = graph_selector.plugin_instance;
+ }
+ else
+ {
+ selector.graph_plugin_instance = graph_selector.plugin_instance;
+ selector.inst_plugin_instance = inst_selector.plugin_instance;
+ }
+
+ if (graph_selector.type == inst_selector.type)
+ {
+ selector.type = graph_selector.type;
+ }
+ else
+ {
+ selector.graph_type = graph_selector.type;
+ selector.inst_type = inst_selector.type;
+ }
+
+ if (graph_selector.type_instance == inst_selector.type_instance)
+ {
+ selector.type_instance = graph_selector.type_instance;
+ }
+ else
+ {
+ selector.graph_type_instance = graph_selector.type_instance;
+ selector.inst_type_instance = inst_selector.type_instance;
+ }
+
+ return (selector);
+} /* }}} instance_get_params */
+
+function ident_clone (ident) /* {{{ */
+{
+ var ret = {};
+
+ ret.host = ident.host;
+ ret.plugin = ident.plugin;
+ ret.plugin_instance = ident.plugin_instance;
+ ret.type = ident.type;
+ ret.type_instance = ident.type_instance;
+
+ return (ret);
+} /* }}} ident_clone */
+
+function graph_get_defs (graph)
{
if (!graph.def)
{
{
if (!graph.def)
{
+ var params = ident_clone (graph.graph_selector);
+ params.action = "graph_def_json";
+
$.ajax({
$.ajax({
- url: "collection.fcgi?action=graph_def_json;" + graph.params,
+ url: "collection.fcgi",
async: false,
dataType: 'json',
async: false,
dataType: 'json',
+ data: params,
success: function (data)
{
if (!data)
success: function (data)
{
if (!data)
if (graph.def)
return (graph.def);
return;
if (graph.def)
return (graph.def);
return;
-} /* json_graph_get_def */
+} /* graph_get_defs */
-function json_graph_update(index)
+function instance_draw (inst, def, data)
{
{
- var graph;
+ var x_data = [];
+ var y_data = [];
+ var i;
+
+ if (!inst || !def || !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];
+
+ x.push (t);
+ y.push (v);
+ }
+
+ x_data.push (x);
+ y_data.push (y);
+ }
+
+ inst.raphael.clear ();
+ if (def.title)
+ inst.raphael.g.text (250, 15, def.title);
+ if (def.vertical_label)
+ inst.raphael.g.text (5, 100, def.vertical_label).rotate (270);
+ inst.raphael.g.linechart(50, 25, 500, 150, x_data, y_data, {axis: "0 0 1 1"});
+}
+
+function json_graph_update (index)
+{
+ var inst;
var def;
var def;
+ var params;
- graph = c4.graphs[index];
- if (!graph)
+ inst = c4.instances[index];
+ if (!inst)
return;
return;
- def = json_graph_get_def (graph);
+ def = graph_get_defs (inst);
if (!def)
return;
if (!def)
return;
- if (!graph.raphael)
- {
- graph.raphael = Raphael ("c4-graph" + index);
- }
+ if (!inst.raphael)
+ inst.raphael = Raphael ("c4-graph" + index);
- $.getJSON ("collection.fcgi?action=graph_data_json;" + graph.params + ";begin=-3600;end=0",
+ params = instance_get_params (inst);
+ params.action = "instance_data_json";
+ params.begin = inst.begin;
+ params.end = inst.end;
+
+ $.getJSON ("collection.fcgi", params,
function (data)
{
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"});
+ instance_draw (inst, def, data);
}); /* getJSON */
} /* json_graph_update */
}); /* getJSON */
} /* json_graph_update */
});
var i;
});
var i;
- for (i = 0; i < c4.graphs.length; i++)
+ for (i = 0; i < c4.instances.length; i++)
{
json_graph_update (i);
}
{
json_graph_update (i);
}