UNPKG

@visactor/vrender-animate

Version:

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

168 lines (157 loc) 6.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.GrowAngleOut = exports.GrowAngleIn = exports.GrowAngleBase = exports.growAngleOut = exports.growAngleIn = void 0; const custom_animate_1 = require("./custom-animate"), vutils_1 = require("@visactor/vutils"), transient_1 = require("./transient"), growAngleInIndividual = (graphic, options, animationParameters) => { const attrs = graphic.getFinalAttribute(); return options && "anticlockwise" === options.orient ? { from: { startAngle: null == attrs ? void 0 : attrs.endAngle }, to: { startAngle: null == attrs ? void 0 : attrs.startAngle } } : { from: { endAngle: null == attrs ? void 0 : attrs.startAngle }, to: { endAngle: null == attrs ? void 0 : attrs.endAngle } }; }, growAngleInOverall = (graphic, options, animationParameters) => { const attrs = graphic.getFinalAttribute(); if (options && "anticlockwise" === options.orient) { const overallValue = (0, vutils_1.isNumber)(options.overall) ? options.overall : 2 * Math.PI; return { from: { startAngle: overallValue, endAngle: overallValue }, to: { startAngle: null == attrs ? void 0 : attrs.startAngle, endAngle: null == attrs ? void 0 : attrs.endAngle } }; } const overallValue = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? options.overall : 0; return { from: { startAngle: overallValue, endAngle: overallValue }, to: { startAngle: null == attrs ? void 0 : attrs.startAngle, endAngle: null == attrs ? void 0 : attrs.endAngle } }; }, growAngleIn = (graphic, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growAngleInOverall(graphic, options) : growAngleInIndividual(graphic, options); }; exports.growAngleIn = growAngleIn; const growAngleOutIndividual = (graphic, options, animationParameters) => { const attrs = graphic.attribute; return options && "anticlockwise" === options.orient ? { from: { startAngle: attrs.startAngle }, to: { startAngle: null == attrs ? void 0 : attrs.endAngle } } : { from: { endAngle: attrs.endAngle }, to: { endAngle: null == attrs ? void 0 : attrs.startAngle } }; }, growAngleOutOverall = (graphic, options, animationParameters) => { const attrs = graphic.attribute; if (options && "anticlockwise" === options.orient) { const overallValue = (0, vutils_1.isNumber)(options.overall) ? options.overall : 2 * Math.PI; return { from: { startAngle: attrs.startAngle, endAngle: attrs.endAngle }, to: { startAngle: overallValue, endAngle: overallValue } }; } const overallValue = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? options.overall : 0; return { from: { startAngle: attrs.startAngle, endAngle: attrs.endAngle }, to: { startAngle: overallValue, endAngle: overallValue } }; }, growAngleOut = (graphic, options, animationParameters) => { var _a; return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growAngleOutOverall(graphic, options) : growAngleOutIndividual(graphic, options); }; exports.growAngleOut = growAngleOut; class GrowAngleBase extends custom_animate_1.ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } determineUpdateFunction() { this.propKeys ? this.propKeys && this.propKeys.length > 1 ? this._updateFunction = this.updateAngle : "startAngle" === this.propKeys[0] ? this._updateFunction = this.updateStartAngle : "endAngle" === this.propKeys[0] ? this._updateFunction = this.updateEndAngle : this.valid = !1 : this.valid = !1; } deleteSelfAttr(key) { this.deleteSelfAttrs([ key ]); } deleteSelfAttrs(keys) { var _a; super.deleteSelfAttrs(keys); const firstKey = null === (_a = this.propKeys) || void 0 === _a ? void 0 : _a[0]; this.propKeys && this.propKeys.length > 1 ? this._updateFunction = this.updateAngle : this._updateFunction = "startAngle" === firstKey ? this.updateStartAngle : "endAngle" === firstKey ? this.updateEndAngle : null; } updateStartAngle(ratio) { (0, transient_1.applyAnimationFrameAttributes)(this.target, { startAngle: this.from.startAngle + (this.to.startAngle - this.from.startAngle) * ratio }); } updateEndAngle(ratio) { (0, transient_1.applyAnimationFrameAttributes)(this.target, { endAngle: this.from.endAngle + (this.to.endAngle - this.from.endAngle) * ratio }); } updateAngle(ratio) { this.updateStartAngle(ratio), this.updateEndAngle(ratio); } onUpdate(end, ratio, out) { this._updateFunction && (this._updateFunction(ratio), this.target.addUpdateShapeAndBoundsTag()); } } exports.GrowAngleBase = GrowAngleBase; class GrowAngleIn extends GrowAngleBase { onBind() { var _a, _b, _c; super.onBind(); const {from: from, to: to} = (0, exports.growAngleIn)(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) && (0, transient_1.applyAppearStartAttributes)(this.target, fromAttrs), this.determineUpdateFunction(); } } exports.GrowAngleIn = GrowAngleIn; class GrowAngleOut extends GrowAngleBase { onBind() { super.onBind(); const {from: from, to: to} = (0, exports.growAngleOut)(this.target, this.params.options, this.params), fromAttrs = from; this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])), this.from = null != fromAttrs ? fromAttrs : this.target.attribute, this.to = to, this.determineUpdateFunction(); } } exports.GrowAngleOut = GrowAngleOut; //# sourceMappingURL=growAngle.js.map