6 function json_graph_get_def (graph)
11 url: "collection.fcgi?action=graph_def_json;" + graph.params,
14 success: function (data)
26 } /* json_graph_get_def */
28 function json_graph_update(index)
33 graph = c4.graphs[index];
37 def = json_graph_get_def (graph);
43 graph.raphael = Raphael ("c4-graph" + index);
46 $.getJSON ("collection.fcgi?action=graph_data_json;" + graph.params + ";begin=-3600;end=0",
56 for (i = 0; i < data.length; i++)
64 for (j = 0; j < ds.data.length; j++)
81 graph.raphael.clear ();
83 graph.raphael.g.text (250, 15, def.title);
84 if (def.vertical_label)
85 graph.raphael.g.text (5, 100, def.vertical_label).rotate (270);
86 graph.raphael.g.linechart(50, 25, 500, 150, x_data, y_data, {axis: "0 0 1 1"});
88 } /* json_graph_update */
90 function format_instance(inst)
92 return ("<li class=\"instance\"><a href=\"" + location.pathname
93 + "?action=show_instance;" + inst.params + "\">" + inst.description
97 function format_instance_list(instances)
99 var ret = "<ul class=\"instance_list\">";
102 if (instances.length == 0)
105 for (i = 0; i < instances.length; i++)
106 ret += format_instance (instances[i]);
113 function format_graph(graph)
115 return ("<li class=\"graph\">" + graph.title + format_instance_list (graph.instances) + "</li>");
118 function update_search_suggestions ()
120 var term = $("#search-input").val ();
123 $("#search-suggest").hide ();
127 $("#search-suggest").show ();
128 $.getJSON ("collection.fcgi",
129 { "action": "search_json", "q": term},
133 $("#search-suggest").html ("");
134 for (i = 0; i < data.length; i++)
137 $("#search-suggest").append (format_graph (graph));
141 } /* update_search_suggestions */
143 function zoom_redraw (jq_obj) /* {{{ */
145 var url = jq_obj.data ("base_url");
147 if ((jq_obj == null) || (url == null))
150 if (jq_obj.data ('begin') != null)
151 url += ";begin=" + jq_obj.data ('begin');
152 if (jq_obj.data ('end') != null)
153 url += ";end=" + jq_obj.data ('end');
155 jq_obj.attr ("src", url);
157 } /* }}} function zoom_redraw */
159 function zoom_reset (graph_id, diff) /* {{{ */
165 jq_obj = $("#" + graph_id);
169 end = new Number ((new Date ()).getTime () / 1000);
170 begin = new Number (end - diff);
172 jq_obj.data ('begin', begin.toFixed (0));
173 jq_obj.data ('end', end.toFixed (0));
175 return (zoom_redraw (jq_obj));
176 } /* }}} function zoom_reset */
178 function zoom_hour (graph_id) /* {{{ */
180 zoom_reset (graph_id, 3600);
181 } /* }}} function zoom_hour */
183 function zoom_day (graph_id) /* {{{ */
185 zoom_reset (graph_id, 86400);
186 } /* }}} function zoom_day */
188 function zoom_week (graph_id) /* {{{ */
190 zoom_reset (graph_id, 7 * 86400);
191 } /* }}} function zoom_week */
193 function zoom_month (graph_id) /* {{{ */
195 zoom_reset (graph_id, 31 * 86400);
196 } /* }}} function zoom_month */
198 function zoom_year (graph_id) /* {{{ */
200 zoom_reset (graph_id, 366 * 86400);
201 } /* }}} function zoom_year */
203 function zoom_relative (graph_id, factor_begin, factor_end) /* {{{ */
210 jq_obj = $("#" + graph_id);
214 begin = jq_obj.data ('begin');
215 end = jq_obj.data ('end');
216 if ((begin == null) || (end == null))
217 return (zoom_day (graph_id));
219 begin = new Number (begin);
220 end = new Number (end);
223 if ((diff <= 300) && (factor_begin > 0.0) && (factor_end < 0.0))
226 jq_obj.data ('begin', begin + (diff * factor_begin));
227 jq_obj.data ('end', end + (diff * factor_end));
229 return (zoom_redraw (jq_obj));
230 } /* }}} function zoom_relative */
232 function zoom_reference (graph_id) /* {{{ */
238 jq_obj = $("#" + graph_id);
242 begin = jq_obj.data ('begin');
243 end = jq_obj.data ('end');
244 if ((begin == null) || (end == null))
247 $(".graph-img img").each (function ()
249 $(this).data ('begin', begin);
250 $(this).data ('end', end);
251 zoom_redraw ($(this));
253 } /* }}} function zoom_reference */
255 function zoom_earlier (graph_id) /* {{{ */
257 return (zoom_relative (graph_id, -0.2, -0.2));
258 } /* }}} function zoom_earlier */
260 function zoom_later (graph_id) /* {{{ */
262 return (zoom_relative (graph_id, +0.2, +0.2));
263 } /* }}} function zoom_later */
265 function zoom_in (graph_id) /* {{{ */
267 return (zoom_relative (graph_id, +0.2, -0.2));
268 } /* }}} function zoom_earlier */
270 function zoom_out (graph_id) /* {{{ */
272 return (zoom_relative (graph_id, (-1.0 / 3.0), (1.0 / 3.0)));
273 } /* }}} function zoom_earlier */
275 $(document).ready(function() {
276 /* $("#layout-middle-right").html ("<ul id=\"search-suggest\" class=\"graph_list\"></ul>"); */
277 $("#search-form").append ("<ul id=\"search-suggest\" class=\"graph_list\"></ul>");
278 $("#search-suggest").hide ();
280 $("#search-input").blur (function()
282 window.setTimeout (function ()
284 $("#search-suggest").hide ();
288 $("#search-input").focus (function()
290 var term = $("#search-input").val ();
293 $("#search-suggest").hide ();
297 $("#search-suggest").show ();
301 $("#search-input").keyup (function()
303 update_search_suggestions ();
307 $(".graph-img").each (function (index, elem)
309 var id = "graph" + graph_count;
312 $(this).find ("img").each (function (img_index, img_elem)
316 $(this).attr ("id", id);
318 base_url = $(this).attr ("src").replace (/;(begin|end)=[^;]*/g, '');
319 $(this).data ("base_url", base_url);
322 $(this).append ("<div class=\"graph-buttons presets\">"
323 + "<div class=\"graph-button\" onClick=\"zoom_hour ('"+id+"');\">H</div>"
324 + "<div class=\"graph-button\" onClick=\"zoom_day ('"+id+"');\">D</div>"
325 + "<div class=\"graph-button\" onClick=\"zoom_week ('"+id+"');\">W</div>"
326 + "<div class=\"graph-button\" onClick=\"zoom_month ('"+id+"');\">M</div>"
327 + "<div class=\"graph-button\" onClick=\"zoom_year ('"+id+"');\">Y</div>"
328 + "<div class=\"graph-button\" onClick=\"zoom_reference ('"+id+"');\">!</div>"
330 + "<div class=\"graph-buttons navigation\">"
331 + "<div class=\"graph-button\" onClick=\"zoom_earlier ('"+id+"');\">←</div>"
332 + "<div class=\"graph-button\" onClick=\"zoom_out ('"+id+"');\">−</div>"
333 + "<div class=\"graph-button\" onClick=\"zoom_in ('"+id+"');\">+</div>"
334 + "<div class=\"graph-button\" onClick=\"zoom_later ('"+id+"');\">→</div>"
340 for (i = 0; i < c4.graphs.length; i++)
342 json_graph_update (i);
346 /* vim: set sw=2 sts=2 et fdm=marker : */