-
Notifications
You must be signed in to change notification settings - Fork 335
Description
I ran into a couple edge cases zooming with dynamic data and limits:
- unexpected
isZoomedOrPanned()
true afterresetZoom
if data changed while zoomed - jitter on zoom-in with fully constrained limits (like a "locked" axis)
- zoom out against a limit vanishes to a no-op as the focal point approaches the other side of the chart
The first issue seems related to, and can be fixed by fixing, getInitialScaleBounds()
not updating the scale limits (relying on a previous zoom or pan operation to have done so). An easy fix that covers the resetZoom
case is to call storeOriginalScaleLimits
at the beginning of getInitialScaleBounds
, though this does still return stale bounds until resetZoom
is actually called; a full fix would be more involved, and it's not clear to me that the functionality is exposed on scales that would make for something correct in all cases (e.g. "original"
limits as data change while zoomed for scales with unset min
/max
, especially if they pad).
The second and third issues can be fixed by simplifying the arithmetic in updateRange(...)
to always respect the zoom range, though this does also affect zooming out from category scales in a potentially unintuitive way. Since category zooming tended to round the vanishing case up to 1, preserving the range in the limit case may now zoom out by two categories on the side opposite the limit in the case where the focal point falls between categories, as illustrated in the changed test spec. It may be worth evaluating what the actual desired behavior is here.
Another possible issue it might not be my place to bring up is the definition of zoom amount/level. These don't seem to be spelled out in the documentation as far as I can tell, but the behavior doesn't seem as one might intend:
chart.getZoomLevel() = 1
chart.zoom(1.99);
chart.getZoomLevel() = 100
chart.zoom(-98);
chart.getZoomLevel() = 1
where chart.zoom(2)
is a zoom to infinity (min = max
). (https://codepen.io/AsturaPhoenix/pen/zYaBqRp)