-
Notifications
You must be signed in to change notification settings - Fork 327
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
fix: trigger onZoom from zoomScale #889
Conversation
Size Change: +12 B (+0.06%) Total Size: 20.5 kB
|
8112776
to
16bec6d
Compare
This update broke our use case and I don't know how to mitigate the new behavior. We basically have the same situation as described as in #768: We have a time series bar chart with only positive y-values. When zooming, y-axis should stay fixed at zero, because it does not make sense to lose the zero anchor. We basically used But with this change, this causes an endless loop. Any idea how to circumvent this? Old code
|
Instead of calling zoomScale from onZoom, just specify Or, you can just update the scale directly: chart.options.scales.y.min = 0;
chart.options.scales.y.max = chart.absMax / chart.getZoomLevel(); // probably not needed
chart.update(); |
This does not work, as it specifies the minimum, but not the maximal minimum (it doesn't get negative).
|
maybe |
Yes, but now I can only zoom in, and not zoom out again.
|
I've created #901 for letting you do something like: onZoom: function ({ chart, trigger }) {
if (trigger === 'api') {
// Ignore onZoom triggered by the chart.zoomScale api call below
return;
}
// The first time the chart is zoomed, save the maximum initial scale bound
if (!chart.absMax) chart.absMax = chart.getInitialScaleBounds().y.max;
// Calculate the maximum value to be shown for the current zoom level
const zoomMax = chart.absMax / chart.getZoomLevel();
// Update the y axis scale
chart.zoomScale("y", { min: 0, max: zoomMax }, "default");
// Update the y axis ticks and round values to natural numbers
chart.options.scales.y.ticks.callback = function (value) {
return value.toFixed(0);
}; |
fix #775