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

[FEATURE] Intersect frequency option for performance improvement #3757

Closed
skogar42 opened this issue Jan 3, 2017 · 5 comments
Closed

[FEATURE] Intersect frequency option for performance improvement #3757

skogar42 opened this issue Jan 3, 2017 · 5 comments

Comments

@skogar42
Copy link

skogar42 commented Jan 3, 2017

Context

I have a line chart that displays a hiking elevation profile with many points. For the tooltip, I am using mode = "x" and intersect = "false". I am experiencing high CPU utilization when I move the mouse around constantly.

Expected Behavior

It would be nice to have a frequency option that can throttle how often the mouseover gets processed.

Possible Solution

One possible way to implement this is to have a timer set to the frequency that sets an okToUpdate flag. Whenever the mouseover happens, check if it is okToUpdate, otherwise ignore the mouseover. I'm not familiar with the design enough to know which object is the best place to add the option.

I would be willing to work on this if someone could give me some pointers on where in the source would be the best place to add this.

Environment

  • Chart.js version: 2.4.0
  • Browser name and version: Chrome 49.0.2623.110 (64-bit)
  • Link to your project: Here is an example of the elevation graph towards the bottom of the page
@etimberg
Copy link
Member

etimberg commented Jan 3, 2017

@skogar42 one option is the timer but I don't think that should live in the core. The main event handler is https://github.com/chartjs/Chart.js/blob/master/src/core/core.controller.js#L609

@skogar42
Copy link
Author

skogar42 commented Jan 4, 2017

Another possibility could be store the last processed timestamp, and only update if the current timestamp exceeds the last timestamp + frequency period. Could this fit somewhere in tooltip.handleEvent()?

@etimberg
Copy link
Member

etimberg commented Jan 4, 2017

@skogar42 yes, that could fit in there. I like it since it avoids the timer (which causes battery life issues and generally means something else is wrong architecturally).

Another option is to throttle in a way similar to how resize events are throttled: https://github.com/chartjs/Chart.js/blob/master/src/core/core.helpers.js#L972

What I would do here would be:

  1. refactor the throttling code in the helpers.addResizeListener function to be more common so that it can be re-used
  2. use that refactored code inside handleEvent.

I think you might want to skip the throttling if the event type changes.
ie, if you have a mousemove and a click, do not throttle the click because the move just happened.

But if you had 4 quick events in the order: mousemove, mousemove, mousemove, click I would expect that the chart handles 1 mousemove and 1 click. Does that make sense?

@skogar42
Copy link
Author

skogar42 commented Jan 5, 2017

Thanks for the suggestion! I'll take a closer look at the resize listener and see what I can do.

@kurkle
Copy link
Member

kurkle commented Jan 14, 2020

Done in #6953

@kurkle kurkle closed this as completed Jan 14, 2020
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

4 participants