I want to interactively add links to my chart based on JointJS.
My idea is to create a small temporary node on pointerdownwith a link from the source node to this temporary node, drag it on top of another node and pointerupcreate a real link that removes the temporary link and node.
Unfortunately, I don’t know how to convince the pointer to move the temporary element, and not the node on which the event occurred pointerdown. Any ideas? Thank!
var tmp_obj;
paper.on('cell:pointerdown', function(cellView, evt, x, y) {
if(evt.button == 1) {
paper.findViewByModel(cellView.model).options.interactive = false;
tmp_obj = new joint.shapes.basic.Rect({
position: { x: x, y: y },
size: { width: 5, height: 5 }
}
}
}
paper.on('cell:pointerup', function(cellView, evt, x, y) {
if(evt.button == 1) {
paper.findViewByModel(cellView.model).options.interactive = true;
tmp_obj.remove()
var elementBelow = graph.get('cells').find(function(cell) {
if (cell instanceof joint.dia.Link) return false;
if (cell.id === cellView.model.id) return false;
if (cell.getBBox().containsPoint(g.point(x, y))) {
return true;
}
return false;
});
}
});
source
share