@antv/g6
Version:
graph visualization frame work
86 lines (70 loc) • 2.83 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
* @fileOverview group item
* @author huangtonger@aliyun.com
*/
var Util = require('../util/');
var Node = require('./node');
var Group = function (_Node) {
_inherits(Group, _Node);
function Group(cfg) {
_classCallCheck(this, Group);
var defaultCfg = {
type: 'group',
isNode: false,
isGroup: true,
zIndex: 1
};
Util.mix(defaultCfg, cfg);
return _possibleConstructorReturn(this, _Node.call(this, defaultCfg));
}
Group.prototype._afterDraw = function _afterDraw() {
var model = this.getModel();
if (model.collapsed) {
this.deepEach(function (child) {
child.hide();
});
}
_Node.prototype._afterDraw.call(this);
};
Group.prototype.updatePosition = function updatePosition() {};
Group.prototype._shouldDraw = function _shouldDraw() {
return true;
};
Group.prototype.getCrossEdges = function getCrossEdges() {
var allChildrenIds = [];
var innerEdges = this.getInnerEdges();
this.deepEach(function (child) {
allChildrenIds.push(child.id);
});
var rst = innerEdges.filter(function (edge) {
var edgeModel = edge.getModel();
return allChildrenIds.indexOf(edgeModel.source) === -1 || allChildrenIds.indexOf(edgeModel.target) === -1;
});
return Util.uniq(rst);
};
Group.prototype.getInnerEdges = function getInnerEdges() {
var edges = [];
this.deepEach(function (child) {
child.getEdges().forEach(function (edge) {
edges.push(edge);
});
});
return Util.uniq(edges);
};
/**
* get children BBox
* @return {object} box
*/
Group.prototype.getChildrenBBox = function getChildrenBBox() {
var children = this.getChildren();
var graphicChildren = children.map(function (child) {
return child.getGraphicGroup();
});
return Util.getChildrenBBox(graphicChildren);
};
return Group;
}(Node);
module.exports = Group;