如何在JointJS中交互式地创建链接
How to interactively create links in JointJS
我想以交互方式添加链接到我的基于JointJS的图形。
我的想法是在pointerdown
上创建一个小的临时节点,从原始节点到这个临时节点的链接,将它拖到另一个节点的顶部,并在pointerup
上创建真正的链接,删除临时链接和节点。
不幸的是,我不知道如何说服指针移动临时元素,而不是pointerdown
事件发生的节点。任何想法?谢谢!
var tmp_obj;
paper.on('cell:pointerdown', function(cellView, evt, x, y) {
if(evt.button == 1) {
// Freeze the selected node so it does not move
paper.findViewByModel(cellView.model).options.interactive = false;
// Create a small temporary node on top of the selected node
tmp_obj = new joint.shapes.basic.Rect({
position: { x: x, y: y },
size: { width: 5, height: 5 }
}
// Create the link between the original node and the small temporary node
// And now?
}
}
paper.on('cell:pointerup', function(cellView, evt, x, y) {
if(evt.button == 1) {
// Unfreeze the origin node
paper.findViewByModel(cellView.model).options.interactive = true;
// Delete the temporary object (and temporary link)
tmp_obj.remove()
// Find the first element below that is not a link nor the dragged element itself.
var elementBelow = graph.get('cells').find(function(cell) {
if (cell instanceof joint.dia.Link) return false; // Not interested in links.
if (cell.id === cellView.model.id) return false; // The same element as the dropped one.
if (cell.getBBox().containsPoint(g.point(x, y))) {
return true;
}
return false;
});
// create the link from cellView to elementBelow
}
});
也许你可以使用JointJS的磁铁特性?如果在JointJS元素的SVG子元素上设置magnet: true
,则该元素将变为活动元素,并允许用户从该元素开始创建链接。例如:
var r = new joint.shapes.basic.Rect({
position: { x: 50, y: 50 },
size: { width: 100, height: 40 },
attrs: { text: { text: 'basic.Rect', magnet: true } }
});
这将使元素表现得像一个端口。
防止悬垂链接:
joint.dia.Paper({ linkPinning: false })
这是一个很好的解决方案。
可以组合
linkView.startArrowheadMove('target');
和
evt.data.view.pointermove(evt, p.x, p.y);
相关文章:
- 使用jQuery迭代数组以创建链接
- 如何在jQuery中以有效的方式创建链接
- 使用其他页面上表单的文本创建链接
- 传单:如何在弹出窗口中创建链接选择器
- 用JavaScript创建链接,并将其集成到createTextNode()中
- 如何为图像的某些部分创建链接
- 如何使用onClick处理程序在React组件中创建链接
- Chrome扩展,从正文中的关键词创建链接
- 根据用户从jQuery UI可选下拉框中选择的内容创建链接
- 在列表中创建链接
- 如何在javascript中创建链接
- 正在节点d3.js之间创建链接,当前返回Uncaught TypeError:无法读取属性'weight'
- 使用 reactjs 创建链接的覆盖
- 如何基于URL的一部分为表中已有的每个链接创建链接
- 基于 Html 表单中的值创建链接,并将其重定向到该链接
- 为字母表中的所有字母创建链接
- 在角度中,创建链接中没有 # 且不修改服务器的 spa
- 无法让javascript从XML列表正确创建链接
- 如何使用 JSON 创建链接,单击这些链接时会显示在单独的
- 如何创建链接/按钮,该链接/按钮将导航到jquery移动页面之外的页面