Skip to content
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

Apply render optimizations when animation duration is 0 #11977

Open
alex-statsig opened this issue Dec 15, 2024 · 3 comments
Open

Apply render optimizations when animation duration is 0 #11977

alex-statsig opened this issue Dec 15, 2024 · 3 comments

Comments

@alex-statsig
Copy link

Feature Proposal

My goal is to allow the same performance optimization that are applied when animations are disabled (i.e. with options.animation = false) or when using mode="none" (i.e. chart.update('none')) to animations with a duration of 0 (i.e. options.animation.duration = 0).

Example context

Sometimes its desirable to only enable animations for certain situations. For example, you may want to generally disable most animations upon updates, but keep around animations for things like zooming (where the animation is more important to preserve context). As suggested in the docs, you can accomplish this with a setup like this:

const options = {
  animations: { duration: 0 },
  transitions: { zoom: { duration: 500 } },
}

Note that you cannot set options.animations = false or else all animations are disabled (including zoom).

In this situation, any chart update with a mode other than 'zoom' can equivalently run with mode='none' since the animations are disabled via duration=0. However, currently chartjs will still use the animation-based render, preventing certain performance optimizations in updaters (such as dataset direct update and line controller direct update). These performance optimizations can significantly speed up renders for large datasets (ex. 200ms -> 30ms).

Possible Implementation

One options could be to detect in chart.update() if an update mode effectively has its animations disabled (via duration=0). In this event, mode could automatically be remapped to 'none' so downstream updates don't need to change their logic (ex. dataset and line controller both already support optimizing mode='none').

@alex-statsig
Copy link
Author

@LeeLenaleee I saw you were contributing more actively to chartjs lately if you have any thoughts here. I'd be happy to help contribute for this improvement, but would like some guidance / validation

@LeeLenaleee
Copy link
Collaborator

It sounds like a good idea, but I don't know this part well enough to help you any further on it.

@etimberg
Copy link
Member

etimberg commented Jan 8, 2025

@alex-statsig it might be as simple as updating https://github.com/chartjs/Chart.js/blob/master/src/core/core.controller.js#L498 but it would require some testing for sure

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

No branches or pull requests

3 participants