简体   繁体   English

使用 GoJS 更改链接上面板的 zOrder

[英]Changing the zOrder of a Panel on a Link with GoJS

I am trying to configure my GoJS diagram (using LayeredDiagraphLayout) such that the panels showing a link's label (in this example it displays a percentage) is always at the foreground, in front of all other items on the diagram.我正在尝试配置我的 GoJS 图(使用 LayeredDiagraphLayout),以便显示链接的 label 的面板(在此示例中显示百分比)始终位于前景,在图表上的所有其他项目之前。 Currently, it is displaying with some link lines in front of the panels (as shown in this image):目前,它在面板前面显示了一些链接线(如图所示): 图表示例

My goal:我的目标:

To ensure that panels displaying percentages are always visible in front of everything else.确保显示百分比的面板始终在其他所有内容之前可见。

What I've Tried So Far:到目前为止我尝试过的:

Bringing the links into the Foreground layer (as suggested here ):将链接带入前景层(如此建议):

myDiagram.linkTemplate =
  $$(go.Link,
    { routing: go.Link.AvoidsNodes, curve: go.Link.JumpGap, corner: 5, layerName:"Foreground" },
    $$(go.Shape, { strokeWidth: 3, stroke: "#555" }),
    $$(go.Panel, "Auto", // this whole Panel is a link label
      $$(go.Shape, "RoundedRectangle", { fill: "lightgray", stroke: "gray" }),
      $$(go.TextBlock, { margin: 3 },
        new go.Binding("text", "ownership"))
    )
  );

Assigning a zOrder directly to the go.Panel , go.Shape , and go.TextBlock items seen in the code above, however, all gave errors like this: Uncaught Error: Trying to set undefined property "zOrder" on object: Shape(RoundedRectangle) . Assigning a zOrder directly to the go.Panel , go.Shape , and go.TextBlock items seen in the code above, however, all gave errors like this: Uncaught Error: Trying to set undefined property "zOrder" on object: Shape(RoundedRectangle) . According to the documentation , Part extends Panel , so I expected that I would be able to assign a zOrder to a Panel , but it is giving this error, so apparently my expectations were wrong.根据文档Part扩展Panel ,所以我希望我能够将zOrder分配给Panel ,但它给出了这个错误,所以显然我的期望是错误的。

How can I configure this diagram such that the Panel on the Link is always at the foreground and therefore always visible in front of everything else?如何配置此图表,使链接上的面板始终位于前台,因此始终在其他所有内容的前面可见? Thank you!谢谢!

See https://forum.nwoods.com/t/changing-zorder-for-panel-on-link-on-layereddiagraphlayout/13714 for a discussion.有关讨论,请参阅https://forum.nwoods.com/t/changeing-zorder-for-panel-on-link-on-layereddiagraphlayout/13714

Maybe this is what you want, assuming the label is the second element of the Link:也许这就是你想要的,假设 label 是链接的第二个元素:

      $(go.Diagram, . . .,
        {
          layout: $(go.LayeredDigraphLayout, { direction: 90, . . . }),
          "LayoutCompleted": function(e) {
            e.diagram.links.each(function(l) { l.elt(1).segmentIndex = -Infinity; });
            e.diagram.nodes.each(function(n) {
              var outs = n.findLinksOutOf();
              var ins = n.findLinksInto();
              if (outs.count === 1) outs.first().elt(1).segmentIndex = 1;
              else if (ins.count === 1) ins.first().elt(1).segmentIndex = -2;
            });
          },
          . . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM