diff options
author | Stef Walter <stef@memberwebs.com> | 2006-04-05 21:59:42 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2006-04-05 21:59:42 +0000 |
commit | 847578bd4fa3f5bead0bd272c2347ca9f96e5abd (patch) | |
tree | 20e879604da76e8e12a4de55a1ed39c380b6ea5c /html/rrdui.js | |
parent | c6e0f00687bcef76d2ce325e9489aba9b3c3da2a (diff) |
Add autoscrolling for graphs. See #67
Diffstat (limited to 'html/rrdui.js')
-rw-r--r-- | html/rrdui.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/html/rrdui.js b/html/rrdui.js index 468fdc3..d5b80bb 100644 --- a/html/rrdui.js +++ b/html/rrdui.js @@ -103,6 +103,11 @@ function displayCurrentPage() if(img != null) continue; + var interval = child.getAttribute("interval"); + if(!interval || isNaN(interval) || interval <= 0) + interval = 0; + interval = Number(interval); + img = gdoc.createElement("img"); var title = child.getAttribute("title"); @@ -124,6 +129,7 @@ function displayCurrentPage() img._name = name; img._tbeg = tbeg; img._tend = tend; + img._tinterval = interval; reloadGraph(img); @@ -131,6 +137,14 @@ function displayCurrentPage() { actionGotoCancel(); return zoomGraphStart(evt || gwindow.event); } img.onmouseover = function(evt) { return actionsDisplay(gwindow.event ? gwindow.event : evt); } + + /* Setup for an auto scroll */ + if(interval) + { + /* Bump up auto scroll interval to 5 seconds */ + var interval = img._tinterval < 5 ? 5 : img._tinterval; + window.setInterval(autoScroll, interval * 1000, img); + } } } @@ -157,9 +171,13 @@ function reloadGraph(img) img._loading = true; updateCursors(img); + /* HACK: The onload event for IMG is called with a strange event target */ img.onload = new Function("reloadedGraph('" + img.id + "');"); img.setAttribute("src", uri); + + var now = nowTime(); + img._last = now; } function reloadedGraph(id) @@ -181,6 +199,34 @@ function updateCursors(img) img.style.cursor = img._loading ? "wait" : "crosshair"; } +function autoScroll(img) +{ + /* Don't auto scroll if we have loading issues */ + if(img._loading) + return; + + /* If we're displaying 'now' somewhere in the graph... */ + var now = nowTime(); + if((img._tend + img._tinterval + 2) >= now) + { + var diff = now - img._last; + + if(diff > 0) + { + /* ... then scroll by X seconds to scroll the graph */ + img._tbeg += diff; + img._tend += diff; + reloadGraph(img); + } + } +} + + + +/* ----------------------------------------------------------------------------- + * ZOOM + */ + function zoomGraphStart(evt) { /* COMPAT: In IE the left button is 1, Mozilla is 0 */ |