From f1844830498d1972e7989b8b603d20d0f7b1378a Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 18 Apr 2010 11:00:59 +0100 Subject: Clickable legend labels to show hide series --- index.html | 12 ++++++++++- jrrd.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index b3aff2e..ce63313 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - untitled + RRD Charts diff --git a/jrrd.js b/jrrd.js index 46858f0..a3b2464 100644 --- a/jrrd.js +++ b/jrrd.js @@ -191,18 +191,77 @@ jrrd.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) { jrrd.Chart = function(template, options) { this.template = template; - this.options = options; + this.options = jQuery.extend(true, {}, options); this.data = []; + var self = this; + $('.legend tr', this.template[0]).live('click', function(e) { + self.switchDataEnabled($(this).children('.legendLabel').text()); + self.draw(); + }); + + this.options['legend'] = { + 'labelFormatter': function(label, series) { + return self.legendLabelFormatter(label, series); + } + }; }; -jrrd.Chart.prototype.addData = function(label, db) { - this.data.push([label, db]); +jrrd.Chart.prototype.legendLabelFormatter = function(label, series) { + for(var i=0; i', + label, + ''].join(''); + } else { + return label; + } + } + } + return 'unknown: ' + label; }; -jrrd.Chart.prototype.draw = function(startTime, endTime) { +jrrd.Chart.prototype.addData = function(label, db, enabled) { + if(typeof enabled == 'undefined') { + enabled = true; + } + this.data.push([label, db, enabled]); +}; + +jrrd.Chart.prototype.switchDataEnabled = function(label) { + for(var i=0; i