Search API

- Preparing search index...
- The search index is not available

Show Summaries
GoJS® Diagramming Components
version 1.8.23 for JavaScript/HTML
by Northwoods Software®

## Class Geometry

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.

It is commonplace to create Geometries using geometry path string syntax: Geometry Path Strings. However it is much more efficient to create Geometries programmatically. One way to do that is illustrated by several of the samples that evaluate JavaScript such as:

    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.

## Constructor Summary Details

Name | Description
--- | ---
Geometry(type) | Construct an empty Geometry.More... The geometry type must be one of the following values: Geometry.Line, Geometry.Ellipse, Geometry.Rectangle, Geometry.Path. Parameters: {EnumValue=} type If not supplied, the default Geometry type is Geometry.Path.

## Properties Summary Details

Name, Value Type | Description
--- | ---
bounds {Rect} | This read-only property returns a rectangle that contains all points within the Geometry.More... The result will always contain the origin (0, 0).
defaultStretch {EnumValue} 1.5 | Gets or sets the Shape.geometryStretch value the Shape should use by default when the Shape.geometryStretch value is GraphObject.None.More... 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.
endX {number} | Gets or sets the ending X coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse.More... The initial value is zero.
endY {number} | Gets or sets the ending Y coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse.More... The initial value is zero.
figures {List.} | Gets or sets the List of PathFigures that describes the content of the path for Geometries of type Path.
spot1 {Spot} | Gets or sets the spot an "Auto" Panel will use for the top-left corner of any panel content when the Shape.spot1 value is Spot.Default.More... The default value is Spot.TopLeft, at the top-left point of the bounds of the Shape.
spot2 {Spot} | Gets or sets the spot an "Auto" Panel will use for the bottom-right corner of any panel content when the Shape.spot2 value is Spot.Default.More... The default value is Spot.BottomRight, at the bottom-right point of the bounds of the Shape.
startX {number} | Gets or sets the starting X coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse.More... The initial value is zero.
startY {number} | Gets or sets the starting Y coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse.More... The initial value is zero.
type {EnumValue} | Gets or sets the type of the Geometry.More... The default type is Geometry.Path. Other permissible values are Geometry.Line, Geometry.Ellipse, or Geometry.Rectangle.

## Method Summary Details

Name, Return Type | Description
--- | ---
add(figure) {Geometry} 1.5 | Add a PathFigure to the figures list.More... Parameters: {PathFigure} figure a newly allocated unshared PathFigure that will become owned by this Geometry Returns: {Geometry} this
computeBoundsWithoutOrigin() {Rect} 1.1 | Computes the Geometry's bounds without adding an origin point, and returns those bounds as a rect.More... This method does not modify the Geometry or its bounds. Returns: {Rect}
copy() {Geometry} | Create a copy of this Geometry, with the same values and figures. Returns: {Geometry}
<static> Geometry.fillPath(str) {string} 1.1 | Given a SVG or GoJS path string, returns a congruent path string with each pathfigure filled.More... For instance, "M0 0 L22 22 L33 0" would become "F M0 0 L22 22 L33 0". Parameters: {string} str Returns: {string}
normalize() {Point} 1.1 | 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.More... 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. Returns: {Point}
offset(x, y) {Geometry} 1.1 | Offsets the Geometry in place by a given (x, y) amountMore... Parameters: {number} x The x-axis offset factor. {number} y The y-axis offset factor. Returns: {Geometry} this
<static> Geometry.parse(str, filled) {Geometry} | Produce a Geometry from a string that uses an SVG-like compact path geometry syntax.More... 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) `Z` Denotes 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 `X` Used before M-commands to denote separate PathFigures instead of a subpath `F` Denotes whether the current PathFigure is filled (true if F is present) `U` Denotes that the PathFigure is not shadowed See the Introduction page on Geometry Parsing for more details. Parameters: {string} str {boolean=} filled 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. Returns: {Geometry}
rotate(angle, x, y) {Geometry} 1.1 | Rotates the Geometry in place by a given angle, with optional x and y values to rotate the geometry about.More... If no x and y value are given, (0, 0) is used as the rotation point. Parameters: {number} angle The angle to rotate by. {number=} x The optional X point to rotate the geometry about. If no point is given, this value is 0. {number=} y The optional Y point to rotate the geometry about. If no point is given, this value is 0. Returns: {Geometry} this
scale(x, y) {Geometry} 1.1 | Scales the Geometry in place by a given (x, y) scale factor.More... If you want to flip a Geometry horizontally, call `geo.scale(-1, 1)`. If you want to flip a Geometry vertically, call `geo.scale(1, -1)`. Parameters: {number} x The x-axis scale factor. {number} y The y-axis scale factor. Returns: {Geometry} this
<static> Geometry.stringify(val) {string} 1.1 | This static function can be used to write out a Geometry as a string that can be read by Geometry.parse.More... 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. Parameters: {Geometry} val Returns: {string}

## Constants Summary Details

Name | Description
--- | ---
Ellipse {EnumValue} | For drawing an ellipse fitting within a rectangle; a value for Geometry.type.More... The ellipse fits within the rectangle that goes from the point (startX, startY) to the point (endX, endY).
Line {EnumValue} | For drawing a simple straight line; a value for Geometry.type.More... The line goes from the point (startX, startY) to the point (endX, endY).
Path {EnumValue} | For drawing a complex path made of a list of PathFigures; a value for Geometry.type.
Rectangle {EnumValue} | For drawing a rectangle; a value for Geometry.type.More... The rectangle goes from the point (startX, startY) to the point (endX, endY).