【问题标题】:fixed size of graphObject in gojs diagramgojs图中graphObject的固定大小
【发布时间】:2020-07-02 10:21:14
【问题描述】:

我正在寻找一种可能性来定义 graphObject 固定大小,这样比例就不会影响它。 (类似于actualBounds-但不是只读)

【问题讨论】:

    标签: javascript gojs


    【解决方案1】:

    也许你的意思就像这里的最后一个例子:https://gojs.net/latest/intro/legends.html#StaticParts

    它展示了如何制作不受比例影响的固定标题。它通过在每次通过"ViewportBoundsChanged" 侦听器更改视口时重新定位和重新缩放它来实现这一点。

      diagram.add(
        $(go.Part,
          {
            layerName: "Grid",  // must be in a Layer that is Layer.isTemporary,
                                // to avoid being recorded by the UndoManager
            _viewPosition: new go.Point(0,0)  // some position in the viewport,
                                               // not in document coordinates
          },
          $(go.TextBlock, "A Title", { font: "bold 24pt sans-serif", stroke: "green" })));
    
      // Whenever the Diagram.position or Diagram.scale change,
      // update the position of all simple Parts that have a _viewPosition property.
      diagram.addDiagramListener("ViewportBoundsChanged", function(e) {
        e.diagram.commit(function(dia) {
          // only iterates through simple Parts in the diagram, not Nodes or Links
          dia.parts.each(function(part) {
            // and only on those that have the "_viewPosition" property set to a Point
            if (part._viewPosition) {
              part.position = dia.transformViewToDoc(part._viewPosition);
              part.scale = 1/dia.scale;
            }
          })
        }, "fix Parts");
      });
    

    【讨论】:

      【解决方案2】:

      GraphObject.actualBounds 属性仍在包含 Panel 的坐标系中,或者如果没有包含 Panel,则在文档坐标系中。如果您想确保无论 Diagram.scale 的值如何,包括整个 Part 在内的特定对象都以恒定的外观大小绘制,则必须显式更改其 GraphObject .scale 来补偿当前的 Diagram.scale

      请阅读https://gojs.net/latest/intro/legends.html#StaticParts 并查看常量大小示例中的示例代码:https://gojs.net/latest/samples/constantSize.html

      【讨论】:

        猜你喜欢
        • 2023-03-28
        • 2011-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-29
        • 2015-10-12
        • 2017-09-20
        • 2013-08-12
        相关资源
        最近更新 更多