用于JointJS库的API文档在这里:http://www.jointjs.com/api --我对带有端口的元素使用了DEVS插件。
我需要限制从一个端口到一个端口的连接数。
一旦从端口创建了链接,除非删除现有连接,否则用户不应该能够从同一个端口启动连接。
在库本身没有代码更改的情况下,有可能吗?
即使在查看了API文档和代码本身之后,我也无法获得实现此需求的钩子/入口点。如有任何帮助或指示,我们将不胜感激。
PS:
发布于 2014-05-30 10:02:47
它就像从图中获取元素并在其上设置某些属性一样简单。
var source = graph.getCell(sourceId);
source.attr('.outPorts circle/magnet', 'passive')发布于 2016-01-13 22:22:11
我一整天都在为这个而挣扎。把磁铁设为无源对我来说还不够好。在深入挖掘源代码之后,我最终得到的结果是使用了纸张对象的validateMagnet函数。我从磁铁中获取端口,然后从源模型获得所有出站链接。如果任何链接使用的是相同的点,我拒绝验证。下面是代码:
validateMagnet: function(cellView, magnet) {
// Prevent links from ports that already have a link
var port = magnet.getAttribute('port');
var links = graph.getConnectedLinks(cellView.model, { outbound: true });
var portLinks = _.filter(links, function(o) {
return o.get('source').port == port;
});
if(portLinks.length > 0) return false;
// Note that this is the default behaviour. Just showing it here for reference.
// Disable linking interaction for magnets marked as passive (see below `.inPorts circle`).
return magnet.getAttribute('magnet') !== 'passive';
},https://stackoverflow.com/questions/23950939
复制相似问题