UNPKG

@antv/g6

Version:

graph visualization frame work

79 lines (76 loc) 2.33 kB
/** * @fileOverview group shapes * @author huangtonger@aliyun.com */ var Shape = require('../shape'); var Util = require('../../util/'); var Global = require('../../global'); Shape.registerGroup('common', { draw: function draw(item) { var model = item.getModel(); if (model.collapsed) { return this.drawCollapsed(item); } return this.drawExpanded(item); }, getLabel: function getLabel(item) { var model = item.getModel(); return model.label; }, drawLabel: function drawLabel(item, x, y) { var label = this.getLabel(item); if (!label) { return; } var group = item.getGraphicGroup(); var margin = [8, 8]; var attrs = Util.mix(true, {}, Global.labelStyle, { x: x + margin[0], y: y + margin[1], textAlign: 'left', textBaseline: 'top' }); if (!Util.isObject(label)) { attrs.text = label; } else { Util.mix(attrs, label); } group.addShape('text', { attrs: attrs }); }, drawKeyShape: function drawKeyShape(item, x, y, width, height) { var model = item.getModel(); var group = item.getGraphicGroup(); var attrs = Util.mix({}, Global.groupStyle, model.style); var path = Util.getRectPath(x, y, width, height, attrs.radius); return group.addShape('path', { attrs: Util.mix({}, attrs, { path: path }) }); }, drawExpanded: function drawExpanded(item) { var box = item.getChildrenBBox(); var x = box.minX - Global.groupBackgroundPadding[3]; var y = box.minY - Global.groupBackgroundPadding[0]; var width = box.maxX - box.minX + Global.groupBackgroundPadding[3] + Global.groupBackgroundPadding[1]; var height = box.maxY - box.minY + Global.groupBackgroundPadding[0] + Global.groupBackgroundPadding[2]; var keyShape = this.drawKeyShape(item, x, y, width, height); this.drawLabel(item, x, y); return keyShape; }, drawCollapsed: function drawCollapsed(item) { var box = item.getChildrenBBox(); var x = box.minX - Global.groupBackgroundPadding[3]; var y = box.minY - Global.groupBackgroundPadding[0]; var width = 184; var height = 40; var keyShape = this.drawKeyShape(item, x, y, width, height); this.drawLabel(item, x, y); return keyShape; }, anchor: { intersectBox: 'rect' } });