【问题标题】:Links label are overlapped between each other链接标签彼此重叠
【发布时间】:2019-09-23 19:05:19
【问题描述】:

我创建了两个正方形,并通过端口将它们连接起来。但是当我创建两个以上的链接时,它们的链接标签开始重叠(您可以在下面的屏幕截图中看到这一点)。 GoJS 是否有一些选项可以正确对齐或分隔标签?

【问题讨论】:

  • 请编辑您的帖子并在您的问题中添加您的示例代码。
  • @novonimo,我只是在询问 goJS 的可能性。 goJS 可以做这些事情吗?如果您对此有所了解,请分享此信息。

标签: javascript gojs


【解决方案1】:

我认为问题可能在于您使用了多个端口。假设端口位于节点的一侧,则链接可以与节点连接的位置没有太多选择。

相反,具有单个端口的节点的默认行为可能是您正在寻找的:

  function init() {
    var $ = go.GraphObject.make;

    myDiagram =
      $(go.Diagram, "myDiagramDiv");

    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        new go.Binding("location"),
        $(go.Shape,
          { fill: "white", portId: "" },
          new go.Binding("fill", "color")),
        $(go.TextBlock,
          { margin: 8 },
          new go.Binding("text"))
      );

    myDiagram.linkTemplate =
      $(go.Link,
        //{ curve: go.Link.Bezier },
        $(go.Shape),
        $(go.Shape, { toArrow: "OpenTriangle" }),
        $(go.TextBlock, { background: "white" },
          new go.Binding("text"))
      );

    myDiagram.model = new go.GraphLinksModel(
    [
      { key: 1, text: "Alpha", color: "lightblue", location: new go.Point(0, 0) },
      { key: 2, text: "Beta", color: "orange", location: new go.Point(200, 50) },
      { key: 3, text: "Gamma", color: "lightgreen", location: new go.Point(50, 200) }
    ],
    [
      { from: 1, to: 2, text: "12" },
      { from: 1, to: 2, text: "a long label" },
      { from: 2, to: 1, text: "345" },
      { from: 1, to: 3, text: "13" },
      { from: 1, to: 3, text: "short" },
      { from: 3, to: 1, text: "34567890" }
    ]);
  }

产生:

或者如果您指定贝塞尔曲线链接:

移动节点,您可以看到链接之间的距离如何根据链接标签的宽度而变化,因为标签不是圆形的。

【讨论】:

  • 是的,我们发现当我们使用多个端口时,我们的链接没有曲线。但是当我们将它们连接到一个端口时,一切正常。
猜你喜欢
  • 1970-01-01
  • 2019-01-07
  • 1970-01-01
  • 2021-10-25
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-20
相关资源
最近更新 更多