Skip to content

Commit

Permalink
Adjust onZoom callback to not trigger on chart.zoomScale introduced i…
Browse files Browse the repository at this point in the history
…n v2.1.0 of the chartjs zoom plugin

Signed-off-by: yubiuser <[email protected]>
  • Loading branch information
yubiuser committed Nov 27, 2024
1 parent 4a7d847 commit 401a63c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scripts/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 401a63c

Please sign in to comment.