gojs图中graphObject的固定大小

fixed size of graphObject in gojs diagram

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

GraphObject.actualBounds属性仍在包含面板的坐标系中,或者如果没有包含面板,则在文档坐标系中。如果要确保无论 Diagram.scale 的值如何,都以恒定的外观尺寸绘制特定对象(包括整个部分),则必须显式更改它的 GraphObject.scale 来补偿当前的 Diagram.scale.

请阅读https://gojs.net/latest/intro/legends.html#StaticParts and see the example code in the Constant Size sample: https://gojs.net/latest/samples/constantSize.html

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

它展示了如何制作一个不受比例影响的固定标题。每次视口通过 "ViewportBoundsChanged" 侦听器更改时,它都会通过重新定位和 re-scaling 来实现。

  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");
  });