1

我正在使用与此链接页面http://gojs.net/temp/swimBands2.html完全相同的 goJS 代码

当节点很简单时看起来不错,但是当它在每个节点内绑定大量数据时,似乎无法显示标题。我必须缩小才能看到它。

有人可以帮我做什么吗?

我修改代码如下

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),标题正在下降,但节点的位置保持不变。

在此处输入图像描述

4

1 回答 1

1

这是因为拥有“bands”的部分位于“Grid” Layer中,并且该层中的部分包含在Diagram.documentBounds中,因此用户(默认情况下)无法滚动超出文档边界。

有几种可能的解决方案,具体取决于您希望允许用户执行的操作。

您可以将Diagram.scrollMode设置为go.Diagram.InfiniteScroll,这允许用户在任何他们想要的地方滚动。但我不知道您是否允许这样做——用户可能会迷路。

或者,您可以修改“网格”层: myDiagram.findLayer("Grid").isBoundsIncluded = true; 以便该层中的部分自动包含在Diagram.documentBounds中。如果您在该层中有其他任何东西,那可能是可取的,也可能不是可取的。

或者,您可以将“VerticalBands”部分放在普通图层中,使其不可拾取或可选择: layerName: "Background", selectable: false, pickable: false, 如果您使用“背景”图层来保存其他部分,则不太理想。

于 2016-01-26T23:24:18.210 回答