G6.registerEdge('multipleLabelsEdge', {
drawShape(cfg, group) {
const startPoint = cfg.startPoint;
const endPoint = cfg.endPoint;
const stroke = (cfg.style && cfg.style.stroke) || '#000';
const endArrow = (cfg.style && cfg.style.endArrow) || undefined;
const middlePoint = startPoint.y + Math.abs(startPoint.y - endPoint.y) / 2;
console.log(cfg);
let controlPoints = [];
if (cfg.controlPoints) {
controlPoints = cfg.controlPoints.map(point => ['L', point.x, point.y]);
}
const shape = group.addShape('path', {
attrs: {
stroke,
path: [
['M', startPoint.x, startPoint.y],
...controlPoints,
['L', endPoint.x, endPoint.y]
],
endArrow
},
name: 'path-shape'
});
if (cfg.primaryLabel) {
group.addShape('text', {
attrs: {
text: cfg.primaryLabel,
fill: '#595959',
textAlign: 'center',
fontSize: 10,
x: endPoint.x,
y: middlePoint + 2
},
name: 'top-text-shape'
});
}
if (cfg.secondaryLabel) {
group.addShape('text', {
attrs: {
text: cfg.secondaryLabel,
fill: '#595959',
fontSize: 8,
textAlign: 'center',
x: endPoint.x,
y: middlePoint + 10
},
name: 'bottom-text-shape'
});
}
return shape;
}
})