commandPalette: fix cursor position in graph view (#1008)

This commit is contained in:
Ape 2026-04-23 14:20:52 +01:00 • committed by GitHub
parent 6c6a0a0711
commit f8c5207f49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -229,8 +229,15 @@ function GraphView({ result }: { result: CalculatorResult; }) {
onMouseMove={event => {
const bounds = svgRef.current?.getBoundingClientRect();
if (!bounds) return;
const scaleX = bounds.width / GRAPH_WIDTH;
const localX = (event.clientX - bounds.left) / scaleX;
const viewAspect = GRAPH_WIDTH / GRAPH_HEIGHT;
const boundsAspect = bounds.width / bounds.height;
const renderedWidth = boundsAspect > viewAspect
? bounds.height * viewAspect
: bounds.width;
const renderedLeft = bounds.left + (bounds.width - renderedWidth) / 2;
const scaleX = renderedWidth / GRAPH_WIDTH;
const localX = (event.clientX - renderedLeft) / scaleX;
const innerX = clamp(localX - GRAPH_PADDING_X, 0, GRAPH_INNER_WIDTH);
const clampedRatio = innerX / GRAPH_INNER_WIDTH;
const nextX = graph.domain[0] + (graph.domain[1] - graph.domain[0]) * clampedRatio;