Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ nv.log = function() {
};

// print console warning, should be used by deprecated functions
nv.deprecated = function(name, info) {
nv.deprecated = nv.warn = function(name, info) {
if (console && console.warn) {
console.warn('nvd3 warning: `' + name + '` has been deprecated. ', info || '');
}
Expand Down
6 changes: 4 additions & 2 deletions src/models/discreteBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ nv.models.discreteBar = function() {
//------------------------------------------------------------

var margin = {top: 0, right: 0, bottom: 0, left: 0}
, barWidth = 0.9 // default to 90% so that there is spacing in between each bar in the chart
, width = 960
, height = 500
, id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one
Expand Down Expand Up @@ -61,7 +62,7 @@ nv.models.discreteBar = function() {
});

x .domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x }))
.rangeBands(xRange || [0, availableWidth], .1);
.rangeBands(xRange || [0, availableWidth], 1 - barWidth);
y .domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return d.y }).concat(forceY)));

// If showValues, pad the Y axis range to account for label height
Expand Down Expand Up @@ -178,7 +179,7 @@ nv.models.discreteBar = function() {
.select('rect')
.attr('class', rectClass)
.watchTransition(renderWatch, 'discreteBar: bars rect')
.attr('width', x.rangeBand() * .9 / data.length);
.attr('width', x.rangeBand() * barWidth / data.length);
bars.watchTransition(renderWatch, 'discreteBar: bars')
//.delay(function(d,i) { return i * 1200 / data[0].values.length })
.attr('transform', function(d,i) {
Expand Down Expand Up @@ -216,6 +217,7 @@ nv.models.discreteBar = function() {

chart._options = Object.create({}, {
// simple options, just get/set the necessary values
barWidth:{get: function(){return barWidth;}, set: function(_){barWidth=nv.utils.setLimits(_, 0.1, 1);}},
width: {get: function(){return width;}, set: function(_){width=_;}},
height: {get: function(){return height;}, set: function(_){height=_;}},
forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}},
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,19 @@ nv.utils.pointIsInArc = function(pt, ptData, d3Arc) {
(theta1 <= angle) && (angle <= theta2);
};

/**
* Given a number, value, reset its value if it is outside
* the limits of minValue or maxValue
* @param {number} value must be [minValue, maxValue]
* @param {number} minValue lower bound
* @param {number} maxValue upper bound
* @return {number} the original value if within the limits defined, otherwise either the min or max value
*/
nv.utils.setLimits = function (value, minValue, maxValue) {
if (minValue <= value && value <= maxValue) {
return value;
} else {
nv.warn('nvd3 warning: Value is out of bounds. Expected ' + value + ' to be within (' + minValue + ', ' + maxValue + ')');
return value < minValue ? minValue : maxValue;
}
};