Get actual shape.geometryStretch

Gets or sets how the shape’s geometry is proportionally created given its computed size. Possible values are GeometryStretch.None, GeometryStretch.Fill, GeometryStretch.Uniform, and GeometryStretch.Default. The default is GeometryStretch.Default, which resolves to GeometryStretch.Fill for most figures, though some regular figures such as “Circle” and “Square” default to GeometryStretch.Uniform.

How can I read the actual value of the geometryStretch field? For example I have a “Circle” which according to docs is set to GeometryStretch.Default but then it says that the “Default” value is resolved to GeometryStretch.Uniform. When I get the geometryStretch field value for “Circle” I still get “Default” instead of “Uniform”.

If you have set (or bound) the Shape.figure property, and if the Shape.geometryStretch is GeometryStretch.Default, and if the Node (or whatever Part) containing that Shape has been measured and arranged, there will be a value for Shape.geometry. That is, its figure generator function will have been called and produced a Geometry that is remembered by the Shape. Look at its Geometry.defaultStretch property.

What if the Shape.geometry is still null when I need it?

If Shape.geometryStretch is Default, the effective stretch value comes from the Shape.geometry’s Geometry.defaultStretch property.

If Shape.geometry is null, then the call to the figure generator function will produce a Geometry. So that function’s construction and initialization of a Geometry is what decides the Geometry.defaultStretch value.

Why do you need to know before the figure generator has been called?

I have incorporated an `ensureBounds` call, and it appears to generate a valid Geometry. However, I am concerned about potential future issues with GoJS that could compromise its integrity. Is this approach acceptable, or are there any underlying GoJS mechanisms that may pose a risk?

const getDefaultStretch = (template: go.Node): go.GeometryStretch | null => {
  const templateCopy = template.copy();
  templateCopy.ensureBounds();
  if (!(templateCopy.resizeObject instanceof go.Shape)) {
    return null;
  }
  const result = templateCopy.resizeObject.geometry?.defaultStretch || null;
  return result;
};

I still don’t know why you need to know before the Node has been measured.

I’m changing node’s category and I need to update it’s size. If I replace a Rectangle with a Circle I need to change the size to look like a square - otherwise adornments look like an ellipsis while the Circle maintains its uniform stretch.

Oh, I see – the new Node contents haven’t been created yet from the new template. So the aspect ratio of the Node (actually its rectangular Shape) is determined by the user, say by resizing, and then you want to lose that resizing when changing the category/template? Then set the desiredSize to (NaN, NaN) and let the new Node determine its own size.

I don’t want to lose the resizing when changing the template. I need the new Node to have similar size to the original Node with a correction for GeometryStretch.

I guess I still do not understand. I will assume that the user can always resize the node, causing it to change aspect ratio, and that you want to preserve the modified width and height when changing the template resulting in a different Shape.figure.

But if the size/ratio changes from equal width and height to unequal, and then the shape changes from “Rectangle” to “Circle”, it seems to me that the circle would naturally have to be drawn to fit the shorter width or height distance/diameter. Really, the same thing should happen if the figure were initially “Square” and the width changed without changing the category/template. Or do you disallow the user from changing the aspect ratio when the figure is '“Square” or “Circle”?