javascript - goJS背景层不显示

标签 javascript jquery gojs

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

enter image description here

最佳答案

这是因为保存“带”的部件位于“网格”中,而位于该层中的部件不在 包含在 Diagram.documentBounds 中,因此用户(默认情况下)无法滚动超出文档边界。

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

您可以将 Diagram.scrollMode 设置为 go.Diagram.InfiniteScroll,这样用户就可以滚动到任意位置。但我不知道您是否愿意允许这样做——用户可能会迷失方向。

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

或者,您可以将该“VerticalBands”部件放入普通图层中,并使其不可拾取或可选择: 图层名称:“背景”, 可选:假, 可挑选:假, 如果您使用“背景”层来容纳其他部件,则这是不太理想的。

关于javascript - goJS背景层不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35008703/

相关文章:

javascript - 类型错误 : Illegal invocation on function alias

jquery - 如何突出显示引用相同 URL 的导航菜单

javascript - 在canvas中上传多张图片转换为一张图片(Html5)

javascript - gojs 在不同级别的节点之间添加子节点

javascript - Go.JS 图添加 Javascript 数组对象未按预期工作没有哈希 ID

javascript - hh :mm:ss format relative to how many seconds 中的输出时间

javascript - 指定在检查 Google Recaptcha 时要执行的某些函数,因为我不是使用 javascript 的机器人

javascript - 查找最小持续时间

javascript - 如何在淡出期间为按钮移动设置动画

javascript - 在 GoJS 节点或 graphObject 中有 "visible overflow"