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/16 13:36:58 UTC
[echarts] branch enhance-morph updated: feat(ut): better guess of
animation key when groupBy is used.
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 5a0fd32 feat(ut): better guess of animation key when groupBy is used.
5a0fd32 is described below
commit 5a0fd32f1193745ef05209afd103f6f9ee523332
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Jun 16 21:35:50 2021 +0800
feat(ut): better guess of animation key when groupBy is used.
Find same dimension on the list if their groupBy is not given.
---
src/animation/universalTransition.ts | 27 ++--
test/universalTransition2.html | 242 ++++++++++-------------------------
2 files changed, 88 insertions(+), 181 deletions(-)
diff --git a/src/animation/universalTransition.ts b/src/animation/universalTransition.ts
index 11b3ef5..1cf1155 100644
--- a/src/animation/universalTransition.ts
+++ b/src/animation/universalTransition.ts
@@ -18,7 +18,7 @@
*/
import SeriesModel from '../model/Series';
-import {createHashMap, each, map, filter, isArray} from 'zrender/src/core/util';
+import {createHashMap, each, map, filter} from 'zrender/src/core/util';
import Element, { ElementAnimateConfig } from 'zrender/src/Element';
import { applyMorphAnimation, getPathList } from './morphTransitionHelper';
import Path from 'zrender/src/graphic/Path';
@@ -104,7 +104,6 @@ function transitionBetweenData(
}
}
- // PENDING: If one data has groupId encode dimension. Other data find this same dimension
function getGroupIdDimension(data: List) {
const dimensions = data.dimensions;
for (let i = 0; i < dimensions.length; i++) {
@@ -115,22 +114,26 @@ function transitionBetweenData(
}
}
+
+ const oldDataGroupIdDim = getGroupIdDimension(oldData);
+ const newDataGroupIdDim = getGroupIdDimension(newData);
+
// TODO share it to other modules. or put it in the List
function createGroupIdGetter(data: List) {
const dataGroupId = data.hostModel && (data.hostModel as SeriesModel).get('dataGroupId') as string;
- const groupIdDimension: string = getGroupIdDimension(data);
+ // If one data has groupId encode dimension. Use this same dimension from other data.
+ // PENDING: If only use groupId dimension of newData.
+ const groupIdDimension: string = data === oldData
+ ? (oldDataGroupIdDim || newDataGroupIdDim)
+ : (newDataGroupIdDim || oldDataGroupIdDim);
+
const dimInfo = groupIdDimension && data.getDimensionInfo(groupIdDimension);
const dimOrdinalMeta = dimInfo && dimInfo.ordinalMeta;
// 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.
return function (rawIdx: number, dataIndex: number): string {
- // Get from raw item. { groupId: '' }
- const itemVal = data.getRawDataItem(dataIndex) as OptionDataItemObject<unknown>;
- if (itemVal && itemVal.groupId) {
- return itemVal.groupId + '';
- }
- if (groupIdDimension) {
+ if (dimOrdinalMeta) {
// Get from encode.itemGroupId.
const groupId = data.get(groupIdDimension, dataIndex);
if (dimOrdinalMeta) {
@@ -138,6 +141,12 @@ function transitionBetweenData(
}
return groupId + '';
}
+
+ // Get from raw item. { groupId: '' }
+ const itemVal = data.getRawDataItem(dataIndex) as OptionDataItemObject<unknown>;
+ if (itemVal && itemVal.groupId) {
+ return itemVal.groupId + '';
+ }
return (dataGroupId || data.getId(dataIndex));
};
}
diff --git a/test/universalTransition2.html b/test/universalTransition2.html
index 9199bfd..843a0e7 100644
--- a/test/universalTransition2.html
+++ b/test/universalTransition2.html
@@ -164,208 +164,106 @@ under the License.
echarts.registerTransform(ecSimpleTransform.aggregate);
echarts.registerTransform(ecSimpleTransform.id);
- const optionCreators = {
- 'CountryAB_Year_Income_Bar'(datasetId, itemGroupId) {
- return {
- xAxis: {
- type: 'category'
- },
- yAxis: {
- name: 'Income'
- },
- series: {
- type: 'bar',
- id: 'main',
- coordinateSystem: 'cartesian2d',
- datasetId,
- universalTransition: {
- enabled: true
- },
- encode: {
- x: 'Year',
- y: 'Income',
- itemName: 'Year',
- itemGroupId,
- tooltip: ['Income'],
- }
- }
- };
- },
+ const RAW_DATA_DIMENSIONS = ['Income', 'Life Expectancy', 'Population', 'Country', 'Year'];
+ const ID_RAW_DATA_DIMENSIONS = ['Income', 'Life Expectancy', 'Population', 'Country', 'Year', 'Id'];
+ const SUM_INCOME_DIMENSIONS = ['Income', 'Country'];
+ var COUNTRY_A = 'Germany';
+ var COUNTRY_B = 'France';
- 'CountryAB_Year_Population_Bar'(datasetId, itemGroupId) {
- return {
- xAxis: {
- type: 'category'
- },
- yAxis: {
- name: 'Population'
+ function createOption(xDim, yDim, seriesType, groupBy) {
+ return {
+ animationDurationUpdate: 1000,
+ dataset: [
+ {
+ id: 'RawData',
+ source: rawData
},
- series: {
- type: 'bar',
- id: 'main',
- coordinateSystem: 'cartesian2d',
- datasetId,
- universalTransition: {
- enabled: true
- },
- encode: {
- x: 'Year',
- y: 'Population',
- itemName: 'Year',
- itemGroupId,
- tooltip: ['Population'],
+ {
+ id: 'CountryABData',
+ fromDatasetId: 'RawData',
+ transform: {
+ type: 'filter',
+ config: {
+ or: [{
+ dimension: 'Country', '=': COUNTRY_A
+ }, {
+ dimension: 'Country', '=': COUNTRY_B
+ }]
+ }
}
- }
- };
- },
-
- 'CountryAB_Income_Population_Scatter'(datasetId, itemGroupId) {
- return {
- xAxis: {
- name: 'Income',
- scale: true
- },
- yAxis: {
- name: 'Population',
- scale: true
},
- series: {
- type: 'scatter',
- id: 'main',
- coordinateSystem: 'cartesian2d',
- datasetId,
- universalTransition: {
- enabled: true
- },
- encode: {
- x: 'Income',
- y: 'Population',
- itemName: ['Year'],
- itemGroupId,
- tooltip: ['Income', 'Population', 'Country']
+ ...(groupBy ? [{
+ id: `groupBy_${groupBy}`,
+ fromDatasetId: 'CountryABData',
+ transform: {
+ type: 'ecSimpleTransform:aggregate',
+ config: {
+ resultDimensions: [
+ { from: 'Income', method: 'sum' },
+ { from: groupBy }
+ ],
+ groupBy
+ }
}
- }
- };
- },
+ }] : [])
+ ],
+ tooltip: {},
- 'CountryAB_Income_Sum_Bar'(datasetId, itemGroupId) {
- return {
- xAxis: {
- name: 'Income'
- },
- yAxis: {
- type: 'category'
+ xAxis: {
+ name: xDim,
+ type: 'category'
+ },
+ yAxis: {
+ name: yDim
+ },
+ series: {
+ type: seriesType,
+ id: 'main',
+ datasetId: groupBy ? `groupBy_${groupBy}` : 'CountryABData',
+ universalTransition: {
+ enabled: true
},
- series: {
- type: 'bar',
- id: 'main',
- coordinateSystem: 'cartesian2d',
- datasetId,
- universalTransition: {
- enabled: true
- },
- encode: {
- x: 'Income',
- y: 'Country',
- itemName: ['Country'],
- itemGroupId,
- tooltip: ['Income']
- }
+ encode: {
+ x: xDim,
+ y: yDim,
+ itemGroupId: groupBy
}
- };
+ }
}
- };
+ }
- let currentStageIdx = 0;
+ let currentOptionIdx = 0;
- const stages = [
+ const options = [
{
- option: optionCreators['CountryAB_Year_Income_Bar']('CountryABData', 'Country')
+ option: createOption('Year', 'Income', 'bar')
},
{
- option: optionCreators['CountryAB_Year_Population_Bar']('CountryABData', 'Country')
+ option: createOption('Year', 'Population', 'bar')
},
{
- option: optionCreators['CountryAB_Income_Population_Scatter']('CountryABData', 'Country')
+ option: createOption('Year', 'Population', 'scatter')
},
{
- option: optionCreators['CountryAB_Income_Sum_Bar']('CountryABSumIncome', 'Country')
+ option: createOption('Country', 'Income', 'bar', 'Country')
}
// {
// option: optionCreators['CountryAB_Year_Income_Bar']('CountryABData', 'Country')
// }
];
- const RAW_DATA_DIMENSIONS = ['Income', 'Life Expectancy', 'Population', 'Country', 'Year'];
- const ID_RAW_DATA_DIMENSIONS = ['Income', 'Life Expectancy', 'Population', 'Country', 'Year', 'Id'];
- const SUM_INCOME_DIMENSIONS = ['Income', 'Country'];
- var COUNTRY_A = 'Germany';
- var COUNTRY_B = 'France';
+ console.log(options);
- const baseOption = {
- animationDurationUpdate: 1000,
- dataset: [{
- id: 'RawData',
- source: rawData
- }, {
- id: 'IdRawData',
- fromDatasetId: 'RawData',
- transform: [{
- type: 'filter',
- config: {
- dimension: 'Year', gte: 1950
- }
- }, {
- type: 'ecSimpleTransform:id',
- config: {
- dimensionIndex: ID_RAW_DATA_DIMENSIONS.indexOf('Id'),
- dimensionName: 'Id'
- }
- }]
- }, {
- id: 'CountryABData',
- fromDatasetId: 'IdRawData',
- transform: {
- type: 'filter',
- config: {
- or: [{
- dimension: 'Country', '=': COUNTRY_A
- }, {
- dimension: 'Country', '=': COUNTRY_B
- }]
- }
- }
- }, {
- id: 'CountryABSumIncome',
- fromDatasetId: 'CountryABData',
- transform: {
- type: 'ecSimpleTransform:aggregate',
- config: {
- resultDimensions: [
- { from: 'Income', method: 'sum' },
- { from: 'Country' }
- ],
- groupBy: 'Country'
- }
- }
- }],
- tooltip: {},
- series: []
- };
-
- function createOption() {
- return Object.assign({}, baseOption, stages[currentStageIdx].option);
- }
function createNextOption() {
- currentStageIdx = (currentStageIdx + 1) % stages.length;
- const option = createOption();
+ currentOptionIdx = (currentOptionIdx + 1) % options.length;
+ const option = options[currentOptionIdx].option;
return option;
}
function createPrevOption() {
- currentStageIdx = (currentStageIdx - 1) % stages.length;
- const option = createOption();
+ currentOptionIdx = (currentOptionIdx - 1) % options.length;
+ const option = options[currentOptionIdx].option;
return option;
}
@@ -373,7 +271,7 @@ under the License.
title: [
'Transition with dataset transform.'
],
- option: createOption(),
+ option: options[currentOptionIdx].option,
// height: 300,
buttons: [{
text: 'prev',
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org