-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(Chart): keep hidden of data value when update #878
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
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -356,7 +356,6 @@ const getChartOption = function (option) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // pie 图除外默认显示 网格线与坐标系 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (option.type !== 'pie' && option.type !== 'doughnut') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (option.options.showXScales === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scale.x.display = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -491,7 +490,13 @@ export function init(id, invoke, method, option) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function update(id, option, method, angle) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { invoke, chart } = Data.get(id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { invoke, chart } = Data.get(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| option.data.forEach(d => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const l = chart.legend.legendItems.find(i => i.text === d.label); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(l) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+494
to
+496
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| option.data.forEach(d => { | |
| const l = chart.legend.legendItems.find(i => i.text === d.label); | |
| if(l) { | |
| const legendItems = chart && chart.legend && Array.isArray(chart.legend.legendItems) | |
| ? chart.legend.legendItems | |
| : []; | |
| const legendItemMap = new Map(); | |
| legendItems.forEach(item => { | |
| legendItemMap.set(item.text, item); | |
| }); | |
| option.data.forEach(d => { | |
| const l = legendItemMap.get(d.label); | |
| if (l) { |
Copilot
AI
Dec 30, 2025
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 code assumes option.data is iterable but doesn't check for null/undefined. If option.data is null or undefined, this will throw a runtime error. Add a defensive check to ensure option.data exists before calling forEach.
| option.data.forEach(d => { | |
| const l = chart.legend.legendItems.find(i => i.text === d.label); | |
| if(l) { | |
| d.hidden = l.hidden; | |
| } | |
| }); | |
| if (Array.isArray(option.data)) { | |
| option.data.forEach(d => { | |
| const l = chart.legend.legendItems.find(i => i.text === d.label); | |
| if (l) { | |
| d.hidden = l.hidden; | |
| } | |
| }); | |
| } |
Copilot
AI
Dec 30, 2025
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 code lacks proper null/undefined safety checks. If chart.legend is null/undefined or chart.legend.legendItems is null/undefined, this code will throw a runtime error. This can happen when the legend is disabled (showLegend: false) or in certain chart configurations. Add defensive checks to ensure these properties exist before attempting to access them.
| option.data.forEach(d => { | |
| const l = chart.legend.legendItems.find(i => i.text === d.label); | |
| if(l) { | |
| d.hidden = l.hidden; | |
| } | |
| }); | |
| const legendItems = chart && chart.legend && chart.legend.legendItems; | |
| if (Array.isArray(option.data) && Array.isArray(legendItems)) { | |
| option.data.forEach(d => { | |
| const l = legendItems.find(i => i.text === d.label); | |
| if (l) { | |
| d.hidden = l.hidden; | |
| } | |
| }); | |
| } |
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.
Missing space after 'if' keyword. JavaScript convention and most style guides recommend a space between 'if' and the opening parenthesis for better readability.