diff --git a/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts b/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts index 39a2657137..982df5465b 100644 --- a/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts +++ b/packages/perspective-viewer-d3fc/src/ts/tooltip/nearbyTip.ts @@ -147,10 +147,12 @@ export default (): NearbyTip => { ) return null; - return Math.sqrt( - Math.pow((xScale(v[xValueName]) as number) - pos.x, 2) + - Math.pow(scale(v[yValueName]) - pos.y, 2) - ); + const xDist = (xScale(v[xValueName]) as number) - pos.x; + const yDist = scale(v[yValueName]) - pos.y; + + if (xDist <= 0 && yDist <= 0) { + return Math.sqrt(Math.pow(xDist, 2) + Math.pow(yDist, 2)); + } }; };