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 069b69295 fix: incorrect dataGroupId for old data items in 
universalTransition (#17559)
069b69295 is described below

commit 069b69295e3a65e16d9d2fbdef86a8d3bfc8023a
Author: Lam Tang <tangye...@gmail.com>
AuthorDate: Sat Oct 15 21:33:48 2022 +0800

    fix: incorrect dataGroupId for old data items in universalTransition 
(#17559)
---
 src/animation/universalTransition.ts | 49 ++++++++++++++++++++++++++----------
 test/universalTransition2.html       |  2 +-
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/src/animation/universalTransition.ts 
b/src/animation/universalTransition.ts
index dabd7ee3e..c82d3d78f 100644
--- a/src/animation/universalTransition.ts
+++ b/src/animation/universalTransition.ts
@@ -43,16 +43,18 @@ import Displayable from 'zrender/src/graphic/Displayable';
 
 const DATA_COUNT_THRESHOLD = 1e4;
 
-interface GlobalStore { oldSeries: SeriesModel[], oldData: SeriesData[] };
+interface GlobalStore { oldSeries: SeriesModel[], oldDataGroupIds: string[], 
oldData: SeriesData[] };
 const getUniversalTransitionGlobalStore = makeInner<GlobalStore, 
ExtensionAPI>();
 
 interface DiffItem {
+    dataGroupId: string
     data: SeriesData
     dim: DimensionLoose
     divide: UniversalTransitionOption['divideShape']
     dataIndex: number
 }
 interface TransitionSeries {
+    dataGroupId: string
     data: SeriesData
     divide: UniversalTransitionOption['divideShape']
     dim?: DimensionLoose
@@ -83,6 +85,7 @@ function flattenDataDiffItems(list: TransitionSeries[]) {
         const groupDim = getGroupIdDimension(data);
         for (let dataIndex = 0; dataIndex < indices.length; dataIndex++) {
             items.push({
+                dataGroupId: seriesInfo.dataGroupId,
                 data,
                 dim: seriesInfo.dim || groupDim,
                 divide: seriesInfo.divide,
@@ -207,7 +210,7 @@ function transitionBetween(
             // 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.
-            const dataGroupId = data.hostModel && (data.hostModel as 
SeriesModel).get('dataGroupId') as string;
+            const dataGroupId = diffItem.dataGroupId;
 
             // If specified key dimension(itemGroupId by default). Use this 
same dimension from other data.
             // PENDING: If only use key dimension of newData.
@@ -470,26 +473,35 @@ function findTransitionSeriesBatches(
 ) {
     const updateBatches = createHashMap<SeriesTransitionBatch>();
 
-    const oldDataMap = createHashMap<SeriesData>();
+    const oldDataMap = createHashMap<{
+        dataGroupId: string,
+        data: SeriesData
+    }>();
     // Map that only store key in array seriesKey.
     // Which is used to query the old data when transition from one to 
multiple series.
     const oldDataMapForSplit = createHashMap<{
         key: string,
+        dataGroupId: string,
         data: SeriesData
     }>();
 
     each(globalStore.oldSeries, (series, idx) => {
+        const oldDataGroupId = globalStore.oldDataGroupIds[idx] as string;
         const oldData = globalStore.oldData[idx];
         const transitionKey = getSeriesTransitionKey(series);
         const transitionKeyStr = convertArraySeriesKeyToString(transitionKey);
-        oldDataMap.set(transitionKeyStr, oldData);
+        oldDataMap.set(transitionKeyStr, {
+            dataGroupId: oldDataGroupId,
+            data: oldData
+        });
 
         if (isArray(transitionKey)) {
             // Same key can't in different array seriesKey.
             each(transitionKey, key => {
                 oldDataMapForSplit.set(key, {
-                    data: oldData,
-                    key: transitionKeyStr
+                    key: transitionKeyStr,
+                    dataGroupId: oldDataGroupId,
+                    data: oldData
                 });
             });
         }
@@ -502,6 +514,7 @@ function findTransitionSeriesBatches(
     }
     each(params.updatedSeries, series => {
         if (series.isUniversalTransitionEnabled() && 
series.isAnimationEnabled()) {
+            const newDataGroupId = series.get('dataGroupId') as string;
             const newData = series.getData();
             const transitionKey = getSeriesTransitionKey(series);
             const transitionKeyStr = 
convertArraySeriesKeyToString(transitionKey);
@@ -515,16 +528,18 @@ function findTransitionSeriesBatches(
                 // TODO check if data is same?
                 updateBatches.set(transitionKeyStr, {
                     oldSeries: [{
-                        divide: getDivideShapeFromData(oldData),
-                        data: oldData
+                        dataGroupId: oldData.dataGroupId,
+                        divide: getDivideShapeFromData(oldData.data),
+                        data: oldData.data
                     }],
                     newSeries: [{
+                        dataGroupId: newDataGroupId,
                         divide: getDivideShapeFromData(newData),
                         data: newData
                     }]
                 });
             }
-           else {
+            else {
                 // Transition from multiple series.
                 if (isArray(transitionKey)) {
                     if (__DEV__) {
@@ -533,10 +548,11 @@ function findTransitionSeriesBatches(
                     const oldSeries: TransitionSeries[] = [];
                     each(transitionKey, key => {
                         const oldData = oldDataMap.get(key);
-                        if (oldData) {
+                        if (oldData.data) {
                             oldSeries.push({
-                                divide: getDivideShapeFromData(oldData),
-                                data: oldData
+                                dataGroupId: oldData.dataGroupId,
+                                divide: getDivideShapeFromData(oldData.data),
+                                data: oldData.data
                             });
                         }
                     });
@@ -544,6 +560,7 @@ function findTransitionSeriesBatches(
                         updateBatches.set(transitionKeyStr, {
                             oldSeries,
                             newSeries: [{
+                                dataGroupId: newDataGroupId,
                                 data: newData,
                                 divide: getDivideShapeFromData(newData)
                             }]
@@ -558,6 +575,7 @@ function findTransitionSeriesBatches(
                         if (!batch) {
                             batch = {
                                 oldSeries: [{
+                                    dataGroupId: oldData.dataGroupId,
                                     data: oldData.data,
                                     divide: 
getDivideShapeFromData(oldData.data)
                                 }],
@@ -566,6 +584,7 @@ function findTransitionSeriesBatches(
                             updateBatches.set(oldData.key, batch);
                         }
                         batch.newSeries.push({
+                            dataGroupId: newDataGroupId,
                             data: newData,
                             divide: getDivideShapeFromData(newData)
                         });
@@ -600,6 +619,7 @@ function transitionSeriesFromOpt(
         const idx = querySeries(globalStore.oldSeries, finder);
         if (idx >= 0) {
             from.push({
+                dataGroupId: globalStore.oldDataGroupIds[idx],
                 data: globalStore.oldData[idx],
                 // TODO can specify divideShape in transition.
                 divide: getDivideShapeFromData(globalStore.oldData[idx]),
@@ -612,6 +632,7 @@ function transitionSeriesFromOpt(
         if (idx >= 0) {
             const data = params.updatedSeries[idx].getData();
             to.push({
+                dataGroupId: globalStore.oldDataGroupIds[idx],
                 data,
                 divide: getDivideShapeFromData(data),
                 dim: finder.dimension
@@ -671,6 +692,7 @@ export function installUniversalTransition(registers: 
EChartsExtensionInstallReg
         // Save all series of current update. Not only the updated one.
         const allSeries = ecModel.getSeries();
         const savedSeries: SeriesModel[] = globalStore.oldSeries = [];
+        const savedDataGroupIds: string[] = globalStore.oldDataGroupIds = [];
         const savedData: SeriesData[] = globalStore.oldData = [];
         for (let i = 0; i < allSeries.length; i++) {
             const data = allSeries[i].getData();
@@ -678,8 +700,9 @@ export function installUniversalTransition(registers: 
EChartsExtensionInstallReg
             // Avoid large data costing too much extra memory
             if (data.count() < DATA_COUNT_THRESHOLD) {
                 savedSeries.push(allSeries[i]);
+                savedDataGroupIds.push(allSeries[i].get('dataGroupId') as 
string);
                 savedData.push(data);
             }
         }
     });
-}
\ No newline at end of file
+}
diff --git a/test/universalTransition2.html b/test/universalTransition2.html
index ef3a998a1..33023a0e4 100644
--- a/test/universalTransition2.html
+++ b/test/universalTransition2.html
@@ -62,9 +62,9 @@ under the License.
                     data: ['Animals', 'Fruits', 'Cars']
                 },
                 yAxis: {},
-                dataGroupId: '',
                 animationDurationUpdate: ANIMATION_DURATION_UPDATE,
                 series: {
+                    dataGroupId: '',
                     type: 'bar',
                     id: 'main',
                     data: [{


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to