fix(DatasetController): skip hidden datasets to improve performance by WAGHMARETANNU · Pull Request #12183 · chartjs/Chart.js
Summary
This PR addresses issue #12179: "Charts with a large number of hidden datasets perform poorly".
When many datasets are present and most are hidden, Chart.js was still performing expensive parsing, stacking, and min/max calculations for hidden datasets. This caused noticeable lag in scenarios like time-tracking charts with 50+ datasets.
Changes
_resyncElementsnow skips processing for datasets wheremeta.hidden === true.getMinMaxreturns{ min: Infinity, max: -Infinity }for hidden datasets, avoiding unnecessary calculations.- Minor refactoring to ensure that hidden datasets do not affect stacks or parsing loops.
Benefits
- Significant performance improvement for charts with many datasets where only a subset is visible.
- Reduces CPU usage and lag in common use cases such as toggling dataset visibility.
- Maintains correct functionality for visible datasets and stacked charts.
Test
- Verified charts with multiple hidden datasets no longer experience lag on updates.
- All existing unit tests pass, and no visual regressions observed.
Issue
Closes #12179