Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1685 - add adjustable padding between each bar in discreteBar #2136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
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=_;}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

barWidth only makes sense to be between 0 and 1 here right? So it should probably validate that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liquidpele if it doesn't validate, should I just return the default value or do a console.error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would nv.log it (wrapper around console.log we use) and ignore the passed value.

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