@visactor/vchart
Version:
charts lib based @visactor/VGrammar
99 lines (89 loc) • 2.69 kB
JavaScript
import { ACustomAnimate } from "@visactor/vrender-animate";
import { getArcsFromCircles, getCirclesFromArcs, getPathFromArcs } from "@visactor/vlayouts";
import { Factory } from "../../core/factory";
export const vennCirclePresetAnimation = preset => {
switch (preset) {
case "fadeIn":
default:
return {
type: "fadeIn"
};
case "growIn":
return {
type: "growRadiusIn"
};
case "scaleIn":
return {
type: "scaleIn"
};
}
};
export const vennOverlapPresetAnimation = preset => {
switch (preset) {
case "fadeIn":
default:
return {
type: "fadeIn"
};
case "scaleIn":
return {
type: "scaleIn"
};
}
};
export class VennOverlapAnimation extends ACustomAnimate {
onBind() {
var _a, _b;
this.fromCircles = {}, null === (_a = getCirclesFromArcs(this.target.attribute.arcs)) || void 0 === _a || _a.forEach((c => {
this.fromCircles[c.setId] = c;
})), this.toCircles = {}, null === (_b = getCirclesFromArcs(this.target.getFinalAttribute().arcs)) || void 0 === _b || _b.forEach((c => {
this.toCircles[c.setId] = c;
}));
}
onUpdate(end, ratio, out) {
const circles = [];
Object.keys(this.fromCircles).forEach((key => {
const fromC = this.fromCircles[key], toC = this.toCircles[key];
fromC && toC && circles.push({
radius: fromC.radius + (toC.radius - fromC.radius) * ratio,
x: fromC.x + (toC.x - fromC.x) * ratio,
y: fromC.y + (toC.y - fromC.y) * ratio,
setId: key
});
}));
const arcs = getArcsFromCircles(circles);
this.target.setAttributes({
arcs: arcs,
path: getPathFromArcs(arcs)
});
}
}
export const registerVennAnimation = () => {
Factory.registerAnimation("vennCircle", ((params, preset) => ({
appear: vennCirclePresetAnimation(preset),
enter: {
type: "growRadiusIn"
},
exit: {
type: "growRadiusOut"
},
disappear: {
type: "growRadiusOut"
}
}))), Factory.registerAnimation("vennOverlap", ((params, preset) => ({
appear: vennOverlapPresetAnimation(preset),
update: {
custom: VennOverlapAnimation
},
enter: {
type: "fadeIn"
},
exit: {
type: "fadeOut"
},
disappear: {
type: "fadeOut"
}
})));
};
//# sourceMappingURL=animation.js.map