Line chart legend: legendHighlight matches by color
Which means that if you have a chart where the same color is used by multiple elements, clicking on a legend item will highlight all of them at once (wrong selection).
I discovered this while working with a composite lineChart, but I suppose that it applies also to other charts with legends. In order to avoid this behaviour, legends and charts should be linked by unique id attributes, not by color, stroke, or other style attributes.
The culprit function in lineChart():
function colorFilter(color, dashstyle, inv) {
return function () {
var item = d3.select(this);
var match = (item.attr('stroke') === color &&
item.attr('stroke-dasharray') === ((dashstyle instanceof Array) ?
dashstyle.join(',') : null)) || item.attr('fill') === color;
return inv ? !match : match;
};
}
Yeah that certainly is not a robust way to select items! Thanks for reporting this.
Another fun fact on this method: Internet Explorer may return an equivalent but different value that the one assigned.
If your original color was "rgba( 1, 1, 1, .2 )", IE will happily return "rgba( 1, 1, 1, 0.2 )" from the item.attr("xxx") methods.
In answer to a question above, the same sketchy code is found in the barChart.
One of the happy side effects of this "undocumented feature" is that I cna have a composite chart with two sub charts that represent one legend item. By making both charts the same color and setting one of the sub charts to not be in the legend ( see #871 ), I'm able to get the correct things to highlight when selecting the item in the legend.
this of course reminds me of: http://xkcd.com/1172/
What ever method is used in the future to get a "robost way to select items", should include the ability to highlight multiple sub charts.