This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch fix/treemap-click in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit b4667c8cc38216417a2d63e8e58562cb3aa16dec Author: 100pah <[email protected]> AuthorDate: Sun Nov 1 23:44:23 2020 +0800 ts: remove @ts-nocheck for some of the treemap files. --- src/chart/treemap/TreemapView.ts | 17 +++-- src/util/animation.ts | 157 ++++++++++++++++++++------------------- 2 files changed, 90 insertions(+), 84 deletions(-) diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts index 4779b5b..42ba1e1 100644 --- a/src/chart/treemap/TreemapView.ts +++ b/src/chart/treemap/TreemapView.ts @@ -17,7 +17,7 @@ * under the License. */ -import {bind, each, indexOf, curry, extend, retrieve, normalizeCssArray} from 'zrender/src/core/util'; +import {bind, each, indexOf, curry, extend, retrieve, normalizeCssArray, isFunction} from 'zrender/src/core/util'; import * as graphic from '../../util/graphic'; import {getECData} from '../../util/innerStore'; import { @@ -358,8 +358,11 @@ class TreemapView extends ChartView { return; } - const duration = seriesModel.get('animationDurationUpdate'); - const easing = seriesModel.get('animationEasing'); + const durationOption = seriesModel.get('animationDurationUpdate'); + const easingOption = seriesModel.get('animationEasing'); + // TODO: do not support function until necessary. + const duration = (isFunction(durationOption) ? 0 : durationOption) || 0; + const easing = (isFunction(easingOption) ? null : easingOption) || 'cubicOut'; const animationWrap = animationUtil.createWrap(); // Make delete animations. @@ -411,8 +414,9 @@ class TreemapView extends ChartView { style: {opacity: 0} }; } - // @ts-ignore - target && animationWrap.add(el, target, duration, easing); + + // TODO: do not support delay until necessary. + target && animationWrap.add(el, target, duration, 0, easing); }); }); @@ -451,8 +455,7 @@ class TreemapView extends ChartView { } } - // @ts-ignore - animationWrap.add(el, target, duration, easing); + animationWrap.add(el, target, duration, 0, easing); }); }, this); diff --git a/src/util/animation.ts b/src/util/animation.ts index fedf418..d48b527 100644 --- a/src/util/animation.ts +++ b/src/util/animation.ts @@ -17,103 +17,106 @@ * under the License. */ -// @ts-nocheck -import * as zrUtil from 'zrender/src/core/util'; import Element, { ElementProps } from 'zrender/src/Element'; import { ZREasing } from './types'; +import { AnimationEasing } from 'zrender/src/animation/easing'; + +interface AnimationWrapStorage { + el: Element; + target: ElementProps; + duration: number; + delay: number; + easing: AnimationEasing +} +type AnimationWrapDoneCallback = () => void; /** + * Animate multiple elements with a single done-callback. + * * @example - * // Animate position * animation * .createWrap() - * .add(el1, {position: [10, 10]}) + * .add(el1, {x: 10, y: 10}) * .add(el2, {shape: {width: 500}, style: {fill: 'red'}}, 400) * .done(function () { // done }) * .start('cubicOut'); */ -export function createWrap() { - - const storage = []; - let elExistsMap = {}; - let doneCallback; +class AnimationWrap { - return { + private _storage = [] as AnimationWrapStorage[]; + private _elExistsMap: { [elId: string]: boolean } = {}; + private _doneCallback: AnimationWrapDoneCallback; - /** - * Caution: a el can only be added once, otherwise 'done' - * might not be called. This method checks this (by el.id), - * suppresses adding and returns false when existing el found. - * - * @return Whether adding succeeded. - * - * @example - * add(el, target, time, delay, easing); - * add(el, target, time, easing); - * add(el, target, time); - * add(el, target); - */ - add: function ( - el: Element, - target: ElementProps, - time?: number, - delay?: number | ZREasing, - easing?: ZREasing - ) { - if (zrUtil.isString(delay)) { - easing = delay; - delay = 0; - } - - if (elExistsMap[el.id]) { - return false; - } - elExistsMap[el.id] = 1; + /** + * Caution: a el can only be added once, otherwise 'done' + * might not be called. This method checks this (by el.id), + * suppresses adding and returns false when existing el found. + * + * @return Whether adding succeeded. + */ + add( + el: Element, + target: ElementProps, + duration?: number, + delay?: number, + easing?: ZREasing + ): boolean { + if (this._elExistsMap[el.id]) { + return false; + } + this._elExistsMap[el.id] = true; - storage.push( - {el: el, target: target, time: time, delay: delay, easing: easing} - ); + this._storage.push({ + el: el, + target: target, + duration: duration, + delay: delay, + easing: easing + }); - return true; - }, + return true; + } - /** - * Only execute when animation finished. Will not execute when any - * of 'stop' or 'stopAnimation' called. - */ - done: function (callback: () => void) { - doneCallback = callback; - return this; - }, + /** + * Only execute when animation finished. Will not execute when any + * of 'stop' or 'stopAnimation' called. + */ + done(callback: AnimationWrapDoneCallback): AnimationWrap { + this._doneCallback = callback; + return this; + } - /** - * Will stop exist animation firstly. - */ - start: function () { - let count = storage.length; + /** + * Will stop exist animation firstly. + */ + start(): AnimationWrap { + let count = this._storage.length; - for (let i = 0, len = storage.length; i < len; i++) { - const item = storage[i]; - item.el.animateTo(item.target, { - duration: item.time, - delay: item.delay, - easing: item.easing, - setToFinal: true, - done - }); + const done = () => { + count--; + if (!count) { + this._storage.length = 0; + this._elExistsMap = {}; + this._doneCallback && this._doneCallback(); } + }; - return this; - - function done() { - count--; - if (!count) { - storage.length = 0; - elExistsMap = {}; - doneCallback && doneCallback(); - } - } + for (let i = 0, len = this._storage.length; i < len; i++) { + const item = this._storage[i]; + item.el.animateTo(item.target, { + duration: item.duration, + delay: item.delay, + easing: item.easing, + setToFinal: true, + done + }); } - }; + + return this; + } +} + +export function createWrap(): AnimationWrap { + return new AnimationWrap(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
