You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/07/16 05:44:06 UTC
[echarts] branch master updated: fix: root node related edge not
removed when update data
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts.git
The following commit(s) were added to refs/heads/master by this push:
new 67a49bc fix: root node related edge not removed when update data
new db6a91a Merge pull request #15251 from ssthouse/fix/tree-unexpected-edges
67a49bc is described below
commit 67a49bc0008609fe908aa8b2cf8688544143008f
Author: timshen <ti...@tencent.com>
AuthorDate: Mon Jun 28 16:34:30 2021 +0800
fix: root node related edge not removed when update data
---
src/chart/tree/TreeView.ts | 97 ++++++++++++++++++++++++++++++----------------
test/tree-basic.html | 6 +--
2 files changed, 67 insertions(+), 36 deletions(-)
diff --git a/src/chart/tree/TreeView.ts b/src/chart/tree/TreeView.ts
index bcc8be8..5c7941c 100644
--- a/src/chart/tree/TreeView.ts
+++ b/src/chart/tree/TreeView.ts
@@ -36,7 +36,7 @@ import ExtensionAPI from '../../core/ExtensionAPI';
import { TreeNode } from '../../data/Tree';
import List from '../../data/List';
import { setStatesStylesFromModel, setStatesFlag, setDefaultStateProxy, HOVER_STATE_BLUR } from '../../util/states';
-import { ECElement } from '../../util/types';
+import { AnimationOption, ECElement } from '../../util/types';
type TreeSymbol = SymbolClz & {
__edge: graphic.BezierCurve | TreePath
@@ -595,44 +595,21 @@ function drawEdge(
}
}
-function removeNode(
+function removeNodeEdge(
+ node: TreeNode,
data: List,
- dataIndex: number,
- symbolEl: TreeSymbol,
group: graphic.Group,
- seriesModel: TreeSeriesModel
+ seriesModel: TreeSeriesModel,
+ removeAnimationOpt: AnimationOption
) {
- const node = data.tree.getNodeByDataIndex(dataIndex);
const virtualRoot = data.tree.root;
+ const { source, sourceLayout } = getSourceNode(virtualRoot, node);
- let source = node.parentNode === virtualRoot ? node : node.parentNode || node;
- // let edgeShape = seriesScope.edgeShape;
- let sourceLayout;
- while (sourceLayout = source.getLayout(), sourceLayout == null) {
- source = source.parentNode === virtualRoot ? source : source.parentNode || source;
- }
-
- // Use same duration and easing with update to have more consistent animation.
- const removeAnimationOpt = {
- duration: seriesModel.get('animationDurationUpdate') as number,
- easing: seriesModel.get('animationEasingUpdate')
- };
-
- graphic.removeElement(symbolEl, {
- x: sourceLayout.x + 1,
- y: sourceLayout.y + 1
- }, seriesModel, {
- cb() {
- group.remove(symbolEl);
- data.setItemGraphicEl(dataIndex, null);
- },
- removeOpt: removeAnimationOpt
- });
+ const symbolEl: TreeSymbol = data.getItemGraphicEl(node.dataIndex) as TreeSymbol;
- symbolEl.fadeOut(null, {
- fadeLabel: true,
- animation: removeAnimationOpt
- });
+ if (!symbolEl) {
+ return;
+ }
const sourceSymbolEl = data.getItemGraphicEl(source.dataIndex) as TreeSymbol;
const sourceEdge = sourceSymbolEl.__edge;
@@ -688,6 +665,60 @@ function removeNode(
}
}
+function getSourceNode(virtualRoot: TreeNode, node: TreeNode): { source: TreeNode, sourceLayout: TreeNodeLayout } {
+ let source = node.parentNode === virtualRoot ? node : node.parentNode || node;
+ let sourceLayout;
+ while (sourceLayout = source.getLayout(), sourceLayout == null) {
+ source = source.parentNode === virtualRoot ? source : source.parentNode || source;
+ }
+ return {
+ source,
+ sourceLayout
+ };
+}
+
+function removeNode(
+ data: List,
+ dataIndex: number,
+ symbolEl: TreeSymbol,
+ group: graphic.Group,
+ seriesModel: TreeSeriesModel
+) {
+ const node = data.tree.getNodeByDataIndex(dataIndex);
+ const virtualRoot = data.tree.root;
+
+ const { sourceLayout } = getSourceNode(virtualRoot, node);
+
+ // Use same duration and easing with update to have more consistent animation.
+ const removeAnimationOpt = {
+ duration: seriesModel.get('animationDurationUpdate') as number,
+ easing: seriesModel.get('animationEasingUpdate')
+ };
+
+ graphic.removeElement(symbolEl, {
+ x: sourceLayout.x + 1,
+ y: sourceLayout.y + 1
+ }, seriesModel, {
+ cb() {
+ group.remove(symbolEl);
+ data.setItemGraphicEl(dataIndex, null);
+ },
+ removeOpt: removeAnimationOpt
+ });
+
+ symbolEl.fadeOut(null, {
+ fadeLabel: true,
+ animation: removeAnimationOpt
+ });
+
+ // remove edge as parent node
+ node.children.forEach(childNode => {
+ removeNodeEdge(childNode, data, group, seriesModel, removeAnimationOpt);
+ });
+ // remove edge as child node
+ removeNodeEdge(node, data, group, seriesModel, removeAnimationOpt);
+}
+
function getEdgeShape(
layoutOpt: TreeSeriesOption['layout'],
orient: TreeSeriesOption['orient'],
diff --git a/test/tree-basic.html b/test/tree-basic.html
index 07bd697..a9ea9ff 100644
--- a/test/tree-basic.html
+++ b/test/tree-basic.html
@@ -114,13 +114,13 @@ under the License.
});
setTimeout(function() {
- var newData = echarts.util.clone(data);
- newData.children.splice(0, 1);
+ // replace root node
+ var newData = [data.children[1]];
chart.setOption({
series: [{
type: 'tree',
id: '3',
- data: [newData]
+ data: newData
}]
}, false);
}, 1000);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org