Fix treemap select action collision when node names are duplicated (Fixes issue #21480)#21481
Conversation
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
Ovilia
left a comment
There was a problem hiding this comment.
The issue #21480 is considered not-a-bug so I'm afraid I have to close this PR. Please check #21480 (comment) for more information.
Thanks for your contribution anyway!
And please don't include the changes under dist next time.
|
|
||
| function getSelectionKey(data: SeriesData, dataIndex: number): string { | ||
| return data.getName(dataIndex) || data.getId(dataIndex); | ||
| return data.getId(dataIndex); |
There was a problem hiding this comment.
I'm afraid this fixing is not correct. In ECharts, series/items with the same name are intentionally considered as the same.
| dataIndex: 3 | ||
| }); | ||
| console.log('selectedMap:', chart.getOption().series[0].selectedMap); | ||
| console.log('selectedIndices:', chart.getModel().getSeriesByIndex(0).getSelectedDataIndices()); |
There was a problem hiding this comment.
The expected result of this example should be all those four data being selected.
Brief Information
This pull request is in the type of:
What does this PR do?
Fixes treemap
dispatchAction({ type: 'select', dataIndex })so that selection targets a single node even when multiple nodes share the same name.Fixed issues
Details
Before: What was the problem?
When using
dispatchAction({ type: 'select', dataIndex })on a treemap that contains multiple nodes with the samenameand no explicitid, the selection logic could select multiple nodes or behave inconsistently.This happened because the internal selection state (
selectedMap) was keyed by nodenamefirst, causing key collisions when names were duplicated.After: How does it behave after the fixing?
Selection is now keyed by
data.getId(dataIndex), which is guaranteed to be unique.As a result:
dispatchAction({ type: 'select', dataIndex })deterministically selects only the intended treemap nodeA minimal reproduction case (
test/treemap-select-21480.html) confirms that only the targeted node is selected.Document Info
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
N.A.
Merging options
Other information
N/A