|
function portAttr(otherPortAttr, ports, count = 1) {
return {
groups: {
output: {
position: { name: 'right' },
attrs: {
circle: {
r: 5,
magnet: true,
stroke: '#B1B1B1',
strokeWidth: 1,
fill: '#B1B1B1',
connectionCount: count,
...otherPortAttr
}
}
},
input: {
position: { name: 'left' },
attrs: {
circle: {
r: 5,
magnet: true,
stroke: '#B1B1B1',
strokeWidth: 1,
fill: '#B1B1B1',
connectionCount: 100,
refX: 10,
refY: -10
}
}
}
},
items: ports
};
}
export class CreateNodeClass {
constructor(node, graph, target) {
// this.type = type;
this.graph = graph;
this.target = target;
this.node = node;
}
// 创建只出不入节点(start)
createStartNode() {
const node = this.graph.createNode({
shape: this.node,
width: 96,
height: 86,
data: this.target,
ports: portAttr({ refX: -4, refY: -10 }, [{ group: 'output' }], 100)
});
return node;
}
// 创建只入不出节点(end)
createEndNode() {
return this.graph.createNode({
shape: this.node,
width: 96,
height: 86,
data: this.target,
ports: portAttr({ refX: -4, refY: -10 }, [{ group: 'input' }])
});
}
// 创建普通输入输出节点(normal)
createNormalNode() {
return this.graph.createNode({
shape: this.node,
width: 96,
height: 86,
data: this.target,
ports: portAttr({ refX: -4, refY: -10 }, [
{ group: 'input' },
{ group: 'output' }
])
});
}
// 创建一入多出节点(branch)
createBranchNode() {
return this.graph.createNode({
shape: this.node,
width: 200,
height: 36,
data: this.target,
ports: {
groups: {
output: {
id: 'default',
position: { name: 'right' },
attrs: {
circle: {
r: 5,
magnet: true,
stroke: '#B1B1B1',
strokeWidth: 1,
fill: '#B1B1B1',
connectionCount: 1,
refX: -15,
refY: 0
}
}
},
input: {
position: { name: 'left' },
attrs: {
circle: {
r: 5,
magnet: true,
stroke: '#B1B1B1',
strokeWidth: 1,
fill: '#B1B1B1',
connectionCount: 100,
refX: 0,
refY: 0
}
}
}
},
items: [{ group: 'input' }, { group: 'output' }]
}
});
}
}
|