GoJS没有拉伸形状以适合父

时间:2015-07-28 11:45:14

标签: javascript gojs

我试图在Panel中创建一个标题形状,它再次位于Node内部。 我的代码到目前为止看起来像这样:

var _ = go.GraphObject.make;
var template =
_(go.Node, "Spot",{
    minSize: new go.Size(150, NaN)
    }
    _(go.Panel, go.Panel.Auto,
        _(go.Shape, {
                    figure: "Rectangle",
                    fill: "#ff00ff",
                    stroke: "#000000",
                    strokeWidth: 1,                
                    alignment: new go.Spot(0.5, 0) //aligning it center
            }
        )
    )
);

如果我想尽可能地拉伸元素,我会添加

stretch: go.GraphObject.Fill

或(如果是水平的)

stretch: go.GraphObject.Horizontal

但是Shape会水平拉伸。

到目前为止我还尝试过:

  • 向Panel添加defaultStretch
  • 将defaultStretch添加到节点和面板
  • 更改面板布局(或如果需要,可定位)
  • 更改节点布局(或定位)
  • 在三个组件中的每一个上设置两个维度的minSize或maxSize

我在Gojs网站上做过研究,但只能找到上面提到的东西。

感谢您帮助我

PS:如果需要任何其他信息,我很乐意提供

1 个答案:

答案 0 :(得分:2)

In most cases a Panel should have more than one element in it. In your code you actually have two Panels, each of which has only one element in it. And your code doesn't show any text (there's no TextBlock), so it cannot act as a title.

You haven't said which element it was that you wanted to stretch. Setting GraphObject.stretch is the right thing to do. But sometimes you need to also set it on a Panel, to make sure the Panel is stretched to allow what is inside the panel to be stretched as well.

Panel.defaultStretch is just a way of setting the default value of GraphObject.stretch on each of the elements of the panel.

My guess is that you want to use an "Auto" Panel if you want to have a Shape that is stretched to fit around another object (possibly a TextBlock). This is what you see by default in the Minimal sample as well as many other samples.

If you add: { minSize: new go.Size(150, NaN) }, to the Node template in the Minimal sample, you'll see: Minimal sample with minSize Nodes

Is that what you were looking for? If not, please add a sketch of what you want.