100pah commented on code in PR #17349:
URL: https://github.com/apache/echarts/pull/17349#discussion_r921362146
##########
src/chart/custom/CustomView.ts:
##########
@@ -1316,24 +1322,43 @@ function mergeChildren(
// might be better performance.
let index = 0;
for (; index < newLen; index++) {
- newChildren[index] && doCreateOrUpdateEl(
- api,
- el.childAt(index),
- dataIndex,
- newChildren[index] as CustomElementOption,
- seriesModel,
- el
- );
+ const newChild = newChildren[index];
+ const oldChild = el.childAt(index);
+ if (newChild) {
+ doCreateOrUpdateEl(
+ api,
+ oldChild,
+ dataIndex,
+ newChild as CustomElementOption,
+ seriesModel,
+ el
+ );
+ }
+ else {
+ removeChildFromGroup(el, oldChild, seriesModel);
Review Comment:
After adding `oldRemovedCount` the effect is better but still has some
issues:
## Consider the case below:
+ step 1. `setOption` with new children: `[elA, elB, elC]` (length: 3)
+ step 2. `setOption` with new children: `[elA, null, elC]` (length: 3)
(means hide `elB`)
+ step 3. `setOption` with new children: `[elA, elB, elC]` (length: 3)
(means show `elB` again)
But with current modified code, the result will be:
+ After step 1. children will be `[elA, elB, elC]`
+ After step 2. children will be `[elA, elC]`
+ After step 3. children will be `[elA, merge(elC, elB), elC]`
which is unexpected.
## Consider leave animation
If the `setOption` is triggered by user's repeat click, the interval between
two clicks is not predicable, may be longer or shorter than the leave animation
duration. In this case, if the indices of some children is different before and
after leave animation, the merge result will be not predicable.
---
Basically, if we use `null/undefined` to delete a child, I think this
principle should be applied:
> The index of any other element should not be changed after this deletion
That is, is we delete a child, that place may be kept "no element" or "an
placeholder element that can not displayed"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]