当actor或useCase被拖动时,您可以通过重新定位连接线来保持actor+useCase的连接。
假设您有 3 个动力学节点或组:
- 演员节点,
- 一个用例节点,
- 专用于连接它们的动力线。
为actor和useCase设置dragmove事件处理程序。
// when the actor is dragged, reposition the connecting line
actor.on('dragmove', function () {
connectThem(actor,useCase,connectingLine);
});
// when the useCase is dragged, reposition the connecting line
useCase.on('dragmove', function () {
connectThem(actor,useCase,connectingLine);
});
在 dragmove 处理程序中,获取 actor 和 useCase 的位置并重新定位连接线。
// reposition the line to connect the actor & useCase
function connectThem(actor,useCase,connectingLine){
// get the XY of the actor+useCase to connect
var x1 = actor.getX();
var y1 = actor.getY();
var x2 = useCase.getX();
var y2 = useCase.getY();
// reposition the connecting line
connectingLine.setPoints([x1,y1,x2,y2]);
// send the connecting line to the back
connectingLine.setZIndex(0);
// redraw the layer
layer.draw();
};