-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPoint.tsx
60 lines (54 loc) · 1.63 KB
/
Point.tsx
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
import React, { FC, MouseEventHandler, SVGAttributes } from 'react';
import { PointDatum } from 'eazychart-core/src/types';
import { defaultPointDatum, defaultPointRadius } from 'eazychart-core/src';
import { useTooltip } from '@/components/addons/tooltip/use-tooltip';
import { useChart } from '@/lib/use-chart';
export interface PointProps extends SVGAttributes<SVGCircleElement> {
shapeDatum?: PointDatum;
}
export const Point: FC<PointProps> = ({
shapeDatum = defaultPointDatum,
r = defaultPointRadius,
fill,
stroke,
strokeWidth = 1,
children,
...rest
}) => {
const { showTooltip, hideTooltip, moveTooltip } = useTooltip();
const {
animationOptions: { duration },
} = useChart();
const { x, y, color } = shapeDatum;
const handleMouseOver: MouseEventHandler<SVGCircleElement> = (event) => {
showTooltip(shapeDatum, event as any as MouseEvent);
};
const handleMouseMove: MouseEventHandler<SVGCircleElement> = (event) => {
moveTooltip(shapeDatum, event as any as MouseEvent);
};
const handleMouseLeave: MouseEventHandler<SVGCircleElement> = (event) => {
hideTooltip(shapeDatum, event as any as MouseEvent);
};
return (
<circle
stroke={stroke || color}
fill={fill || color}
r={r}
cx={x}
cy={y}
onMouseOver={handleMouseOver}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
{...rest}
strokeWidth={strokeWidth}
data-testid="ez-point"
className="ez-point"
>
{children ? (
children
) : (
<animate attributeName="r" from={0} to={r} dur={`${duration}ms`} />
)}
</circle>
);
};