@visactor/vchart
Version:
charts lib based @visactor/VGrammar
172 lines (153 loc) • 6.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.registerSankeyAnimation = exports.LinkPathUpdate = exports.LinkPathGrowOut = exports.LinkPathGrowIn = exports.sankeyLinkPresetAnimation = exports.sankeyNodePresetAnimation = exports.sankeyGrowOut = exports.sankeyGrowIn = void 0;
const factory_1 = require("../../core/factory"), config_1 = require("../../animation/config"), vrender_animate_1 = require("@visactor/vrender-animate"), sankeyGrowIn = (params, isOverall = !0) => ({
type: "horizontal" === params.direction ? "growWidthIn" : "growHeightIn",
options: {
overall: isOverall ? params.growFrom() : isOverall,
orient: "positive"
}
});
exports.sankeyGrowIn = sankeyGrowIn;
const sankeyGrowOut = (params, isOverall = !0) => ({
type: "horizontal" === params.direction ? "growWidthOut" : "growHeightOut",
options: {
overall: isOverall ? params.growFrom() : isOverall,
orient: "positive"
}
});
exports.sankeyGrowOut = sankeyGrowOut;
const sankeyNodePresetAnimation = (params, preset) => "fadeIn" === preset ? {
type: "fadeIn"
} : (0, exports.sankeyGrowIn)(params);
exports.sankeyNodePresetAnimation = sankeyNodePresetAnimation;
const sankeyLinkPresetAnimation = preset => "fadeIn" === preset ? {
type: "fadeIn"
} : {
type: "linkPathGrowIn"
};
exports.sankeyLinkPresetAnimation = sankeyLinkPresetAnimation;
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
};
};
class LinkPathGrowIn extends vrender_animate_1.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);
}
}
exports.LinkPathGrowIn = LinkPathGrowIn;
class LinkPathGrowOut extends vrender_animate_1.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);
}
}
exports.LinkPathGrowOut = LinkPathGrowOut;
class LinkPathUpdate extends vrender_animate_1.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);
}
}
exports.LinkPathUpdate = LinkPathUpdate;
const registerSankeyAnimation = () => {
factory_1.Factory.registerAnimation("sankeyNode", ((params, preset) => Object.assign({
appear: (0, exports.sankeyNodePresetAnimation)(params, preset)
}, config_1.FadeInOutAnimation))), factory_1.Factory.registerAnimation("sankeyLinkPath", ((params, preset) => ({
appear: (0, exports.sankeyLinkPresetAnimation)(preset),
enter: {
type: "linkPathGrowIn"
},
exit: {
type: "linkPathGrowOut"
},
disappear: {
type: "linkPathGrowOut"
}
}))), vrender_animate_1.AnimateExecutor.registerBuiltInAnimate("linkPathGrowOut", LinkPathGrowOut),
vrender_animate_1.AnimateExecutor.registerBuiltInAnimate("linkPathGrowIn", LinkPathGrowIn);
};
exports.registerSankeyAnimation = registerSankeyAnimation;
//# sourceMappingURL=animation.js.map