1+ import { useToggle } from '@react-hookz/web' ;
12import { type ThreeEvent } from '@react-three/fiber' ;
23import { useTooltip } from '@visx/tooltip' ;
34import { type ReactElement , useCallback } from 'react' ;
@@ -10,7 +11,11 @@ import VisMesh from './VisMesh';
1011interface Props {
1112 size ?: Size ;
1213 guides ?: 'horizontal' | 'vertical' | 'both' ;
13- renderTooltip : ( x : number , y : number ) => ReactElement | undefined ;
14+ renderTooltip : (
15+ x : number ,
16+ y : number ,
17+ exact : boolean ,
18+ ) => ReactElement | undefined ;
1419}
1520
1621function TooltipMesh ( props : Props ) {
@@ -27,6 +32,8 @@ function TooltipMesh(props: Props) {
2732 hideTooltip,
2833 } = useTooltip < Coords > ( ) ;
2934
35+ const [ isExact , toggleExact ] = useToggle ( ) ;
36+
3037 // Show and/or update tooltip when pointer moves except when dragging
3138 const onPointerMove = useCallback (
3239 ( evt : ThreeEvent < PointerEvent > ) => {
@@ -57,7 +64,16 @@ function TooltipMesh(props: Props) {
5764 } , [ hideTooltip , tooltipOpen ] ) ;
5865
5966 // Hide tooltip when user starts panning
60- const onPointerDown = useCallback ( ( ) => hideTooltip ( ) , [ hideTooltip ] ) ;
67+ const onPointerDown = useCallback (
68+ ( evt : ThreeEvent < PointerEvent > ) => {
69+ if ( evt . button === 1 ) {
70+ toggleExact ( ) ;
71+ } else {
72+ hideTooltip ( ) ;
73+ }
74+ } ,
75+ [ hideTooltip , toggleExact ] ,
76+ ) ;
6177
6278 // Show tooltip after dragging, if pointer is released inside the vis viewport
6379 const onPointerUp = useCallback (
@@ -71,7 +87,7 @@ function TooltipMesh(props: Props) {
7187 [ height , onPointerMove , width ] ,
7288 ) ;
7389
74- const content = tooltipData && renderTooltip ( ...tooltipData ) ;
90+ const content = tooltipData && renderTooltip ( ...tooltipData , isExact ) ;
7591
7692 return (
7793 < >
0 commit comments