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

Make bar width (percentage) a prop for Bar Series #1018

Merged
merged 2 commits into from
Oct 22, 2018
Merged
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
5 changes: 5 additions & 0 deletions docs/bar-series.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ Type: `object`

A list of CSS properties to style the series outside of the explicitly set properties. Note that it will override all other properties (ie fill, stroke, opacity, color). See [style](style.md)

#### barWidth
Type: `Number`
The percentage for which each bar fills the designated bucket. 1.0 means that the bar fills the whole bucket (no padding between bars), while a
smaller percentage means more whitespace between the bars.

## Interaction handlers
#### onNearestX (optional)

Expand Down
14 changes: 11 additions & 3 deletions src/plot/series/bar-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ class BarSeries extends AbstractSeries {
valuePosAttr: PropTypes.string,
lineSizeAttr: PropTypes.string,
valueSizeAttr: PropTypes.string,
cluster: PropTypes.string
cluster: PropTypes.string,
barWidth: PropTypes.number
};
}

static get defaultProps() {
return {
barWidth: 0.85
};
}

Expand All @@ -52,7 +59,8 @@ class BarSeries extends AbstractSeries {
marginTop,
style,
valuePosAttr,
valueSizeAttr
valueSizeAttr,
barWidth
} = this.props;

if (!data) {
Expand All @@ -79,7 +87,7 @@ class BarSeries extends AbstractSeries {
this._getAttributeFunctor('stroke') || this._getAttributeFunctor('color');
const opacityFunctor = this._getAttributeFunctor('opacity');

const itemSize = (distance / 2) * 0.85;
const itemSize = (distance / 2) * barWidth;

return (
<g
Expand Down