-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[BUG] Browser crashes with "type: 'time'" for Y axis while hidden #5029
Comments
This bug is caused in part by the ChartJS layoutservice, which doesn't sanitize sizes to be positive. Unfortunately in the case of a time axis this negative value bubbles through Chart.js/src/scales/scale.time.js Line 243 in 6f34b22
// possible fix
capacity = (capacity && capacity > 0) ? capacity : 1; // guarantee capacity is positive
return Math.ceil(range / (capacity * milliseconds)); Edit: added link to current code. |
@etimberg or would it be better/preferred to make the sanity check inside the Chart.js/src/scales/scale.time.js Line 751 in 6f34b22
var capacity = Math.floor(innerWidth / tickLabelWidth);
return (capacity && capacity > 0) ? capacity : 1; Edit: Chart.js/src/scales/scale.time.js Lines 320 to 322 in 6f34b22
if (stepSize <= 0) {
stepSize = 1;
} |
@jcopperfield I wonder how hard it is to sanitize the size to not be negative in the layout service. That would prevent other potential issues in the future |
@etimberg I agree that having the layout service take care of this would be best, however it seems that the |
Another possibility would be to skip the tick creation loop if the Chart.js/src/scales/scale.time.js Lines 349 to 351 in 6f34b22
if (stepSize > 0) {
for (; time < last; time.add(stepSize, minor)) {
ticks.push(+time);
}
} |
I agree that the label capacity should always be positive so I would recommend that as the solution for the time scale |
- infinite loop in generating time axis, due to insufficient bounds checking.
- infinite loop in generating time axis, due to insufficient bounds checking.
- infinite loop in generating time axis, due to insufficient bounds checking.
The browser freezes/crashes in this minimal test case (uncomment the indicated line to try it):
https://jsfiddle.net/aLk05ptk/10/
This is using 2.7.1.
From what testing I could do so far, the problem does not happen if the canvas is visible initially, nor when the axis type is "linear", nor when only the X axis is "time".
The text was updated successfully, but these errors were encountered: