Issue #68 updated discreteBar model to standard format

master-patched
Bob Monteverde 12 years ago
parent 4f6e678def
commit e767359018

@ -97,7 +97,6 @@ nv.addGraph(function() {
var chart = nv.models.discreteBarChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.rotateLabels(-45)
.staggerLabels(true)
//.staggerLabels(historicalBarChart[0].values.length > 8)
.tooltips(false)

@ -1853,40 +1853,47 @@ nv.models.cumulativeLineChart = function() {
return chart;
}
//TODO: consider deprecating by adding necessary features to multiBar model
nv.models.discreteBar = function() {
//============================================================
// 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(),
showValues = false,
valueFormat = d3.format(',.2f'),
xDomain, yDomain;
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()
, showValues = false
, valueFormat = d3.format(',.2f')
, xDomain
, yDomain
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
;
//============================================================
//============================================================
// Private Variables
//------------------------------------------------------------
var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout'),
x0, y0;
var x0, y0;
//============================================================
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);
//add series index to each data point for reference
@ -1899,6 +1906,10 @@ nv.models.discreteBar = 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) {
@ -1920,16 +1931,23 @@ nv.models.discreteBar = function() {
x0 = x0 || x;
y0 = y0 || y.copy().range([y(0),y(0)]);
//------------------------------------------------------------
var wrap = d3.select(this).selectAll('g.nv-wrap.nv-discretebar').data([data]);
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('g.nv-wrap.nv-discretebar').data([data]);
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-discretebar');
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 + ')');
//------------------------------------------------------------
//TODO: by definition, the discrete bar should not have multiple groups, will modify/remove later
@ -2044,11 +2062,7 @@ nv.models.discreteBar = function() {
});
//TODO: decide if this makes sense to add into all the models for ease of updating (updating without needing the selection)
chart.update = function() { chart(selection) };
//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();
@ -2058,6 +2072,10 @@ nv.models.discreteBar = function() {
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
chart.x = function(_) {
@ -2144,6 +2162,8 @@ nv.models.discreteBar = function() {
return chart;
};
//============================================================
return chart;
}

8
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,37 +1,44 @@
//TODO: consider deprecating by adding necessary features to multiBar model
nv.models.discreteBar = function() {
//============================================================
// 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(),
showValues = false,
valueFormat = d3.format(',.2f'),
xDomain, yDomain;
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()
, showValues = false
, valueFormat = d3.format(',.2f')
, xDomain
, yDomain
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
;
//============================================================
//============================================================
// Private Variables
//------------------------------------------------------------
var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout'),
x0, y0;
var x0, y0;
//============================================================
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);
//add series index to each data point for reference
@ -44,6 +51,10 @@ nv.models.discreteBar = 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) {
@ -65,16 +76,23 @@ nv.models.discreteBar = function() {
x0 = x0 || x;
y0 = y0 || y.copy().range([y(0),y(0)]);
//------------------------------------------------------------
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = d3.select(this).selectAll('g.nv-wrap.nv-discretebar').data([data]);
var wrap = container.selectAll('g.nv-wrap.nv-discretebar').data([data]);
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-discretebar');
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 + ')');
//------------------------------------------------------------
//TODO: by definition, the discrete bar should not have multiple groups, will modify/remove later
@ -189,11 +207,7 @@ nv.models.discreteBar = function() {
});
//TODO: decide if this makes sense to add into all the models for ease of updating (updating without needing the selection)
chart.update = function() { chart(selection) };
//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();
@ -203,6 +217,10 @@ nv.models.discreteBar = function() {
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
chart.x = function(_) {
@ -289,6 +307,8 @@ nv.models.discreteBar = function() {
return chart;
};
//============================================================
return chart;
}

Loading…
Cancel
Save