是否可以控制GOJS

时间:2016-06-30 18:19:39

标签: gojs

我正在实施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

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

我想要的是每个端口在图enter image description here

中不应该有多个链接

即服务参数的集装箱车不应该有多个链接到设备模型中的任何其他节点。类似设备模型中的设备不应具有来自服务参数的多个链接。同样适用于所有其他节点。

1 个答案:

答案 0 :(得分: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; }

并更改节点模板以更加智能地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; }), 不要使用fromMaxLinkstoMaxLinks属性,因为这不区分Tree Mapper示例使用的不同类型的链接。

详情请参阅:http://gojs.net/latest/intro/validation.htmlhttp://gojs.net/latest/intro/ports.html