-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathSparklinesBars.js
More file actions
37 lines (31 loc) · 1.17 KB
/
SparklinesBars.js
File metadata and controls
37 lines (31 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import DataProcessor from './DataProcessor';
export default class SparklinesBars extends React.Component {
static propTypes = {
points: React.PropTypes.arrayOf(React.PropTypes.object),
height: React.PropTypes.number,
style: React.PropTypes.object,
barWidth: React.PropTypes.number
};
static defaultProps = {
style: { fill: 'slategray' }
};
render() {
const { points, height, style, barWidth } = this.props;
const strokeWidth = 1 * ((style && style.strokeWidth) || 0);
const width = barWidth || (points && points.length >= 2 ? Math.ceil(Math.max(0, points[1].x - points[0].x - strokeWidth)) : 0);
return (
<g>
{points.map((p, i) =>
DataProcessor.isGapValue(p.y) ? null : (<rect
key={i}
x={Math.ceil(p.x - strokeWidth * i)}
y={Math.ceil(p.y)}
width={Math.ceil(width)}
height={Math.ceil(Math.max(0, height - p.y))}
style={style} />)
)}
</g>
)
}
}