Skip to content

added allowZoom pre-condition to filter out unnecessary zoom events #329

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

Conversation

nullifiedtsk
Copy link

@nullifiedtsk nullifiedtsk commented Mar 3, 2020

Extended zoom plugin options with parameter options.plugins.zoom.allowZoom. It is function with signature of

function allowZoom(
  chart: Chart, 
  scale: ChartElement, 
  originalOptions: ScalesOptions, 
  changes: ScalesOptionsPendingChanges
): boolean

May be used to prevent unnecessary zooming operations (e.g. chart is zoomed too near).

If function is defined and returns false, chart scale options will be restored as before calculating new time/ticks value (before calling chart.update).

p.s. Added example of usage to README

…gnature of `(chart: Chart, scale: ChartElement, originalOptions: ScalesOptions, changes: ScalesOptionsPendingChanges) => boolean` option as zooming pre-condition evaluator.
@benmccann benmccann changed the title # nullifiedtsk - added allowZoom pre-condition to filter out unnessecary zoom events. added allowZoom pre-condition to filter out unnessecary zoom events Mar 23, 2020
* @param {Scale} scale - Scale/Axis being zoomed (x/y, method will be called for each axis)
* @param {ChartOptions} options - Original chart options before any zoom values applied.
* @param {PendingScaleChanges} changes - Changes that will be applied to chart options if method returns true.
allowZoom: function(chart, scale, options, changes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most Chart.js options that take functions have those functions take a single object argument. Can you make these parameters properties on an object that is passed to the function instead?

* @property {MinMaxValue} time - new options.time values (may be undefined)
*/
/**
* This function may be used to filter unnessecary zoom events. Returns true to allow zooming, false to prevent.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary

@alexeigs
Copy link

alexeigs commented Apr 1, 2020

Great adjustment, much in need of it. When do you expect this to be available in the official plugin?

@benmccann
Copy link
Collaborator

@nullifiedtsk this PR needs to be rebased

@benmccann benmccann changed the title added allowZoom pre-condition to filter out unnessecary zoom events added allowZoom pre-condition to filter out unnecessary zoom events Nov 21, 2020
@kurkle
Copy link
Member

kurkle commented May 1, 2021

Closing in favor of #487

@kurkle kurkle closed this May 1, 2021
@mavoi09
Copy link

mavoi09 commented Feb 24, 2022

Can we have this fix for version 0.7.7? Some users can't upgrade to later versions (IE issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants