-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathSparklinesReferenceLine.js
More file actions
32 lines (25 loc) · 911 Bytes
/
SparklinesReferenceLine.js
File metadata and controls
32 lines (25 loc) · 911 Bytes
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
import PropTypes from 'prop-types';
import React from 'react';
import * as dataProcessing from './dataProcessing';
export default class SparklinesReferenceLine extends React.Component {
static propTypes = {
type: PropTypes.oneOf(['max', 'min', 'mean', 'avg', 'median', 'custom']),
value: PropTypes.number,
style: PropTypes.object
};
static defaultProps = {
type: 'mean',
style: { stroke: 'red', strokeOpacity: .75, strokeDasharray: '2, 2' }
};
render() {
const { points, margin, type, style, value } = this.props;
const ypoints = points.map(p => p.y);
const y = type == 'custom' ? value : dataProcessing[type](ypoints);
return (
<line
x1={points[0].x} y1={y + margin}
x2={points[points.length - 1].x} y2={y + margin}
style={style} />
)
}
}