|
|
|
@ -4518,15 +4518,15 @@ nv.models.multiBar = function() {
|
|
|
|
|
function chart(selection) {
|
|
|
|
|
selection.each(function(data) {
|
|
|
|
|
var availableWidth = width - margin.left - margin.right,
|
|
|
|
|
availableHeight = height - margin.top - margin.bottom;
|
|
|
|
|
availableHeight = height - margin.top - margin.bottom,
|
|
|
|
|
container = d3.select(this);
|
|
|
|
|
|
|
|
|
|
if (stacked) {
|
|
|
|
|
if (stacked)
|
|
|
|
|
data = d3.layout.stack()
|
|
|
|
|
.offset('zero')
|
|
|
|
|
.values(function(d){ return d.values })
|
|
|
|
|
.y(getY)
|
|
|
|
|
(data);
|
|
|
|
|
}
|
|
|
|
|
.offset('zero')
|
|
|
|
|
.values(function(d){ return d.values })
|
|
|
|
|
.y(getY)
|
|
|
|
|
(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//add series index to each data point for reference
|
|
|
|
@ -4579,7 +4579,7 @@ nv.models.multiBar = function() {
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Setup containers and skeleton of chart
|
|
|
|
|
|
|
|
|
|
var wrap = d3.select(this).selectAll('g.nv-wrap.nv-multibar').data([data]);
|
|
|
|
|
var wrap = container.selectAll('g.nv-wrap.nv-multibar').data([data]);
|
|
|
|
|
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibar');
|
|
|
|
|
var defsEnter = wrapEnter.append('defs');
|
|
|
|
|
var gEnter = wrapEnter.append('g');
|
|
|
|
@ -5188,39 +5188,57 @@ nv.models.multiBarChart = function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nv.models.multiBarHorizontal = function() {
|
|
|
|
|
var margin = {top: 0, right: 0, bottom: 0, left: 0},
|
|
|
|
|
width = 960,
|
|
|
|
|
height = 500,
|
|
|
|
|
id = Math.floor(Math.random() * 10000), //Create semi-unique ID in case user doesn't select one
|
|
|
|
|
x = d3.scale.ordinal(),
|
|
|
|
|
y = d3.scale.linear(),
|
|
|
|
|
getX = function(d) { return d.x },
|
|
|
|
|
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(),
|
|
|
|
|
stacked = false,
|
|
|
|
|
showValues = false,
|
|
|
|
|
valuePadding = 60,
|
|
|
|
|
valueFormat = d3.format(',.2f'),
|
|
|
|
|
delay = 1200,
|
|
|
|
|
xDomain, yDomain,
|
|
|
|
|
x0, y0;
|
|
|
|
|
|
|
|
|
|
var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout');
|
|
|
|
|
//============================================================
|
|
|
|
|
// Public Variables with Default Settings
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
var margin = {top: 0, right: 0, bottom: 0, left: 0}
|
|
|
|
|
, width = 960
|
|
|
|
|
, height = 500
|
|
|
|
|
, id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one
|
|
|
|
|
, x = d3.scale.ordinal()
|
|
|
|
|
, y = d3.scale.linear()
|
|
|
|
|
, getX = function(d) { return d.x }
|
|
|
|
|
, 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()
|
|
|
|
|
, stacked = false
|
|
|
|
|
, showValues = false
|
|
|
|
|
, valuePadding = 60
|
|
|
|
|
, valueFormat = d3.format(',.2f')
|
|
|
|
|
, delay = 1200
|
|
|
|
|
, xDomain
|
|
|
|
|
, yDomain
|
|
|
|
|
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
// Private Variables
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
var x0, y0 //used to store previous scales
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function chart(selection) {
|
|
|
|
|
selection.each(function(data) {
|
|
|
|
|
var availableWidth = width - margin.left - margin.right,
|
|
|
|
|
availableHeight = height - margin.top - margin.bottom;
|
|
|
|
|
availableHeight = height - margin.top - margin.bottom,
|
|
|
|
|
container = d3.select(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stacked)
|
|
|
|
|
data = d3.layout.stack()
|
|
|
|
|
.offset('zero')
|
|
|
|
|
.values(function(d){ return d.values })
|
|
|
|
|
.y(getY)
|
|
|
|
|
(data);
|
|
|
|
|
.offset('zero')
|
|
|
|
|
.values(function(d){ return d.values })
|
|
|
|
|
.y(getY)
|
|
|
|
|
(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//add series index to each data point for reference
|
|
|
|
@ -5233,6 +5251,10 @@ nv.models.multiBarHorizontal = function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Setup Scales
|
|
|
|
|
|
|
|
|
|
// remap and flatten the data for use in calculating the scales' domains
|
|
|
|
|
var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate
|
|
|
|
|
data.map(function(d) {
|
|
|
|
|
return d.values.map(function(d,i) {
|
|
|
|
@ -5244,25 +5266,33 @@ nv.models.multiBarHorizontal = function() {
|
|
|
|
|
.rangeBands([0, availableHeight], .1);
|
|
|
|
|
|
|
|
|
|
y .domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return d.y + (stacked ? d.y0 : 0) }).concat(forceY)))
|
|
|
|
|
//.range([0, availableWidth]);
|
|
|
|
|
|
|
|
|
|
if (showValues && !stacked) y.range([(y.domain()[0] < 0 ? valuePadding : 0), availableWidth - (y.domain()[1] > 0 ? valuePadding : 0) ]);
|
|
|
|
|
else y.range([0, availableWidth]);
|
|
|
|
|
if (showValues && !stacked)
|
|
|
|
|
y.range([(y.domain()[0] < 0 ? valuePadding : 0), availableWidth - (y.domain()[1] > 0 ? valuePadding : 0) ]);
|
|
|
|
|
else
|
|
|
|
|
y.range([0, availableWidth]);
|
|
|
|
|
|
|
|
|
|
//store old scales if they exist
|
|
|
|
|
x0 = x0 || x;
|
|
|
|
|
y0 = y0 || d3.scale.linear().domain(y.domain()).range([y(0),y(0)]);
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Setup containers and skeleton of chart
|
|
|
|
|
|
|
|
|
|
var wrap = d3.select(this).selectAll('g.nv-wrap.nv-multibarHorizontal').data([data]);
|
|
|
|
|
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibarHorizontal');
|
|
|
|
|
var defsEnter = wrapEnter.append('defs');
|
|
|
|
|
var gEnter = wrapEnter.append('g');
|
|
|
|
|
var g = wrap.select('g');
|
|
|
|
|
|
|
|
|
|
gEnter.append('g').attr('class', 'nv-groups');
|
|
|
|
|
|
|
|
|
|
var g = wrap.select('g')
|
|
|
|
|
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var groups = wrap.select('.nv-groups').selectAll('.nv-group')
|
|
|
|
@ -5398,52 +5428,9 @@ nv.models.multiBarHorizontal = function() {
|
|
|
|
|
.attr('width', function(d,i) {
|
|
|
|
|
return Math.abs(y(getY(d,i)) - y(0))
|
|
|
|
|
});
|
|
|
|
|
/*
|
|
|
|
|
if (stacked)
|
|
|
|
|
d3.transition(bars)
|
|
|
|
|
.delay(function(d,i) { return i * 1000 / data[0].values.length })
|
|
|
|
|
.attr('x', function(d,i) {
|
|
|
|
|
return y(d.y0);
|
|
|
|
|
})
|
|
|
|
|
.attr('width', function(d,i) {
|
|
|
|
|
return Math.abs(y(getY(d,i) + d.y0) - y(d.y0))
|
|
|
|
|
})
|
|
|
|
|
.each('end', function() {
|
|
|
|
|
d3.transition(d3.select(this))
|
|
|
|
|
.attr('y', function(d,i) {
|
|
|
|
|
return 0
|
|
|
|
|
})
|
|
|
|
|
.attr('height', x.rangeBand() );
|
|
|
|
|
})
|
|
|
|
|
else
|
|
|
|
|
d3.transition(bars)
|
|
|
|
|
.delay(function(d,i) { return i * 1200 / data[0].values.length })
|
|
|
|
|
.attr('y', function(d,i) {
|
|
|
|
|
return d.series * x.rangeBand() / data.length
|
|
|
|
|
})
|
|
|
|
|
.attr('height', x.rangeBand() / data.length )
|
|
|
|
|
.each('end', function() {
|
|
|
|
|
d3.transition(d3.select(this))
|
|
|
|
|
.attr('x', function(d,i) {
|
|
|
|
|
return getY(d,i) < 0 ? //TODO: stacked must be all positive or all negative, not both?
|
|
|
|
|
y(getY(d,i)) :
|
|
|
|
|
y(0)
|
|
|
|
|
})
|
|
|
|
|
.attr('width', function(d,i) {
|
|
|
|
|
return Math.abs(y(getY(d,i)) - y(0))
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: decide if this makes sense to add into all the models for ease of updating (updating without needing the selection)
|
|
|
|
|
chart.update = function() {
|
|
|
|
|
selection.transition().call(chart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//store old scales for use in transitions on update, to animate from old to new positions, and sizes
|
|
|
|
|
//store old scales for use in transitions on update
|
|
|
|
|
x0 = x.copy();
|
|
|
|
|
y0 = y.copy();
|
|
|
|
|
|
|
|
|
@ -5453,6 +5440,10 @@ nv.models.multiBarHorizontal = function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
// Expose Public Variables
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
chart.dispatch = dispatch;
|
|
|
|
|
|
|
|
|
|
chart.x = function(_) {
|
|
|
|
@ -5557,6 +5548,8 @@ nv.models.multiBarHorizontal = function() {
|
|
|
|
|
return chart;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
}
|
|
|
|
|