diff options
author | Richard Wall <richard@aziz> | 2010-04-18 14:02:34 +0100 |
---|---|---|
committer | Richard Wall <richard@aziz> | 2010-04-18 14:02:34 +0100 |
commit | b13d601d81e103377f25a890fcdeaa9c6ac81f4b (patch) | |
tree | 4f28a0aae93df31fc71c0fb95b4ce3b76d30fc48 /jrrd.js | |
parent | 3f5e6bd8eaeba9a67cc21f13bf536562d44b756b (diff) |
a neater way to highlight disabled items in the legend
Diffstat (limited to 'jrrd.js')
-rw-r--r-- | jrrd.js | 37 |
1 files changed, 15 insertions, 22 deletions
@@ -198,27 +198,6 @@ jrrd.Chart = function(template, options) { self.switchDataEnabled($(this).children('.legendLabel').text()); self.draw(); }); - - this.options['legend'] = { - 'labelFormatter': function(label, series) { - return self.legendLabelFormatter(label, series); - } - }; -}; - -jrrd.Chart.prototype.legendLabelFormatter = function(label, series) { - for(var i=0; i<this.data.length; i++) { - if(this.data[i][0] == label) { - if(!this.data[i][2]) { - return ['<span style="text-decoration: line-through;">', - label, - '</span>'].join(''); - } else { - return label; - } - } - } - return 'unknown: ' + label; }; jrrd.Chart.prototype.addData = function(label, db, enabled) { @@ -272,10 +251,24 @@ jrrd.Chart.prototype.draw = function() { return MochiKit.Async.gatherResults(results) .addCallback( function(self, data) { - for(var i=0; i<data.length; i++) { + var i, disabled = []; + for(i=0; i<data.length; i++) { data[i].label = self.data[i][0]; + if(!self.data[i][2]) { + disabled.push(self.data[i][0]); + } } var plot = $.plot(self.template, data, self.options); + + // Highlight any disabled data sources in the legend + self.template.find('.legendLabel').each( + function(i, el) { + var labelCell = $(el); + if( $.inArray(labelCell.text(), disabled) > -1 ) { + labelCell.addClass('disabled'); + } + } + ); }, this) .addErrback( function(self, failure) { |