我试图用GoJS库绘制嵌套形状。现在我有一条长方形,里面只有一行。整个对象是一个有两个形状的面板,一个矩形和一个减号线。此时它很好,MinusLine呈现在矩形的中心。
我想要实现的是定位/改变位置的MinusLine从上到下,等等,基于某些条件,但我不能移动它的任何方式。例如,将完全居中的黄线移动到红色或棕色的位置。
代码看起来如下:
GO(go.Node, "Table",
{
layerName: "AfterForeground",
movable: false,
locationObjectName: "BODY",
locationSpot: go.Spot.parse("0.5 0 0 0 "),
selectionObjectName: "MAIN_SHAPE",
selectionObjectName: "MAIN_SHAPE",
},
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
GO(go.Panel,go.Panel.Position, "Auto", {
row: 1,
column: 1,
name: "BODY",
stretch: go.GraphObject.Fill
},
GO(go.Shape, "Rectangle", {
fill: wellColor,
name: "MAIN_SHAPE",
stroke: myColor,
strokeWidth: 0.4,
}, new go.Binding("fill", "wellColor"),
) , new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify)
,GO(go.Shape, "MinusLine", {}), // <-- Move this YELLOW line vertically somehere inside Rectangle
)
发布于 2020-10-15 12:54:01
表面板(节点的面板类型)真的是您想要的吗?
到目前为止,您有一个只有一个单元格的表面板,默认情况下,单元格中的所有对象都将位于中间。通过将alignment
属性添加到元素中,可以轻松地移动它们。
下面是您的表的一个示例,其中两个子面板添加到节点,一个与顶部对齐,一个与中心对齐,y偏移量为30:https://codepen.io/simonsarris/pen/zYBrLaX?editors=1011
表面板的其他定位示例如下:
https://gojs.net/latest/intro/tablePanels.html
https://gojs.net/latest/intro/tablePanels.html#StretchAndAlignmente
注意,由于您已经定义了模板,该形状占用了表的整个空间,形状的中心有一条减号行。这可能不是你想要的。我在形状上放了一个宽度和高度,在桌子上放了一个(更大的)高度来做示范legibile。
https://stackoverflow.com/questions/64366289
复制相似问题