- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs
Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
209 lines
6.3 KiB
JavaScript
209 lines
6.3 KiB
JavaScript
import { __assign, __rest } from "tslib";
|
||
import { registerNode, BaseGlobal as Global } from '@antv/g6-core';
|
||
import { mix } from '@antv/util';
|
||
/**
|
||
* 基本的椭圆,可以添加文本,默认文本居中
|
||
*/
|
||
registerNode('ellipse', {
|
||
// 自定义节点时的配置
|
||
options: {
|
||
size: [80, 40],
|
||
style: {
|
||
x: 0,
|
||
y: 0,
|
||
stroke: Global.defaultNode.style.stroke,
|
||
fill: Global.defaultNode.style.fill,
|
||
lineWidth: Global.defaultNode.style.lineWidth
|
||
},
|
||
// 文本样式配置
|
||
labelCfg: {
|
||
style: {
|
||
fill: Global.nodeLabel.style.fill,
|
||
fontSize: Global.nodeLabel.style.fontSize,
|
||
fontFamily: Global.windowFontFamily
|
||
}
|
||
},
|
||
// 节点上左右上下四个方向上的链接circle配置
|
||
linkPoints: {
|
||
top: false,
|
||
right: false,
|
||
bottom: false,
|
||
left: false,
|
||
// circle的大小
|
||
size: Global.defaultNode.linkPoints.size,
|
||
lineWidth: Global.defaultNode.linkPoints.lineWidth,
|
||
fill: Global.defaultNode.linkPoints.fill,
|
||
stroke: Global.defaultNode.linkPoints.stroke
|
||
},
|
||
// 节点中icon配置
|
||
icon: {
|
||
// 是否显示icon,值为 false 则不渲染icon
|
||
show: false,
|
||
// icon的地址,字符串类型
|
||
img: 'https://gw.alipayobjects.com/zos/bmw-prod/5d015065-8505-4e7a-baec-976f81e3c41d.svg',
|
||
width: 20,
|
||
height: 20
|
||
},
|
||
stateStyles: __assign({}, Global.nodeStateStyles)
|
||
},
|
||
shapeType: 'ellipse',
|
||
// 文本位置
|
||
labelPosition: 'center',
|
||
drawShape: function drawShape(cfg, group) {
|
||
var _a = (this.mergeStyle || this.getOptions(cfg)).icon,
|
||
icon = _a === void 0 ? {} : _a;
|
||
var style = this.getShapeStyle(cfg);
|
||
var keyShape = group.addShape('ellipse', {
|
||
attrs: style,
|
||
className: 'ellipse-keyShape',
|
||
name: 'ellipse-keyShape',
|
||
draggable: true
|
||
});
|
||
group['shapeMap']['ellipse-keyShape'] = keyShape;
|
||
var width = icon.width,
|
||
height = icon.height,
|
||
show = icon.show,
|
||
text = icon.text;
|
||
if (show) {
|
||
if (text) {
|
||
group['shapeMap']["".concat(this.type, "-icon")] = group.addShape('text', {
|
||
attrs: __assign({
|
||
x: 0,
|
||
y: 0,
|
||
fontSize: 12,
|
||
fill: '#000',
|
||
stroke: '#000',
|
||
textBaseline: 'middle',
|
||
textAlign: 'center'
|
||
}, icon),
|
||
className: "".concat(this.type, "-icon"),
|
||
name: "".concat(this.type, "-icon"),
|
||
draggable: true
|
||
});
|
||
} else {
|
||
group['shapeMap']["".concat(this.type, "-icon")] = group.addShape('image', {
|
||
attrs: __assign({
|
||
x: -width / 2,
|
||
y: -height / 2
|
||
}, icon),
|
||
className: "".concat(this.type, "-icon"),
|
||
name: "".concat(this.type, "-icon"),
|
||
draggable: true
|
||
});
|
||
}
|
||
}
|
||
this.drawLinkPoints(cfg, group);
|
||
return keyShape;
|
||
},
|
||
/**
|
||
* 绘制节点上的LinkPoints
|
||
* @param {Object} cfg data数据配置项
|
||
* @param {Group} group Group实例
|
||
*/
|
||
drawLinkPoints: function drawLinkPoints(cfg, group) {
|
||
var _a = (this.mergeStyle || this.getOptions(cfg)).linkPoints,
|
||
linkPoints = _a === void 0 ? {} : _a;
|
||
var top = linkPoints.top,
|
||
left = linkPoints.left,
|
||
right = linkPoints.right,
|
||
bottom = linkPoints.bottom,
|
||
markSize = linkPoints.size,
|
||
markR = linkPoints.r,
|
||
markStyle = __rest(linkPoints, ["top", "left", "right", "bottom", "size", "r"]);
|
||
var size = this.getSize(cfg);
|
||
var rx = size[0] / 2;
|
||
var ry = size[1] / 2;
|
||
if (left) {
|
||
// left circle
|
||
group['shapeMap']['link-point-left'] = group.addShape('circle', {
|
||
attrs: __assign(__assign({}, markStyle), {
|
||
x: -rx,
|
||
y: 0,
|
||
r: markSize / 2 || markR || 5
|
||
}),
|
||
className: 'link-point-left',
|
||
name: 'link-point-left',
|
||
isAnchorPoint: true
|
||
});
|
||
}
|
||
if (right) {
|
||
// right circle
|
||
group['shapeMap']['link-point-right'] = group.addShape('circle', {
|
||
attrs: __assign(__assign({}, markStyle), {
|
||
x: rx,
|
||
y: 0,
|
||
r: markSize / 2 || markR || 5
|
||
}),
|
||
className: 'link-point-right',
|
||
name: 'link-point-right',
|
||
isAnchorPoint: true
|
||
});
|
||
}
|
||
if (top) {
|
||
// top circle
|
||
group['shapeMap']['link-point-top'] = group.addShape('circle', {
|
||
attrs: __assign(__assign({}, markStyle), {
|
||
x: 0,
|
||
y: -ry,
|
||
r: markSize / 2 || markR || 5
|
||
}),
|
||
className: 'link-point-top',
|
||
name: 'link-point-top',
|
||
isAnchorPoint: true
|
||
});
|
||
}
|
||
if (bottom) {
|
||
// bottom circle
|
||
group['shapeMap']['link-point-bottom'] = group.addShape('circle', {
|
||
attrs: __assign(__assign({}, markStyle), {
|
||
x: 0,
|
||
y: ry,
|
||
r: markSize / 2 || markR || 5
|
||
}),
|
||
className: 'link-point-bottom',
|
||
name: 'link-point-bottom',
|
||
isAnchorPoint: true
|
||
});
|
||
}
|
||
},
|
||
/**
|
||
* 获取节点的样式,供基于该节点自定义时使用
|
||
* @param {Object} cfg 节点数据模型
|
||
* @return {Object} 节点的样式
|
||
*/
|
||
getShapeStyle: function getShapeStyle(cfg) {
|
||
var defaultStyle = (this.mergeStyle || this.getOptions(cfg)).style;
|
||
var strokeStyle = {
|
||
stroke: cfg.color
|
||
};
|
||
// 如果设置了color,则覆盖默认的stroke属性
|
||
var style = mix({}, defaultStyle, strokeStyle);
|
||
var size = this.getSize(cfg);
|
||
var rx = size[0] / 2;
|
||
var ry = size[1] / 2;
|
||
var styles = __assign({
|
||
x: 0,
|
||
y: 0,
|
||
rx: rx,
|
||
ry: ry
|
||
}, style);
|
||
return styles;
|
||
},
|
||
update: function update(cfg, item, updateType) {
|
||
var group = item.getContainer();
|
||
// 这里不传 cfg 参数是因为 cfg.style 需要最后覆盖样式
|
||
var defaultStyle = this.getOptions({}).style;
|
||
var size = this.getSize(cfg);
|
||
var strokeStyle = {
|
||
stroke: cfg.color,
|
||
rx: size[0] / 2,
|
||
ry: size[1] / 2
|
||
};
|
||
// 与 getShapeStyle 不同在于,update 时需要获取到当前的 style 进行融合。即新传入的配置项中没有涉及的属性,保留当前的配置。
|
||
var keyShape = item.get('keyShape');
|
||
var style = mix({}, defaultStyle, keyShape.attr(), strokeStyle);
|
||
style = mix(style, cfg.style);
|
||
this.updateShape(cfg, item, style, true, updateType);
|
||
this.updateLinkPoints(cfg, group);
|
||
}
|
||
}, 'single-node'); |