#69: adding a way to color individual bars (rather than the whole series as it is done right now). Leaving the previous behavior as the default.

master-patched
Ricardo 11 years ago
parent 5079b67649
commit 4fccaa8cb7

@ -6108,6 +6108,7 @@ nv.models.multiBarHorizontal = function() {
, getY = function(d) { return d.y }
, forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove
, color = nv.utils.defaultColor()
, barColor = null // adding the ability to set the color for each rather than the whole group
, stacked = false
, showValues = false
, valuePadding = 60
@ -6300,9 +6301,11 @@ nv.models.multiBarHorizontal = function() {
bars
.attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'})
//.attr('transform', function(d,i,j) {
//return 'translate(' + y0(stacked ? d.y0 : 0) + ',' + x(getX(d,i)) + ')'
//})
if (barColor) {
bars.style('fill', barColor).style('stroke', barColor);
}
if (stacked)
d3.transition(bars)
//.delay(function(d,i) { return i * delay / data[0].values.length })
@ -6426,6 +6429,12 @@ nv.models.multiBarHorizontal = function() {
return chart;
};
chart.barColor = function(_) {
if (!arguments.length) return barColor;
barColor = nv.utils.getColor(_);
return chart;
};
chart.id = function(_) {
if (!arguments.length) return id;
id = _;

6
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -15,6 +15,7 @@ nv.models.multiBarHorizontal = function() {
, getY = function(d) { return d.y }
, forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove
, color = nv.utils.defaultColor()
, barColor = null // adding the ability to set the color for each rather than the whole group
, stacked = false
, showValues = false
, valuePadding = 60
@ -207,9 +208,11 @@ nv.models.multiBarHorizontal = function() {
bars
.attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'})
//.attr('transform', function(d,i,j) {
//return 'translate(' + y0(stacked ? d.y0 : 0) + ',' + x(getX(d,i)) + ')'
//})
if (barColor) {
bars.style('fill', barColor).style('stroke', barColor);
}
if (stacked)
d3.transition(bars)
//.delay(function(d,i) { return i * delay / data[0].values.length })
@ -333,6 +336,12 @@ nv.models.multiBarHorizontal = function() {
return chart;
};
chart.barColor = function(_) {
if (!arguments.length) return barColor;
barColor = nv.utils.getColor(_);
return chart;
};
chart.id = function(_) {
if (!arguments.length) return id;
id = _;

Loading…
Cancel
Save