Skip to content

Commit dc5bdca

Browse files
kafka-tamuraborisyankov
authored andcommitted
Patch: Right-most bar spills over viewbox (#75)
Subtracted twice the margin in calculating width of bar and added margin to PropTypes. This should fix the last bar from spilling over the viewbox.
1 parent 25b8577 commit dc5bdca

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/SparklinesBars.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class SparklinesBars extends React.Component {
77
height: React.PropTypes.number,
88
style: React.PropTypes.object,
99
barWidth: React.PropTypes.number,
10+
margin: React.PropTypes.number,
1011
onMouseMove: React.PropTypes.func
1112
};
1213

@@ -18,7 +19,8 @@ export default class SparklinesBars extends React.Component {
1819

1920
const { points, height, style, barWidth, onMouseMove } = this.props;
2021
const strokeWidth = 1 * ((style && style.strokeWidth) || 0);
21-
const width = barWidth || (points && points.length >= 2 ? Math.max(0, points[1].x - points[0].x - strokeWidth) : 0);
22+
const marginWidth = margin ? 2*margin : 0;
23+
const width = barWidth || (points && points.length >= 2 ? Math.max(0, points[1].x - points[0].x - strokeWidth - marginWidth) : 0);
2224

2325
return (
2426
<g transform = "scale(1,-1)">

0 commit comments

Comments
 (0)