UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

156 lines (144 loc) 6.17 kB
import { Factory } from "../../core/factory"; import { FadeInOutAnimation } from "../../animation/config"; import { ACustomAnimate, AnimateExecutor } from "@visactor/vrender-animate"; export const sankeyGrowIn = (params, isOverall = !0) => ({ type: "horizontal" === params.direction ? "growWidthIn" : "growHeightIn", options: { overall: isOverall ? params.growFrom() : isOverall, orient: "positive" } }); export const sankeyGrowOut = (params, isOverall = !0) => ({ type: "horizontal" === params.direction ? "growWidthOut" : "growHeightOut", options: { overall: isOverall ? params.growFrom() : isOverall, orient: "positive" } }); export const sankeyNodePresetAnimation = (params, preset) => "fadeIn" === preset ? { type: "fadeIn" } : sankeyGrowIn(params); export const sankeyLinkPresetAnimation = preset => "fadeIn" === preset ? { type: "fadeIn" } : { type: "linkPathGrowIn" }; const linkPathGrowIn = (graphic, options, animationParameters) => { const linkValues = { x0: graphic.getFinalAttribute().x0, x1: graphic.getFinalAttribute().x1, y0: graphic.getFinalAttribute().y0, y1: graphic.getFinalAttribute().y1, thickness: graphic.getFinalAttribute().thickness }; return { from: Object.assign({}, linkValues, { x1: linkValues.x0, y1: linkValues.y0 }), to: linkValues }; }, linkPathGrowOut = (element, options, animationParameters) => { const linkValues = { x0: element.getFinalAttribute().x0, x1: element.getFinalAttribute().x1, y0: element.getFinalAttribute().y0, y1: element.getFinalAttribute().y1, thickness: element.getFinalAttribute().thickness }; return { from: linkValues, to: Object.assign({}, linkValues, { x1: linkValues.x0, y1: linkValues.y0 }) }; }, linkPathUpdate = (graphic, options, animationParameters) => { let from, to; { const {x0: x0, x1: x1, y0: y0, y1: y1} = graphic.getFinalAttribute(); from = { x0: x0, x1: x1, y0: y0, y1: y1 }; } { const {x0: x0, x1: x1, y0: y0, y1: y1} = graphic.attribute; to = { x0: x0, x1: x1, y0: y0, y1: y1 }; } return { from: from, to: to }; }; export class LinkPathGrowIn extends ACustomAnimate { onBind() { var _a, _b, _c; super.onBind(), (null === (_a = this.params) || void 0 === _a ? void 0 : _a.diffAttrs) && this.target.setAttributes(this.params.diffAttrs); const {from: from, to: to} = linkPathGrowIn(this.target, this.params.options, this.params), fromAttrs = null !== (_c = null === (_b = this.target.context) || void 0 === _b ? void 0 : _b.lastAttrs) && void 0 !== _c ? _c : from, finalAttribute = this.target.getFinalAttribute(); finalAttribute && Object.assign(this.target.attribute, finalAttribute), this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])), this.animate.reSyncProps(), this.from = fromAttrs, this.to = to, this.target.setAttributes(fromAttrs); } onUpdate(end, ratio, out) { const attribute = this.target.attribute; this.propKeys.forEach((key => { attribute[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), this.target.setAttributes(attribute); } } export class LinkPathGrowOut extends ACustomAnimate { onBind() { var _a, _b, _c; super.onBind(), (null === (_a = this.params) || void 0 === _a ? void 0 : _a.diffAttrs) && this.target.setAttributes(this.params.diffAttrs); const {from: from, to: to} = linkPathGrowOut(this.target, this.params.options, this.params), fromAttrs = null !== (_c = null === (_b = this.target.context) || void 0 === _b ? void 0 : _b.lastAttrs) && void 0 !== _c ? _c : from; this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])), this.animate.reSyncProps(), this.from = fromAttrs, this.to = to, this.target.setAttributes(fromAttrs); } onUpdate(end, ratio, out) { const attribute = this.target.attribute; this.propKeys.forEach((key => { attribute[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), this.target.setAttributes(attribute); } } export class LinkPathUpdate extends ACustomAnimate { onBind() { var _a, _b, _c; (null === (_a = this.params) || void 0 === _a ? void 0 : _a.diffAttrs) && this.target.setAttributes(this.params.diffAttrs); const {from: from, to: to} = linkPathUpdate(this.target, this.params.options, this.params), fromAttrs = null !== (_c = null === (_b = this.target.context) || void 0 === _b ? void 0 : _b.lastAttrs) && void 0 !== _c ? _c : from; this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])), this.animate.reSyncProps(), this.from = fromAttrs, this.to = to, this.target.setAttributes(fromAttrs); } onUpdate(end, ratio, out) { const attribute = this.target.attribute; this.propKeys.forEach((key => { attribute[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), this.target.setAttributes(attribute); } } export const registerSankeyAnimation = () => { Factory.registerAnimation("sankeyNode", ((params, preset) => Object.assign({ appear: sankeyNodePresetAnimation(params, preset) }, FadeInOutAnimation))), Factory.registerAnimation("sankeyLinkPath", ((params, preset) => ({ appear: sankeyLinkPresetAnimation(preset), enter: { type: "linkPathGrowIn" }, exit: { type: "linkPathGrowOut" }, disappear: { type: "linkPathGrowOut" } }))), AnimateExecutor.registerBuiltInAnimate("linkPathGrowOut", LinkPathGrowOut), AnimateExecutor.registerBuiltInAnimate("linkPathGrowIn", LinkPathGrowIn); }; //# sourceMappingURL=animation.js.map