尝试通过左侧对齐任何节点时组的布局不正确

时间:2019-06-13 11:01:52

标签: javascript gojs

我想按组内的左侧和右侧对齐某些节点(有特定类型)。当我向组中添加一个应按左侧对齐的节点时,布局出现问题: one node aligned by left side

但是如果我添加第二个应该在右侧对齐的节点,或者删除所有节点,则组的布局是正确的,并且它们在屏幕的左侧对齐。有两个节点: two nodes

无节点:

without nodes

这是我的小组的模板:

$(go.Group, "Auto",
  {
    layout: $(go.LayeredDigraphLayout, {
          direction: 0,
          columnSpacing: 10,
          initializeOption: go.LayeredDigraphLayout.InitDepthFirstOut,
          aggressiveOption: go.LayeredDigraphLayout.AggressiveMore
        }),
    minSize: new go.Size(800, 30),
    computesBoundsIncludingLocation: true,
    computesBoundsIncludingLinks: true,
    computesBoundsAfterDrag: true,
    isSubGraphExpanded: true,
  },
  $(go.Shape, "Rectangle", [
      {
          fill: null,
          stroke: "gray",
          strokeWidth: 2
      },
      new go.Binding('fill', '', function (group) {
          return group.data.isEditable ? '#eee' : '#F7EAEC';
      }).ofObject('')
  ]),
  $(go.Panel, "Vertical",
      { defaultAlignment: go.Spot.Left, margin: 4 },
      $(go.Panel, "Horizontal",
          { defaultAlignment: go.Spot.Top },
          $(go.TextBlock,
              { font: "Bold 18px Sans-Serif", margin: 4, textAlign: "left" },
              new go.Binding("text", "name"))
      ),
      $(go.Placeholder,
          { padding: new go.Margin(10, 10), margin: 0 })
  )
)

要左对齐节点,我只需在 LayoutCompleted 事件上为零件设置新位置:

var viewportBounds = event.diagram.viewportBounds.copy(); 
var yPosition = part.location.y;
var xPosition = viewportBounds.x > 15 ? 5 : viewportBounds.x; // some margin for left
part.location = new go.Point(xPosition, yPosition);

对于解决此问题的任何帮助,我们将不胜感激。

0 个答案:

没有答案