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/06/19 15:29:58 UTC
[echarts] branch enhance-morph updated: feat(ut): use id as key if
two data has same length.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch enhance-morph
in repository https://gitbox.apache.org/repos/asf/echarts.git
The following commit(s) were added to refs/heads/enhance-morph by this push:
new 5a813c7 feat(ut): use id as key if two data has same length.
5a813c7 is described below
commit 5a813c7be4b1931a81e9242989384a5c741c025d
Author: pissang <bm...@gmail.com>
AuthorDate: Sat Jun 19 23:28:42 2021 +0800
feat(ut): use id as key if two data has same length.
It's most likely to be one to one animation
---
src/animation/morphTransitionHelper.ts | 5 ++++-
src/animation/universalTransition.ts | 17 +++++++++++++----
test/universalTransition2.html | 13 +++++++------
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/src/animation/morphTransitionHelper.ts b/src/animation/morphTransitionHelper.ts
index 0d08ca3..fb1eb5f 100644
--- a/src/animation/morphTransitionHelper.ts
+++ b/src/animation/morphTransitionHelper.ts
@@ -94,7 +94,10 @@ const pathDividers: Record<SeriesOption['universalTransition']['divideShape'], D
clone(params) {
const ret: Path[] = [];
for (let i = 0; i < params.count; i++) {
- ret.push(clonePath(params.path));
+ const cloned = clonePath(params.path);
+ // const opacity = params.path.style.opacity;
+ // cloned.setStyle('opacity', opacity / params.count);
+ ret.push(cloned);
}
return ret;
},
diff --git a/src/animation/universalTransition.ts b/src/animation/universalTransition.ts
index 8ac392a..c455a93 100644
--- a/src/animation/universalTransition.ts
+++ b/src/animation/universalTransition.ts
@@ -161,11 +161,15 @@ function transitionBetween(
let hasMorphAnimation = false;
- function createKeyGetter(isOld: boolean) {
+ function createKeyGetter(isOld: boolean, onlyGetId: boolean) {
return function (diffItem: DiffItem): string {
const data = diffItem.data;
const dataIndex = diffItem.dataIndex;
+ if (onlyGetId) {
+ return data.getId(dataIndex);
+ }
+
// Use group id as transition key by default.
// So we can achieve multiple to multiple animation like drilldown / up naturally.
// If group id not exits. Use id instead. If so, only one to one transition will be applied.
@@ -205,6 +209,8 @@ function transitionBetween(
const newSeries = newItem.data.hostModel as SeriesModel;
+ // TODO some elements in new data is shared with the old elements
+ // And already being morphed.
const oldEl = oldItem.data.getItemGraphicEl(oldItem.dataIndex);
const newEl = newItem.data.getItemGraphicEl(newItem.dataIndex);
@@ -213,7 +219,6 @@ function transitionBetween(
return;
}
-
if (newEl) {
// TODO: If keep animating the group in case
// some of the elements don't want to be morphed.
@@ -242,11 +247,14 @@ function transitionBetween(
// else keep oldEl leaving animation.
}
+ // Use id if it's very likely to be an one to one animation
+ // It's more robust than groupId
+ const useId = oldDiffItems.length === newDiffItems.length;
(new DataDiffer(
oldDiffItems,
newDiffItems,
- createKeyGetter(true),
- createKeyGetter(false),
+ createKeyGetter(true, useId),
+ createKeyGetter(false, useId),
null,
'multiple'
))
@@ -281,6 +289,7 @@ function transitionBetween(
newIndex,
updateMorphingPathProps
);
+
}
else {
fadeInElement(newEl, newSeries, newItem.dataIndex);
diff --git a/test/universalTransition2.html b/test/universalTransition2.html
index 78a1ac3..8ccb7dc 100644
--- a/test/universalTransition2.html
+++ b/test/universalTransition2.html
@@ -177,7 +177,6 @@ under the License.
fromDatasetId: 'raw_dataset',
transform: {
type: 'ecStat:clustering',
- print: true,
config: {
clusterCount: 4,
dimensions: ['COUNT', 'PRICE'],
@@ -199,7 +198,6 @@ under the License.
fromDatasetId: 'raw_clustered_dataset',
transform: {
type: 'ecSimpleTransform:aggregate',
- print: true,
config: {
resultDimensions: [
{ from: 'COUNT', method: 'count' },
@@ -225,7 +223,7 @@ under the License.
id: 'main',
animationDurationUpdate: 1000,
datasetId: 'raw_clustered_dataset',
- symbolSize: 10,
+ symbolSize: 20,
encode: {
itemName: 'ID',
x: 'PRICE',
@@ -256,11 +254,12 @@ under the License.
encode: {
x: 'CLUSTER_CENTER_PRICE',
y: 'CLUSTER_CENTER_COUNT',
+ itemGroupId: 'CLUSTER_IDX',
tooltip: ['CLUSTER_CENTER_PRICE', 'CLUSTER_CENTER_COUNT']
},
universalTransition: {
enabled: true,
- // divideShape: 'clone'
+ divideShape: 'clone'
}
}
}
@@ -275,12 +274,12 @@ under the License.
buttons: [{
text: 'All',
onclick: function () {
- chart.setOption(rawScatterOption, true);
+ chart.setOption(rawScatterOption);
}
}, {
text: 'Clustered',
onclick: function () {
- chart.setOption(clusteredScatterOption, true);
+ chart.setOption(clusteredScatterOption);
}
}],
});
@@ -402,6 +401,7 @@ under the License.
id: 'CountryA',
datasetId: 'CountryAData',
stack,
+ symbol: 'circle',
universalTransition: {
enabled: true
},
@@ -416,6 +416,7 @@ under the License.
id: 'CountryB',
datasetId: 'CountryBData',
stack,
+ symbol: 'circle',
universalTransition: {
enabled: true
},
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org