-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (52 loc) · 1.46 KB
/
index.js
File metadata and controls
55 lines (52 loc) · 1.46 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React, { Fragment, useState, useCallback } from "react"
const HOV_SIZE = 50
export const Point = ({ x, y, value, t, color, width }) => {
const [showPoint, setShowPoint] = useState(false)
const onShow = useCallback(() => setShowPoint(true), [setShowPoint])
const onHide = useCallback(() => setShowPoint(false), [setShowPoint])
return (
<g onMouseEnter={onShow} onMouseLeave={onHide}>
{showPoint && (
<Fragment>
<text x={x + 10} y={y - 10} fill={color}>
{value}
</text>
<circle cx={x} cy={y} r={5} fill={color} />
</Fragment>
)}
<rect
x={x - width / 2}
y={y - HOV_SIZE / 2}
width={width}
height={HOV_SIZE}
fill="transparent"
// If you're debugging the hover region, uncomment the following
// fill="rgba(0,0,0,0.5)"
></rect>
</g>
)
}
export const HighlightValueLabels = ({
visibleTransformedPointsOnCurves = [],
curveColors = [],
}) => {
return (
<g>
{visibleTransformedPointsOnCurves.flatMap((points, curveIndex) =>
points.map((p, i) => (
<Point
key={`${curveIndex},${i}`}
color={curveColors[curveIndex]}
width={
i === 0 || i === points.length - 1
? HOV_SIZE
: (points[i + 1].x - points[i - 1].x) / 2
}
{...p}
/>
))
)}
</g>
)
}
export default HighlightValueLabels