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 c9f4853 feat(ut): support mulitple from/to in setOption transition c9f4853 is described below commit c9f4853aff22bb48b868a75806c013303de1524d Author: pissang <bm2736...@gmail.com> AuthorDate: Thu Jun 17 17:24:19 2021 +0800 feat(ut): support mulitple from/to in setOption transition --- src/animation/universalTransition.ts | 52 +++++++++++++++++++++++------------- src/core/echarts.ts | 5 ++-- src/core/lifecycle.ts | 6 ++--- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/animation/universalTransition.ts b/src/animation/universalTransition.ts index 1b44203..fa96d2f 100644 --- a/src/animation/universalTransition.ts +++ b/src/animation/universalTransition.ts @@ -20,7 +20,7 @@ // Universal transitions that can animate between any shapes(series) and any properties in any amounts. import SeriesModel from '../model/Series'; -import {createHashMap, each, map, filter, isArray} from 'zrender/src/core/util'; +import {createHashMap, each, map, filter, isArray, find} from 'zrender/src/core/util'; import Element, { ElementAnimateConfig } from 'zrender/src/Element'; import { applyMorphAnimation, getPathList } from './morphTransitionHelper'; import Path from 'zrender/src/graphic/Path'; @@ -29,7 +29,12 @@ import { initProps } from '../util/graphic'; import DataDiffer from '../data/DataDiffer'; import List from '../data/List'; import { DimensionLoose, OptionDataItemObject } from '../util/types'; -import { UpdateLifecycleParams, UpdateLifecycleTransitionItem } from '../core/lifecycle'; +import { + UpdateLifecycleParams, + UpdateLifecycleTransitionItem, + UpdateLifecycleTransitionSeriesFinder +} from '../core/lifecycle'; +import { normalizeToArray } from '../util/model'; interface DiffItem { data: List @@ -418,7 +423,7 @@ function findTransitionSeriesBatches(params: UpdateLifecycleParams) { return updateBatches; } -function querySeries(series: SeriesModel[], finder: UpdateLifecycleTransitionItem['from']) { +function querySeries(series: SeriesModel[], finder: UpdateLifecycleTransitionSeriesFinder) { for (let i = 0; i < series.length; i++) { const found = finder.seriesIndex != null && finder.seriesIndex === series[i].seriesIndex || finder.seriesId != null && finder.seriesId === series[i].id; @@ -429,16 +434,28 @@ function querySeries(series: SeriesModel[], finder: UpdateLifecycleTransitionIte } function transitionSeriesFromOpt(transitionOpt: UpdateLifecycleTransitionItem, params: UpdateLifecycleParams) { - const fromSeriesIdx = querySeries(params.oldSeries, transitionOpt.from); - const toSeriesIdx = querySeries(params.updatedSeries, transitionOpt.to); - if (fromSeriesIdx >= 0 && toSeriesIdx >= 0) { - transitionBetween([{ - data: params.oldData[fromSeriesIdx], - dim: transitionOpt.from.dimension - }], [{ - data: params.updatedSeries[toSeriesIdx].getData(), - dim: transitionOpt.to.dimension - }]); + const from: TransitionSeries[] = []; + const to: TransitionSeries[] = []; + each(normalizeToArray(transitionOpt.from), finder => { + const idx = querySeries(params.oldSeries, finder); + if (idx >= 0) { + from.push({ + data: params.oldData[idx], + dim: finder.dimension + }); + } + }); + each(normalizeToArray(transitionOpt.to), finder => { + const idx = querySeries(params.updatedSeries, finder); + if (idx >= 0) { + to.push({ + data: params.updatedSeries[idx].getData(), + dim: finder.dimension + }); + } + }); + if (from.length > 0 && to.length > 0) { + transitionBetween(from, to); } } @@ -449,12 +466,9 @@ export function installUniversalTransition(registers: EChartsExtensionInstallReg // Use give transition config if its' give; const transitionOpt = params.seriesTransition; if (transitionOpt) { - if (!isArray(transitionOpt)) { - transitionSeriesFromOpt(transitionOpt, params); - } - else { - each(transitionOpt, opt => transitionSeriesFromOpt(opt, params)); - } + each(normalizeToArray(transitionOpt), opt => { + transitionSeriesFromOpt(opt, params); + }); } else { // Else guess from series based on transition series key. const updateBatches = findTransitionSeriesBatches(params); diff --git a/src/core/echarts.ts b/src/core/echarts.ts index 6f9351f..cf00d17 100644 --- a/src/core/echarts.ts +++ b/src/core/echarts.ts @@ -620,8 +620,7 @@ class ECharts extends Eventful<ECEventDefinition> { if (transitionOpt) { each(modelUtil.normalizeToArray(transitionOpt), transOpt => { - const finder = transOpt.to; - if (finder) { + each(modelUtil.normalizeToArray(transOpt.to), (finder) => { const series = this._model.getSeries(); for (let i = 0; i < series.length; i++) { if (finder.seriesIndex != null && finder.seriesIndex === series[i].seriesIndex @@ -629,7 +628,7 @@ class ECharts extends Eventful<ECEventDefinition> { series[i][SERIES_UNIVERSAL_TRANSITION_PROP] = true; } } - } + }); }); } diff --git a/src/core/lifecycle.ts b/src/core/lifecycle.ts index 7aa91cd..d5c5976 100644 --- a/src/core/lifecycle.ts +++ b/src/core/lifecycle.ts @@ -26,7 +26,7 @@ import List from '../data/List'; import { ModelFinderIdQuery, ModelFinderIndexQuery } from '../util/model'; import { DimensionLoose } from '../util/types'; -interface TransitionSeriesFinder { +export interface UpdateLifecycleTransitionSeriesFinder { seriesIndex?: ModelFinderIndexQuery, seriesId?: ModelFinderIdQuery dimension: DimensionLoose; @@ -36,8 +36,8 @@ export interface UpdateLifecycleTransitionItem { // If `from` not given, it means that do not make series transition mandatorily. // There might be transition mapping dy default. Sometimes we do not need them, // which might bring about misleading. - from?: TransitionSeriesFinder; - to: TransitionSeriesFinder; + from?: UpdateLifecycleTransitionSeriesFinder | UpdateLifecycleTransitionSeriesFinder[]; + to: UpdateLifecycleTransitionSeriesFinder | UpdateLifecycleTransitionSeriesFinder[]; }; export type UpdateLifecycleTransitionOpt = UpdateLifecycleTransitionItem | UpdateLifecycleTransitionItem[]; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org