我使用的 goJS 代码与此链接页面完全相同 http://gojs.net/temp/swimBands2.html
当节点很简单时看起来不错,但是当每个节点内绑定(bind)大量数据时,似乎无法显示标题。我必须缩小才能看到它。
有人可以帮我做什么吗?
我将代码修改如下
myDiagram.nodeTemplateMap.add("VerticalBands",
$(go.Part, "Position",
{
isLayoutPositioned: false, // but still in document bounds
locationSpot: new go.Spot(0, 0, 0, 16), // account for header height
layerName: "Grid", // not pickable, not selectable
itemTemplate:
$(go.Panel, "Vertical",
new go.Binding("opacity", "visible", function(v) { return v ? 1 : 0; }),
new go.Binding("position", "bounds", function(b) {b.position.y+= 30;return b.position; }),
$(go.TextBlock,
{
stretch: go.GraphObject.Horizontal,
textAlign: "center",
wrap: go.TextBlock.None,
font: "bold 11pt sans-serif",
background: $(go.Brush, go.Brush.Linear, { 0: "lightgray", 1: "whitesmoke" })
},
new go.Binding("text"),
new go.Binding("width", "bounds", function(r) { return r.width; })),
// for separator lines:
//$(go.Shape, "LineV",
// { stroke: "gray", alignment: go.Spot.Left, width: 1 },
// new go.Binding("height", "bounds", function(r) { return r.height; }),
// new go.Binding("visible", "itemIndex", function(i) { return i > 0; }).ofObject()),
// for rectangular bands:
$(go.Shape,
{ stroke: null, strokeWidth: 0 },
new go.Binding("desiredSize", "bounds", function(r) { return r.size; }),
new go.Binding("fill", "itemIndex", function(i) { return i % 2 == 0 ? "white" : "lightgray"; }).ofObject())
)
},
new go.Binding("itemArray")
));
我将locationSpot修改为新的go.Spot(0,0,0,-8),标题下降,但节点的位置保持不变。
最佳答案
这是因为保存“带”的部件位于“网格”层中,而位于该层中的部件不在 包含在 Diagram.documentBounds 中,因此用户(默认情况下)无法滚动超出文档边界。
有多种可能的解决方案,具体取决于您希望允许用户执行的操作。
您可以将 Diagram.scrollMode 设置为 go.Diagram.InfiniteScroll
,这样用户就可以滚动到任意位置。但我不知道您是否愿意允许这样做——用户可能会迷失方向。
或者,您可以修改“网格”图层:
myDiagram.findLayer("Grid").isBoundsInincluded = true;
以便该层中的部分自动包含在 Diagram.documentBounds 中。如果该层中有其他任何内容,这可能是理想的,也可能不是理想的。
或者,您可以将该“VerticalBands”部件放入普通图层中,并使其不可拾取或可选择:
图层名称:“背景”,
可选:假,
可挑选:假,
如果您使用“背景”层来容纳其他部件,则这是不太理想的。
关于javascript - goJS背景层不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35008703/