Skip to content

Commit

Permalink
Merge pull request #359 from dwt/legend_respects_series_classes
Browse files Browse the repository at this point in the history
Respect series classes in legend renderer
  • Loading branch information
dchester committed Dec 2, 2013
2 parents 5fc0869 + 07f0d69 commit 8830920
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/js/Rickshaw.Graph.Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ Rickshaw.Graph.Legend = Rickshaw.Class.create( {
if (series.disabled) {
line.className += ' disabled';
}

if (series.className) {
d3.select(line).classed(series.className, true);
}
var swatch = document.createElement('div');
swatch.className = 'swatch';
swatch.style.backgroundColor = series.color;
Expand Down
21 changes: 17 additions & 4 deletions tests/Rickshaw.Graph.Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,28 @@ exports.hasDefaultClassName = function(test) {
};

exports.canOverrideClassName = function(test) {
var MyLegend = Rickshaw.Class.create( Rickshaw.Graph.Legend, {
className: 'fnord'
});
var MyLegend = Rickshaw.Class.create( Rickshaw.Graph.Legend, {
className: 'fnord'
});
var legend = new MyLegend({
graph: this.graph,
element: this.legendEl
});

test.equal(this.legendEl.className, "fnord")
test.done();
};

exports['should put series classes on legend elements'] = function(test) {
this.graph.series[0].className = 'fnord-series-0';
this.graph.series[1].className = 'fnord-series-1';

var legend = new Rickshaw.Graph.Legend({
graph: this.graph,
element: this.legendEl
});
test.equal(d3.select(this.legendEl).selectAll('.line').size(), 2);
test.equal(d3.select(this.legendEl).selectAll('.fnord-series-0').size(), 1);
test.equal(d3.select(this.legendEl).selectAll('.fnord-series-1').size(), 1);
test.done();
};

0 comments on commit 8830920

Please sign in to comment.