@antv/g6
Version:
graph visualization frame work
89 lines (84 loc) • 2.41 kB
JavaScript
/**
* @fileOverview animate mixin
* @author huangtonger@aliyun.com
*/
var Util = require('../util/');
var Animate = require('../controller/animate');
var Mixin = {};
Mixin.INIT = '_initAnimate';
Mixin.CFG = {
/**
* animate switch
* @type {boolean}
*/
animate: false,
/**
* animate force prevent
* @type {boolean}
*/
forcePreventAnimate: false,
_enterAnimate: function _enterAnimate(item) {
var group = item.getGraphicGroup();
var matrix = group.getMatrix();
var box = Util.getBBox(group, matrix); // need apply self matrix
var centerX = (box.minX + box.maxX) / 2;
var centerY = (box.minY + box.maxY) / 2;
Util.scaleIn(group, centerX, centerY);
},
_leaveAnimate: function _leaveAnimate(item) {
var group = item.getGraphicGroup();
var matrix = group.getMatrix();
var box = Util.getBBox(group, matrix); // need apply self matrix
var centerX = (box.minX + box.maxX) / 2;
var centerY = (box.minY + box.maxY) / 2;
Util.scaleOut(group, centerX, centerY);
}
};
Mixin.AUGMENT = {
_initAnimate: function _initAnimate() {
var _this = this;
var controllers = this.get('_controllers');
var animate = this.get('animate');
var canvas = this.get('_canvas');
var frontCanvas = this.get('_frontCanvas');
var animateController = void 0;
if (animate) {
animateController = new Animate({
canvases: [canvas, frontCanvas],
graph: this
});
controllers.animate = animateController;
}
var simpleDraw = function simpleDraw() {
canvas.draw();
frontCanvas.draw();
};
var animateDraw = Util.debounce(function () {
animateController.run();
}, 16);
if (animateController) {
var updateStashTimeout = void 0;
this.draw = function () {
var forcePreventAnimate = _this.get('forcePreventAnimate');
if (forcePreventAnimate) {
if (updateStashTimeout) {
clearTimeout(updateStashTimeout);
}
updateStashTimeout = setTimeout(function () {
animateController.updateStash();
}, 16);
simpleDraw();
} else {
animateDraw();
}
};
} else {
this.draw = simpleDraw;
}
},
drawFrontCanvas: function drawFrontCanvas() {
var frontCanvas = this.get('_frontCanvas');
frontCanvas.draw();
}
};
module.exports = Mixin;