The Geometry class is used to define the "shape" of a Shape. A Geometry can be simple straight lines, rectangles, or ellipses. A Geometry can also be an arbitrarily complex path, consisting of a list of PathFigures.
A Geometry must not be modified once it has been used by a Shape. However, a Geometry may be shared by multiple Shapes.
new go.Geometry() .add(new go.PathFigure(p.x, p.y) .add(new go.PathSegment(go.PathSegment.Arc, -sweep/2, sweep, 0, 0, radius+layerThickness, radius+layerThickness)) .add(new go.PathSegment(go.PathSegment.Line, q.x, q.y)) .add(new go.PathSegment(go.PathSegment.Arc, sweep/2, -sweep, 0, 0, radius, radius).close()));
See samples that make use of Geometries in the samples index.
This read-only property returns a rectangle that contains all points within the Geometry. The result will always contain the origin (0, 0).
Gets or sets the Shape.geometryStretch value the Shape should use by default when the Shape.geometryStretch value is GraphObject.None. The default value is GraphObject.Fill. Some figure generators return a Geometry with this property set to GraphObject.Uniform, in order to preserve its aspect ratio when used by a Shape that may have different sizes.
Computes the Geometry's bounds without adding an origin point, and returns those bounds as a rect. This method does not modify the Geometry or its bounds.
Create a copy of this Geometry, with the same values and figures.
Given a SVG or GoJS path string, returns a congruent path string with each pathfigure filled. For instance, "M0 0 L22 22 L33 0" would become "F M0 0 L22 22 L33 0".
Normalizes the Geometry points in place by ensuring the top-left bounds of the geometry lines up with (0, 0), returning the Point (x, y) amount it was shifted. After this method is called there will be no negative X or Y value for the Geometry's bounds, and no empty space at the top-left of the Geometry.
Offsets the Geometry in place by a given (x, y) amount
The x-axis offset factor.
The y-axis offset factor.
Produce a Geometry from a string that uses an SVG-like compact path geometry syntax. The syntax accepts all SVG Path Syntax (SVG Path Syntax (w3.org)), as well as three GoJS-specific tokens. Specifically, the following tokens are allowed:
M (x,y)+- Move commands
L (x,y)+, H (x)+, V (y)+Lines commands, including horizontal and vertical lines
C (x1 y1 x2 y2 x y)+, S (x2 y2 x y)+Cubic bezier curves
Q (x1 y1 x y)+, T (x y)+Quadratic bezier curves
A (rx ry x-axis-rotation large-arc-flag clockwise-flag x y)+Arcs (following SVG arc conventions)
ZDenotes that the previous subpath is closed
Additionally there are some tokens specific to GoJS:
B (startAngle, sweepAngle, centerX, centerY, radius)+Arcs following GoJS canvas arc conventions
XUsed before M-commands to denote separate PathFigures instead of a subpath
FDenotes whether the current PathFigure is filled (true if F is present)
UDenotes that the PathFigure is not shadowed
See the Introduction page on Geometry Parsing for more details.
whether figures should be filled. If true, all PathFigures in the string will be filled regardless of the presence of an "F" command or not. If false, all PathFigures will determine their own filled state by the presence of an "F" command or not. Default is false.
Rotates the Geometry in place by a given angle, with optional x and y values to rotate the geometry about. If no x and y value are given, (0, 0) is used as the rotation point.
The angle to rotate by.
The optional X point to rotate the geometry about. If no point is given, this value is 0.
The optional Y point to rotate the geometry about. If no point is given, this value is 0.
Scales the Geometry in place by a given (x, y) scale factor.
If you want to flip a Geometry horizontally, call
If you want to flip a Geometry vertically, call
The x-axis scale factor.
The y-axis scale factor.
The string produced by this method is a superset of the SVG path string rules that contains some additional GoJS-specific tokens. See the Introduction page on Geometry Parsing for more details.