-
Notifications
You must be signed in to change notification settings - Fork 30
fix: bubble chart crash on window resize with named series in manual config #1267
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
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,12 +31,17 @@ var isResizeRequest = false; | |
| // remember, some charts do not support annotations so they should not be included in this. | ||
| var no_annotation_charts = ['tabular', 'timeline', 'gauge', 'geo', 'bubble', 'candlestick']; | ||
| if ( undefined !== chart.settings && undefined !== chart.settings.series && undefined === chart.settings.series.length ) { | ||
| var chartSeries = []; | ||
| var chartSeriesValue = Object.values( chart.settings.series ); | ||
| $.each( Object.keys( chart.settings.series ), function( index, element ) { | ||
| chartSeries[element] = chartSeriesValue[index]; | ||
| } ); | ||
| chart.settings.series = chartSeries; | ||
| var seriesKeys = Object.keys( chart.settings.series ); | ||
| // Only convert when keys are numeric indices (PHP JSON-encoded array). | ||
| // String keys (e.g. named series from manual config) must be left as-is. | ||
| if ( seriesKeys.every( function( k ) { return ! isNaN( k ); } ) ) { | ||
| var chartSeries = []; | ||
| var chartSeriesValue = Object.values( chart.settings.series ); | ||
| $.each( seriesKeys, function( index, element ) { | ||
| chartSeries[ element ] = chartSeriesValue[ index ]; | ||
| } ); | ||
| chart.settings.series = chartSeries; | ||
| } | ||
|
Comment on lines
33
to
+44
|
||
| } | ||
| if(id !== 'canvas' && typeof chart.series !== 'undefined' && typeof chart.settings.series !== 'undefined' && ! no_annotation_charts.includes(chart.type) ) { | ||
| hasAnnotation = chart.series.length - chart.settings.series.length > 1; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The numeric-key detection uses
! isNaN( k ), butisNaNperforms coercion and will treat values like'1.5','1e2','', or'00'as “numeric”. Some of these are not valid array indices in JS (e.g.'1.5'/'00'become non-index properties), which can recreate the same sparse/length=0 behavior this change is trying to prevent. Consider using a stricter check for non-negative integer indices (e.g./^(0|[1-9]\d*)$/orNumber.isInteger( Number(k) ) && String( Number(k) ) === k) and optionally castingelementto a number when assigning intochartSeries.