-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathHoverBar.js
81 lines (74 loc) · 1.84 KB
/
HoverBar.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import PropTypes from 'prop-types';
import React from 'react';
import { Bar, Rect } from 'victory';
import _ from 'lodash';
import colors from '../../../styles/colors.css';
export const HoverBar = props => {
const {
barSpacing,
barWidth,
chartLabelWidth,
cornerRadius,
domain,
index,
scale = {
x: _.noop,
y: _.noop,
},
width,
x
} = props;
const barGridWidth = barWidth / 6;
const barGridRadius = _.get(cornerRadius, 'top', 2);
const widthCorrection = (width - chartLabelWidth) / width;
return (
<g className="HoverBar">
<g className="HoverBarTarget" pointerEvents="all">
<Rect
{...props}
x={0}
y={scale.x(index + 1) - (barWidth / 2) - (barSpacing / 2)}
rx={barGridRadius}
ry={barGridRadius}
width={scale.y(domain.y[1])}
height={barWidth + barSpacing}
style={{
stroke: 'transparent',
fill: 'transparent',
}}
{...props.events}
/>
</g>
<g className="barBg" pointerEvents="none">
<Rect
{...props}
x={0}
y={scale.x(index + 1) - (barGridWidth / 2)}
rx={barGridRadius}
ry={barGridRadius}
width={scale.y(domain.y[1]) - chartLabelWidth}
height={barGridWidth}
style={{
stroke: 'transparent',
fill: colors.axis,
}}
/>
</g>
<g pointerEvents="none">
<Bar
{...props}
width={scale.y(domain.x[1]) - chartLabelWidth}
x={x * widthCorrection}
/>
</g>
</g>
);
};
HoverBar.propTypes = {
chartLabelWidth: PropTypes.number,
domain: PropTypes.object.isRequired,
scale: PropTypes.object,
y: PropTypes.number,
};
HoverBar.displayName = 'HoverBar';
export default HoverBar;