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.

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(type?: EnumValue): Geometry

Construct an empty Geometry. The geometry type must be one of the following values: Geometry#Line, Geometry#Ellipse, Geometry#Rectangle, Geometry#Path.

Parameters

  • type?: EnumValue optional

    If not supplied, the default Geometry type is Geometry#Path.

Returns

Geometry

Properties

public static Ellipse: EnumValue

For drawing an ellipse fitting within a rectangle; a value for Geometry#type.

public static Line: EnumValue

For drawing a simple straight line; a value for Geometry#type.

public static Path: EnumValue

For drawing a complex path made of a list of PathFigures; a value for Geometry#type.

public static Rectangle: EnumValue

For drawing a rectangle; a value for Geometry#type.

public bounds: Rect

Gets a rectangle that contains all points within the Geometry.

public endX: number

Gets or sets the ending X coordinate of the Geometry if it is of type #Line, #Rectangle, or #Ellipse.

public endY: number

Gets or sets the ending Y coordinate of the Geometry if it is of type #Line, #Rectangle, or #Ellipse.

public figures: List

Gets or sets the List of PathFigures that describes the content of the path for Geometries of type #Path.

public spot1: Spot

Gets or sets the spot to use when the Shape#spot1 value is Spot#Default.

public spot2: Spot

Gets or sets the spot to use when the Shape#spot2 value is Spot#Default.

public startX: number

Gets or sets the starting X coordinate of the Geometry if it is of type #Line, #Rectangle, or #Ellipse.

public startY: number

Gets or sets the starting Y coordinate of the Geometry if it is of type #Line, #Rectangle, or #Ellipse.

public type: EnumValue

Gets or sets the type of the Geometry.

Methods

public computeBoundsWithoutOrigin(): Rect

Computes the Geometry's bounds without adding an origin point, and returns those bounds as a rect.

Returns

Rect

public copy(): Geometry

Create a copy of this Geometry, with the same values and figures.

Returns

Geometry

public static fillPath(str: string): string

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".

Parameters

  • str: string

Returns

string

public normalize(): Point

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.

Returns

Point

public offset(x: number, y: number): any

Offsets the Geometry in place by a given (x, y) amount

Parameters

  • x: number

    The x-axis offset factor.

  • y: number

    The y-axis offset factor.

Returns

any

public static parse(str: string, filled?: boolean): Geometry

Produce a Geometry from a string that uses an SVG-like compact path geometry syntax.

Parameters

  • str: string
  • filled?: boolean optional

    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

public rotate(angle: number, x?: number, y?: number): any

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 giving, (0, 0) is used as the rotation point.

Parameters

  • angle: number

    The angle to rotate by.

  • x?: number optional

    The optional X point to rotate the geometry about. If no point is given, this value is 0.

  • y?: number optional

    The optional Y point to rotate the geometry about. If no point is given, this value is 0.

Returns

any

public scale(x: number, y: number): any

Scales the Geometry in place by a given (x, y) scale factor

Parameters

  • x: number

    The x-axis scale factor.

  • y: number

    The y-axis scale factor.

Returns

any

public static stringify(val: Geometry): string

This static method can be used to write out a Geometry as a string that can be read by Geometry.parse. 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

Returns

string