Skip to content

[charts-pro] Fix initial render for zoom slider selection #18208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ export function ChartAxisZoomSliderTrack({
// Ensure the zoomFromPointerDown is within the min and max range
zoomFromPointerDown = Math.max(Math.min(zoomFromPointerDown, maxEnd), minStart);

let pointerMoved = false;

const onPointerMove = rafThrottle(function onPointerMove(pointerMoveEvent: PointerEvent) {
const pointerMovePoint = getSVGPoint(element, pointerMoveEvent);
const zoomFromPointerMove = calculateZoomFromPoint(
Expand All @@ -92,7 +90,6 @@ export function ChartAxisZoomSliderTrack({
return;
}

pointerMoved = true;
const zoomOptions = selectorChartAxisZoomOptionsLookup(store.getSnapshot(), axisId);

instance.setAxisZoomData(axisId, (prevZoomData) => {
Expand Down Expand Up @@ -138,27 +135,6 @@ export function ChartAxisZoomSliderTrack({
document.removeEventListener('pointerup', onPointerUp);
setIsSelecting(false);
onSelectEnd?.();

if (pointerMoved) {
return;
}

// If the pointer didn't move, we still need to respect the zoom constraints (minSpan, etc.)
// In that case, we assume the start to be the pointerZoom and calculate the end.
const pointerUpPoint = getSVGPoint(element, pointerUpEvent);
const zoomFromPointerUp = calculateZoomFromPoint(store.getSnapshot(), axisId, pointerUpPoint);

if (zoomFromPointerUp === null) {
return;
}

const zoomOptions = selectorChartAxisZoomOptionsLookup(store.getSnapshot(), axisId);

instance.setAxisZoomData(axisId, (prev) => ({
...prev,
start: zoomFromPointerUp,
end: calculateZoomEnd(zoomFromPointerUp, prev, zoomOptions),
}));
};

event.preventDefault();
Expand All @@ -170,11 +146,6 @@ export function ChartAxisZoomSliderTrack({

onSelectStart?.();
setIsSelecting(true);
instance.setAxisZoomData(axisId, (prev) => ({
...prev,
start: zoomFromPointerDown,
end: zoomFromPointerDown,
}));
};

return (
Expand Down