You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2018/06/19 19:51:24 UTC
[incubator-echarts] branch master updated: [custom series] Support
invisible, ignore and merge children options.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/master by this push:
new 426fb39 [custom series] Support invisible, ignore and merge children options.
426fb39 is described below
commit 426fb392a6921b726e8bad32fe30e97f1bc8d273
Author: sushuang <su...@gmail.com>
AuthorDate: Wed Jun 20 03:50:59 2018 +0800
[custom series] Support invisible, ignore and merge children options.
---
src/chart/custom.js | 110 +++++++++++++++++++++++++--------------
test/custom-children-remove.html | 2 +-
test/custom.html | 2 +-
3 files changed, 72 insertions(+), 42 deletions(-)
diff --git a/src/chart/custom.js b/src/chart/custom.js
index 148f529..b665903 100644
--- a/src/chart/custom.js
+++ b/src/chart/custom.js
@@ -270,7 +270,12 @@ function updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot
}
// z2 must not be null/undefined, otherwise sort error may occur.
- el.attr({z2: elOption.z2 || 0, silent: elOption.silent});
+ el.attr({
+ z2: elOption.z2 || 0,
+ silent: elOption.silent,
+ invisible: elOption.invisible,
+ ignore: elOption.ignore
+ });
// If `elOption.styleEmphasis` is `false`, remove hover style. The
// logic is ensured by `graphicUtil.setElementHoverStyle`.
@@ -544,45 +549,8 @@ function doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data,
!el && (el = createEl(elOption));
updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot);
- // If `renderItem` returns no children, follow the principle of
- // "merge", remain the children of the original elements
- // (if exists). The feature can help optimization when roam and
- // data zoom. If intending to clear children, `renderItem` could
- // returns an empty array as children.
- var newChildren = elOption.children;
- if (elOptionType === 'group' && newChildren) {
- var oldChildren = el.children() || [];
-
- // By default, do not diff elements by name inside a
- // group, because that might be lower performance.
- if (elOption.diffChildrenByName) {
- diffGroupChildren({
- oldChildren: oldChildren,
- newChildren: newChildren,
- dataIndex: dataIndex,
- animatableModel: animatableModel,
- group: el,
- data: data
- });
- }
- // Mapping children of a group simply by index, which
- // might be better performance.
- else {
- var index = 0;
- for (; index < newChildren.length; index++) {
- doCreateOrUpdate(
- el.childAt(index),
- dataIndex,
- newChildren[index],
- animatableModel,
- el,
- data
- );
- }
- for (; index < oldChildren.length; index++) {
- oldChildren[index] && el.remove(oldChildren[index]);
- }
- }
+ if (elOptionType === 'group') {
+ mergeChildren(el, dataIndex, elOption, animatableModel, data);
}
// Always add whatever already added to ensure sequence.
@@ -591,6 +559,68 @@ function doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data,
return el;
}
+// Usage:
+// (1) By default, `elOption.$mergeChildren` is `'byIndex'`, which indicates that
+// the existing children will not be removed, and enables the feature that
+// update some of the props of some of the children simply by construct
+// the returned children of `renderItem` like:
+// `var children = group.children = []; children[3] = {opacity: 0.5};`
+// (2) If `elOption.$mergeChildren` is `'byName'`, add/update/remove children
+// by child.name. But that might be lower performance.
+// (3) If `elOption.$mergeChildren` is `false`, the existing children will be
+// replaced totally.
+// For implementation simpleness, do not provide a direct way to remove sinlge
+// child (otherwise the total indicies of the children array have to be modified).
+// User can remove a single child by set its `ignore` as `true` or replace
+// it by another element, where its `$merge` can be set as `true` if necessary.
+function mergeChildren(el, dataIndex, elOption, animatableModel, data) {
+ var newChildren = elOption.children;
+ var newLen = newChildren ? newChildren.length : 0;
+ var mergeChildren = elOption.$mergeChildren;
+ // `diffChildrenByName` has been deprecated.
+ var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
+ var notMerge = mergeChildren === false;
+
+ // For better performance on roam update, only enter if necessary.
+ if (!newChildren.length && !byName && !notMerge) {
+ return;
+ }
+
+ if (byName) {
+ diffGroupChildren({
+ oldChildren: el.children() || [],
+ newChildren: newChildren || [],
+ dataIndex: dataIndex,
+ animatableModel: animatableModel,
+ group: el,
+ data: data
+ });
+ return;
+ }
+
+ notMerge && el.removeAll();
+
+ // Mapping children of a group simply by index, which
+ // might be better performance.
+ var index = 0;
+ for (; index < newLen; index++) {
+ newChildren[index] && doCreateOrUpdate(
+ el.childAt(index),
+ dataIndex,
+ newChildren[index],
+ animatableModel,
+ el,
+ data
+ );
+ }
+ if (__DEV__) {
+ zrUtil.assert(
+ !notMerge || el.childCount() === index,
+ 'MUST NOT contain empty item in children array when `group.$mergeChildren` is `false`.'
+ );
+ }
+}
+
function diffGroupChildren(context) {
(new DataDiffer(
context.oldChildren,
diff --git a/test/custom-children-remove.html b/test/custom-children-remove.html
index 4b3d029..20eedd1 100644
--- a/test/custom-children-remove.html
+++ b/test/custom-children-remove.html
@@ -152,7 +152,7 @@ under the License.
return {
type: 'group',
- diffChildrenByName: true,
+ $mergeChildren: 'byName',
children: nameTexts
};
}
diff --git a/test/custom.html b/test/custom.html
index d25ed6c..d0f8074 100644
--- a/test/custom.html
+++ b/test/custom.html
@@ -1404,7 +1404,7 @@ under the License.
return {
type: 'group',
- diffChildrenByName: true,
+ $mergeChildren: 'byName',
children: nameTexts
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org