3.3.0 • Published 10 months ago

@visx/event v3.3.0

Weekly downloads
19,780
License
MIT
Repository
github
Last release
10 months ago

@visx/event

Installation

npm install --save @visx/event

Usage

@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.3.0

10 months ago

3.0.1

1 year ago

2.17.0

1 year ago

3.0.0

1 year ago

2.17.0-alpha.0

1 year ago

2.6.0

2 years ago

2.1.2

3 years ago

2.1.0

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.3.0

3 years ago

1.3.0-alpha.0

3 years ago

1.0.0

4 years ago

0.0.200-alpha.0

4 years ago