UNPKG

@visactor/vrender-animate

Version:

This module provides a graph-based animation system for VRender.

113 lines (104 loc) 4.68 kB
import { ACustomAnimate } from "./custom-animate"; import { isNumber } from "@visactor/vutils"; import { applyAnimationFrameAttributes, applyAppearStartAttributes } from "./transient"; const growRadiusInIndividual = (graphic, options, animationParameters) => { const attrs = graphic.getFinalAttribute(); return options && "inside" === options.orient ? { from: { innerRadius: null == attrs ? void 0 : attrs.outerRadius }, to: { innerRadius: null == attrs ? void 0 : attrs.innerRadius } } : { from: { outerRadius: null == attrs ? void 0 : attrs.innerRadius }, to: { outerRadius: null == attrs ? void 0 : attrs.outerRadius } }; }, growRadiusInOverall = (graphic, options, animationParameters) => { const attrs = graphic.getFinalAttribute(), overallValue = isNumber(null == options ? void 0 : options.overall) ? options.overall : 0; return { from: { innerRadius: overallValue, outerRadius: overallValue }, to: { innerRadius: null == attrs ? void 0 : attrs.innerRadius, outerRadius: null == attrs ? void 0 : attrs.outerRadius } }; }; export const growRadiusIn = (graphic, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growRadiusInOverall(graphic, options) : growRadiusInIndividual(graphic, options); }; const growRadiusOutIndividual = (graphic, options, animationParameters) => { const attrs = graphic.getFinalAttribute(); return options && "inside" === options.orient ? { from: { innerRadius: null == attrs ? void 0 : attrs.innerRadius }, to: { innerRadius: null == attrs ? void 0 : attrs.outerRadius } } : { from: { outerRadius: null == attrs ? void 0 : attrs.outerRadius }, to: { outerRadius: null == attrs ? void 0 : attrs.innerRadius } }; }, growRadiusOutOverall = (graphic, options, animationParameters) => { const attrs = graphic.getFinalAttribute(), overallValue = isNumber(null == options ? void 0 : options.overall) ? options.overall : 0; return { from: { innerRadius: null == attrs ? void 0 : attrs.innerRadius, outerRadius: null == attrs ? void 0 : attrs.outerRadius }, to: { innerRadius: overallValue, outerRadius: overallValue } }; }; export const growRadiusOut = (graphic, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growRadiusOutOverall(graphic, options) : growRadiusOutIndividual(graphic, options); }; export class GrowPointsBase extends ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } onUpdate(end, ratio, out) { const attrs = {}; this.propKeys.forEach((key => { attrs[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), applyAnimationFrameAttributes(this.target, attrs), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag(); } } export class GrowRadiusIn extends GrowPointsBase { onBind() { var _a, _b, _c; super.onBind(); const {from: from, to: to} = growRadiusIn(this.target, this.params.options, this.params), fromAttrs = null !== (_b = null === (_a = this.target.context) || void 0 === _a ? void 0 : _a.lastAttrs) && void 0 !== _b ? _b : from; this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])), this.from = fromAttrs, this.to = to, this.target.applyFinalAttributeToAttribute(), !1 !== (null === (_c = this.params.controlOptions) || void 0 === _c ? void 0 : _c.immediatelyApply) && applyAppearStartAttributes(this.target, fromAttrs); } } export class GrowRadiusOut extends GrowPointsBase { onBind() { super.onBind(); const {to: to} = (graphic = this.target, options = this.params.options, this.params, !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growRadiusOutOverall(graphic, options) : growRadiusOutIndividual(graphic, options)); var graphic, options, _a; this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])), this.from = this.target.attribute, this.to = to; } } //# sourceMappingURL=growRadius.js.map