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/06 12:35:51 UTC
[echarts] branch master updated: more precise when determine if
using id as key in universal transition (#15303)
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 3f9932e more precise when determine if using id as key in universal transition (#15303)
3f9932e is described below
commit 3f9932e5c4855772aa25b3b9497db7a55e31bedf
Author: Yi Shen <bm...@gmail.com>
AuthorDate: Tue Jul 6 20:35:40 2021 +0800
more precise when determine if using id as key in universal transition (#15303)
* fix(ut): more precise when determine if using id as key
* test: optimize test cases for universal transition
---
src/animation/universalTransition.ts | 17 ++++++++++++++++-
src/model/Series.ts | 1 +
test/runTest/actions/universalTransition2.json | 2 +-
test/universalTransition2.html | 24 +++++++++++++++++-------
4 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/src/animation/universalTransition.ts b/src/animation/universalTransition.ts
index 53bf2da..140afca 100644
--- a/src/animation/universalTransition.ts
+++ b/src/animation/universalTransition.ts
@@ -142,6 +142,21 @@ function animateElementStyles(el: Element, dataIndex: number, seriesModel: Serie
}
+function isAllIdSame(oldDiffItems: DiffItem[], newDiffItems: DiffItem[]) {
+ const len = oldDiffItems.length;
+ if (len !== newDiffItems.length) {
+ return false;
+ }
+ for (let i = 0; i < len; i++) {
+ const oldItem = oldDiffItems[i];
+ const newItem = newDiffItems[i];
+ if (oldItem.data.getId(oldItem.dataIndex) !== newItem.data.getId(newItem.dataIndex)) {
+ return false;
+ }
+ }
+ return true;
+}
+
function transitionBetween(
oldList: TransitionSeries[],
newList: TransitionSeries[],
@@ -220,7 +235,7 @@ function transitionBetween(
// Use id if it's very likely to be an one to one animation
// It's more robust than groupId
// TODO Check if key dimension is specified.
- const useId = oldDiffItems.length === newDiffItems.length;
+ const useId = isAllIdSame(oldDiffItems, newDiffItems);
const isElementStillInChart: Dictionary<boolean> = {};
if (!useId) {
diff --git a/src/model/Series.ts b/src/model/Series.ts
index 1972ca7..9ee54c8 100644
--- a/src/model/Series.ts
+++ b/src/model/Series.ts
@@ -541,6 +541,7 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode
return true;
}
+ // NOTE: don't support define universalTransition in global option yet.
const universalTransitionOpt = this.option.universalTransition;
// Quick reject
if (!universalTransitionOpt) {
diff --git a/test/runTest/actions/universalTransition2.json b/test/runTest/actions/universalTransition2.json
index cdc7262..9e746cd 100644
--- a/test/runTest/actions/universalTransition2.json
+++ b/test/runTest/actions/universalTransition2.json
@@ -1 +1 @@
-[{"name":"Action 1","ops":[{"type":"mousedown","time":472,"x":221,"y":267},{"type":"mouseup","time":561,"x":221,"y":267},{"time":562,"delay":100,"type":"screenshot-auto"},{"type":"mousemove","time":1020,"x":220,"y":266},{"type":"mousemove","time":1220,"x":72,"y":121},{"type":"mousemove","time":1420,"x":65,"y":106},{"type":"mousemove","time":1625,"x":68,"y":90},{"type":"mousemove","time":1855,"x":68,"y":90},{"type":"mousedown","time":2046,"x":68,"y":90},{"type":"mouseup","time":2124,"x":6 [...]
\ No newline at end of file
+[{"name":"Action 1","ops":[{"type":"mousedown","time":442,"x":233,"y":291},{"type":"mouseup","time":541,"x":233,"y":291},{"time":542,"delay":100,"type":"screenshot-auto"},{"type":"mousemove","time":796,"x":232,"y":291},{"type":"mousemove","time":1001,"x":113,"y":115},{"type":"mousemove","time":1212,"x":99,"y":92},{"type":"mousemove","time":1412,"x":93,"y":92},{"type":"mousemove","time":1615,"x":87,"y":91},{"type":"mousedown","time":1824,"x":83,"y":90},{"type":"mousemove","time":1834,"x": [...]
\ No newline at end of file
diff --git a/test/universalTransition2.html b/test/universalTransition2.html
index 860ce29..ef3a998 100644
--- a/test/universalTransition2.html
+++ b/test/universalTransition2.html
@@ -149,9 +149,13 @@ under the License.
fontSize: 18
},
onclick() {
- chart.setOption(option);
+ chart.setOption(option, {
+ replaceMerge: ['xAxis', 'yAxis']
+ });
}
}]
+ }, {
+ replaceMerge: ['xAxis', 'yAxis']
});
}
});
@@ -416,21 +420,27 @@ under the License.
yAxis: {
scale: true
},
- universalTransition: {
- enabled: true,
- delay(idx, count) {
- return (idx / count) * 1000;
- }
- },
series: [{
type: 'scatter',
id: 'female',
dataGroupId: 'female',
+ universalTransition: {
+ enabled: true,
+ delay(idx, count) {
+ return (idx / count) * 1000;
+ }
+ },
data: femaleData
}, {
type: 'scatter',
id: 'male',
dataGroupId: 'male',
+ universalTransition: {
+ enabled: true,
+ delay(idx, count) {
+ return (idx / count) * 1000;
+ }
+ },
data: maleDeta
}]
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org