From b96a962c8ea828569c17b3c730f6a113a1013bf5 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Fri, 9 Apr 2010 03:39:46 +0100 Subject: enable range selections --- index.html | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index b7986f1..66baba2 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,7 @@ $.ajax({ url: url, dataType: 'text', + cache: false, beforeSend: function(request) { try { request.overrideMimeType('text/plain; charset=x-user-defined'); @@ -148,11 +149,8 @@ } }; - $(function() { - new RrdDataWrapper('data/localhost/load/load.rrd') - .getData( - new Date('7 April 2010 09:30:00'), - new Date('7 April 2010 11:00:00')) + function drawChart(db, startTime, endTime) { + return db.getData(startTime, endTime) .addCallback( function(data) { var plot = $.plot($('.container'), data, graphOptions); @@ -161,11 +159,26 @@ function(failure) { $('.container').text('error: ' + failure.message); }); + } + + var db = new RrdDataWrapper('data/localhost/load/load.rrd'); + + $(function() { + drawChart(db, new Date('7 April 2010 09:30:00'), + new Date('7 April 2010 15:00:00')); + $('.container').bind('plotclick', function(event, pos, item) { if (item) { console.log(['X: ' + new Date(item.datapoint[0]), 'Y: ' + item.datapoint[1]]); } }); + + $('.container').bind("plotselected", function(event, ranges) { + var startTime = new Date(ranges.xaxis.from); + var endTime = new Date(ranges.xaxis.to); + drawChart(db, startTime, endTime); + console.log("You selected " + startTime + " to " + endTime); + }); }); -- cgit v1.1-4-g5e80