Expose d3's stack offset to allow for percent-based stack using 'expand' - fix #225

master
Rusty Bailey 11 years ago
parent 843577aff8
commit a4ef6d3c5c

@ -16,6 +16,7 @@ nv.models.multiBar = function() {
, forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove
, clipEdge = true , clipEdge = true
, stacked = false , stacked = false
, stackOffset = 'zero' // options include 'silhouette', 'wiggle', 'expand', 'zero', or a custom function
, color = nv.utils.defaultColor() , color = nv.utils.defaultColor()
, hideable = false , hideable = false
, barColor = null // adding the ability to set the color for each rather than the whole group , barColor = null // adding the ability to set the color for each rather than the whole group
@ -60,7 +61,7 @@ nv.models.multiBar = function() {
if (stacked) if (stacked)
data = d3.layout.stack() data = d3.layout.stack()
.offset('zero') .offset(stackOffset)
.values(function(d){ return d.values }) .values(function(d){ return d.values })
.y(getY) .y(getY)
(!data.length && hideable ? hideable : data); (!data.length && hideable ? hideable : data);
@ -399,6 +400,12 @@ nv.models.multiBar = function() {
return chart; return chart;
}; };
chart.stackOffset = function(_) {
if (!arguments.length) return stackOffset;
stackOffset = _;
return chart;
};
chart.clipEdge = function(_) { chart.clipEdge = function(_) {
if (!arguments.length) return clipEdge; if (!arguments.length) return clipEdge;
clipEdge = _; clipEdge = _;

@ -393,7 +393,7 @@ nv.models.multiBarChart = function() {
chart.yAxis = yAxis; chart.yAxis = yAxis;
d3.rebind(chart, multibar, 'x', 'y', 'xDomain', 'yDomain', 'xRange', 'yRange', 'forceX', 'forceY', 'clipEdge', d3.rebind(chart, multibar, 'x', 'y', 'xDomain', 'yDomain', 'xRange', 'yRange', 'forceX', 'forceY', 'clipEdge',
'id', 'stacked', 'delay', 'barColor','groupSpacing'); 'id', 'stacked', 'stackOffset', 'delay', 'barColor','groupSpacing');
chart.margin = function(_) { chart.margin = function(_) {
if (!arguments.length) return margin; if (!arguments.length) return margin;

Loading…
Cancel
Save