2

我正在实现 GOJS 图表链接,如下面的链接所示

http://gojs.net/latest/samples/treeMapper.html

我的问题是,如果左侧/右侧的任何元素已经有链接连接,是否可以不允许重复链接?

根据您最初的回答,我更新了 nodeTemplate 的代码,如下所示

 myDiagram.nodeTemplate =
              $(TreeNode,
                { movable: false },  // user cannot move an individual node
                // no Adornment: instead change panel background color by binding to Node.isSelected
                { selectionAdorned: false },
                { fromLinkable: true, toLinkable: true,fromMaxLinks: 1,toMaxLinks:1 },  // user can draw link to and from such tree nodes
                $("TreeExpanderButton",  // support expanding/collapsing subtrees
                  { width: 14, height: 14,
                    "ButtonIcon.stroke": "black",
                    "ButtonIcon.strokeWidth": 2,
                    "ButtonBorder.fill": "whitesmoke",
                    "ButtonBorder.stroke": "black",
                    "ButtonBorder.figure": "Rectangle"
                  }),
                $(go.Panel, "Horizontal",
                  { position: new go.Point(16, 0) },
                  new go.Binding("background", "isSelected", function(s) { return (s ? "lightblue" : "white"); }).ofObject(),

                  $(go.TextBlock,{ font: '9pt Verdana, sans-serif' },
                    new go.Binding("text", "Data", function(s) { return s; }))
                )  // end Horizontal Panel
              );  // end Node

注意:这不仅仅是一个树实现,这是作为记录映射字段的一部分实现的树,如我共享的链接中所示。

我想要的是每个端口在图中不应有多个链接在此处输入图像描述

也就是说,服务参数的集装箱车与设备模型中的任何其他节点的链接不应超过一个。同样,设备模型中的设备不应有多个来自服务参数的链接。对于所有其他节点也是如此。

4

1 回答 1

1

改进checkLink谓词如下: function checkLink(fn, fp, tn, tp, link) { // make sure the nodes are inside different Groups if (fn.containingGroup === null || fn.containingGroup.data.key !== -1) return false; if (tn.containingGroup === null || tn.containingGroup.data.key !== -2) return false; // optional limit to a single mapping link per node if (fn.linksConnected.any(function(l) { return l.category === "Mapping"; })) return false; if (tn.linksConnected.any(function(l) { return l.category === "Mapping"; })) return false; return true; }

并将节点模板更改为更智能地了解 and 的值fromLinkabletoLinkable而不是盲目地将它们设置为 true: // whether the user can start drawing a link from or to this node depends on which group it's in new go.Binding("fromLinkable", "group", function(k) { return k === -1; }), new go.Binding("toLinkable", "group", function(k) { return k === -2; }), 不要费心使用fromMaxLinksandtoMaxLinks属性,因为这无法区分 Tree Mapper 示例使用的不同类型的链接。

阅读更多相关信息: http: //gojs.net/latest/intro/validation.htmlhttp://gojs.net/latest/intro/ports.html

于 2016-06-30T19:28:16.160 回答