From 401a63c4c3749c10b38b61db9f5807b99a236e2e Mon Sep 17 00:00:00 2001 From: yubiuser Date: Wed, 27 Nov 2024 22:12:46 +0100 Subject: [PATCH] Adjust onZoom callback to not trigger on chart.zoomScale introduced in v2.1.0 of the chartjs zoom plugin Signed-off-by: yubiuser --- scripts/js/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/js/index.js b/scripts/js/index.js index a68648c07..d5ec1125d 100644 --- a/scripts/js/index.js +++ b/scripts/js/index.js @@ -515,8 +515,13 @@ $(function () { enabled: true, }, mode: "y", - onZoom: function ({ chart }) { + 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();