@antv/g6
Version:
graph visualization frame work
76 lines (72 loc) • 1.77 kB
JavaScript
/**
* @fileOverview layout mixin
* @author huangtonger@aliyun.com
*/
var Util = require('../util/');
var Layout = require('../controller/layout');
var Mixin = {};
Mixin.CFG = {
/**
* Layout cfg
* @type {object|function|undefined}
*/
layout: undefined
};
Mixin.INIT = '_initLayout';
Mixin.AUGMENT = {
_initLayout: function _initLayout() {
var controllers = this.get('_controllers');
var layoutCfg = this._getLayoutCfg();
if (layoutCfg) {
controllers.layout = new Layout(Util.mix({
graph: this
}, layoutCfg));
}
},
_getLayoutCfg: function _getLayoutCfg() {
var layout = this.get('layout');
if (Util.isPlainObject(layout)) {
return layout;
} else if (Util.isFunction(layout) || Util.isObject(layout)) {
return {
processer: layout
};
}
return null;
},
layout: function layout() {
this._getController('layout').layout();
return this;
},
/**
* @return {Graph} this
*/
updateNodePosition: function updateNodePosition() {
var nodes = this.getNodes();
var groups = this.getGroups();
var edges = this.getEdges();
var guides = this.getGuides();
nodes.forEach(function (node) {
node.layoutUpdate();
});
groups.forEach(function (group) {
group.layoutUpdate();
});
edges.forEach(function (edge) {
edge.layoutUpdate();
});
guides.forEach(function (guide) {
guide.layoutUpdate();
});
this.draw();
return this;
},
changeLayout: function changeLayout(processer) {
this._getController('layout').changeLayout(processer);
return this;
},
getLayout: function getLayout() {
return this._getController('layout').getLayoutProcesser();
}
};
module.exports = Mixin;