3.12.0 • Published 1 year ago
@visx/event v3.12.0
@visx/event
Installation
npm install --save @visx/eventUsage
@visx/event exports a utility localPoint that takes an SVG MouseEvent or TouchEvent as
input and returns a { x: number; y: number; } point coordinate (or null in the case the event
has no ownerSVGElement) within the coordinate system of the SVG. This makes placement of
tooltips, finding nearby datum, etc. easier.
Example:
import { localPoint } from '@visx/event';
<svg>
<SomeElement
{...}
onMouseMove={(event: MouseEvent) => {
const point = localPoint(event) || { x: 0, y: 0 };
// use coordinates ...
}}
/>
{...}
</svg>You may optionally pass a reference to the SVG node
import { useRef } from 'react';
import { localPoint } from '@visx/event';
const svgRef = useRef<SVGSVGElement>(null);
<svg ref={svgRef}>
<SomeElement
{...}
onMouseMove={(event: MouseEvent) => {
const point = localPoint(svgRef.current, event) || { x: 0, y: 0 };
// use coordinates ...
}}
/>
{...}
</svg>3.12.0
1 year ago
3.3.0
2 years ago
3.0.1
3 years ago
2.17.0
3 years ago
3.0.0
3 years ago
2.17.0-alpha.0
3 years ago
2.6.0
4 years ago
2.1.2
4 years ago
2.1.0
4 years ago
1.7.0
5 years ago
1.6.1
5 years ago
1.3.0
5 years ago
1.3.0-alpha.0
5 years ago
1.0.0
5 years ago
0.0.200-alpha.0
5 years ago