6 function graph_get_params (graph)
8 var graph_selector = graph.graph_selector;
9 var inst_selector = graph.instance_selector;
12 if (graph_selector.host == inst_selector.host)
14 selector.host = graph_selector.host;
18 selector.graph_host = graph_selector.host;
19 selector.inst_host = inst_selector.host;
22 if (graph_selector.plugin == inst_selector.plugin)
24 selector.plugin = graph_selector.plugin;
28 selector.graph_plugin = graph_selector.plugin;
29 selector.inst_plugin = inst_selector.plugin;
32 if (graph_selector.plugin_instance == inst_selector.plugin_instance)
34 selector.plugin_instance = graph_selector.plugin_instance;
38 selector.graph_plugin_instance = graph_selector.plugin_instance;
39 selector.inst_plugin_instance = inst_selector.plugin_instance;
42 if (graph_selector.type == inst_selector.type)
44 selector.type = graph_selector.type;
48 selector.graph_type = graph_selector.type;
49 selector.inst_type = inst_selector.type;
52 if (graph_selector.type_instance == inst_selector.type_instance)
54 selector.type_instance = graph_selector.type_instance;
58 selector.graph_type_instance = graph_selector.type_instance;
59 selector.inst_type_instance = inst_selector.type_instance;
63 } /* graph_get_params */
65 function ident_clone (ident)
69 ret.host = ident.host;
70 ret.plugin = ident.plugin;
71 ret.plugin_instance = ident.plugin_instance;
72 ret.type = ident.type;
73 ret.type_instance = ident.type_instance;
78 function json_graph_get_def (graph)
82 var params = ident_clone (graph.graph_selector);
83 params.action = "graph_def_json";
86 url: "collection.fcgi",
90 success: function (data)
102 } /* json_graph_get_def */
104 function json_graph_update (index)
110 graph = c4.instances[index];
114 def = json_graph_get_def (graph);
120 graph.raphael = Raphael ("c4-graph" + index);
123 params = graph_get_params (graph);
124 params.action = "graph_data_json";
125 params.begin = graph.begin;
126 params.end = graph.end;
128 $.getJSON ("collection.fcgi", params,
138 for (i = 0; i < data.length; i++)
146 for (j = 0; j < ds.data.length; j++)
163 graph.raphael.clear ();
165 graph.raphael.g.text (250, 15, def.title);
166 if (def.vertical_label)
167 graph.raphael.g.text (5, 100, def.vertical_label).rotate (270);
168 graph.raphael.g.linechart(50, 25, 500, 150, x_data, y_data, {axis: "0 0 1 1"});
170 } /* json_graph_update */
172 function format_instance(inst)
174 return ("<li class=\"instance\"><a href=\"" + location.pathname
175 + "?action=show_instance;" + inst.params + "\">" + inst.description
179 function format_instance_list(instances)
181 var ret = "<ul class=\"instance_list\">";
184 if (instances.length == 0)
187 for (i = 0; i < instances.length; i++)
188 ret += format_instance (instances[i]);
195 function format_graph(graph)
197 return ("<li class=\"graph\">" + graph.title + format_instance_list (graph.instances) + "</li>");
200 function update_search_suggestions ()
202 var term = $("#search-input").val ();
205 $("#search-suggest").hide ();
209 $("#search-suggest").show ();
210 $.getJSON ("collection.fcgi",
211 { "action": "search_json", "q": term},
215 $("#search-suggest").html ("");
216 for (i = 0; i < data.length; i++)
219 $("#search-suggest").append (format_graph (graph));
223 } /* update_search_suggestions */
225 function zoom_redraw (jq_obj) /* {{{ */
227 var url = jq_obj.data ("base_url");
229 if ((jq_obj == null) || (url == null))
232 if (jq_obj.data ('begin') != null)
233 url += ";begin=" + jq_obj.data ('begin');
234 if (jq_obj.data ('end') != null)
235 url += ";end=" + jq_obj.data ('end');
237 jq_obj.attr ("src", url);
239 } /* }}} function zoom_redraw */
241 function zoom_reset (graph_id, diff) /* {{{ */
247 jq_obj = $("#" + graph_id);
251 end = new Number ((new Date ()).getTime () / 1000);
252 begin = new Number (end - diff);
254 jq_obj.data ('begin', begin.toFixed (0));
255 jq_obj.data ('end', end.toFixed (0));
257 return (zoom_redraw (jq_obj));
258 } /* }}} function zoom_reset */
260 function zoom_hour (graph_id) /* {{{ */
262 zoom_reset (graph_id, 3600);
263 } /* }}} function zoom_hour */
265 function zoom_day (graph_id) /* {{{ */
267 zoom_reset (graph_id, 86400);
268 } /* }}} function zoom_day */
270 function zoom_week (graph_id) /* {{{ */
272 zoom_reset (graph_id, 7 * 86400);
273 } /* }}} function zoom_week */
275 function zoom_month (graph_id) /* {{{ */
277 zoom_reset (graph_id, 31 * 86400);
278 } /* }}} function zoom_month */
280 function zoom_year (graph_id) /* {{{ */
282 zoom_reset (graph_id, 366 * 86400);
283 } /* }}} function zoom_year */
285 function zoom_relative (graph_id, factor_begin, factor_end) /* {{{ */
292 jq_obj = $("#" + graph_id);
296 begin = jq_obj.data ('begin');
297 end = jq_obj.data ('end');
298 if ((begin == null) || (end == null))
299 return (zoom_day (graph_id));
301 begin = new Number (begin);
302 end = new Number (end);
305 if ((diff <= 300) && (factor_begin > 0.0) && (factor_end < 0.0))
308 jq_obj.data ('begin', begin + (diff * factor_begin));
309 jq_obj.data ('end', end + (diff * factor_end));
311 return (zoom_redraw (jq_obj));
312 } /* }}} function zoom_relative */
314 function zoom_reference (graph_id) /* {{{ */
320 jq_obj = $("#" + graph_id);
324 begin = jq_obj.data ('begin');
325 end = jq_obj.data ('end');
326 if ((begin == null) || (end == null))
329 $(".graph-img img").each (function ()
331 $(this).data ('begin', begin);
332 $(this).data ('end', end);
333 zoom_redraw ($(this));
335 } /* }}} function zoom_reference */
337 function zoom_earlier (graph_id) /* {{{ */
339 return (zoom_relative (graph_id, -0.2, -0.2));
340 } /* }}} function zoom_earlier */
342 function zoom_later (graph_id) /* {{{ */
344 return (zoom_relative (graph_id, +0.2, +0.2));
345 } /* }}} function zoom_later */
347 function zoom_in (graph_id) /* {{{ */
349 return (zoom_relative (graph_id, +0.2, -0.2));
350 } /* }}} function zoom_earlier */
352 function zoom_out (graph_id) /* {{{ */
354 return (zoom_relative (graph_id, (-1.0 / 3.0), (1.0 / 3.0)));
355 } /* }}} function zoom_earlier */
357 $(document).ready(function() {
358 /* $("#layout-middle-right").html ("<ul id=\"search-suggest\" class=\"graph_list\"></ul>"); */
359 $("#search-form").append ("<ul id=\"search-suggest\" class=\"graph_list\"></ul>");
360 $("#search-suggest").hide ();
362 $("#search-input").blur (function()
364 window.setTimeout (function ()
366 $("#search-suggest").hide ();
370 $("#search-input").focus (function()
372 var term = $("#search-input").val ();
375 $("#search-suggest").hide ();
379 $("#search-suggest").show ();
383 $("#search-input").keyup (function()
385 update_search_suggestions ();
389 $(".graph-img").each (function (index, elem)
391 var id = "graph" + graph_count;
394 $(this).find ("img").each (function (img_index, img_elem)
398 $(this).attr ("id", id);
400 base_url = $(this).attr ("src").replace (/;(begin|end)=[^;]*/g, '');
401 $(this).data ("base_url", base_url);
404 $(this).append ("<div class=\"graph-buttons presets\">"
405 + "<div class=\"graph-button\" onClick=\"zoom_hour ('"+id+"');\">H</div>"
406 + "<div class=\"graph-button\" onClick=\"zoom_day ('"+id+"');\">D</div>"
407 + "<div class=\"graph-button\" onClick=\"zoom_week ('"+id+"');\">W</div>"
408 + "<div class=\"graph-button\" onClick=\"zoom_month ('"+id+"');\">M</div>"
409 + "<div class=\"graph-button\" onClick=\"zoom_year ('"+id+"');\">Y</div>"
410 + "<div class=\"graph-button\" onClick=\"zoom_reference ('"+id+"');\">!</div>"
412 + "<div class=\"graph-buttons navigation\">"
413 + "<div class=\"graph-button\" onClick=\"zoom_earlier ('"+id+"');\">←</div>"
414 + "<div class=\"graph-button\" onClick=\"zoom_out ('"+id+"');\">−</div>"
415 + "<div class=\"graph-button\" onClick=\"zoom_in ('"+id+"');\">+</div>"
416 + "<div class=\"graph-button\" onClick=\"zoom_later ('"+id+"');\">→</div>"
422 for (i = 0; i < c4.instances.length; i++)
424 json_graph_update (i);
428 /* vim: set sw=2 sts=2 et fdm=marker : */