Geometry class

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.

Available Extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

Geometry([EnumValue? type])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

ellipse EnumValue
For drawing an ellipse fitting within a rectangle; a value for Geometry#type. The ellipse fits within the rectangle that goes from the point (#startX, #startY) to the point (#endX, #endY).
getter/setter pair
line EnumValue
For drawing a simple straight line; a value for Geometry#type. The line goes from the point (#startX, #startY) to the point (#endX, #endY).
getter/setter pair
path EnumValue
For drawing a complex path made of a list of PathFigures; a value for Geometry#type.
getter/setter pair
rectangle EnumValue
For drawing a rectangle; a value for Geometry#type. The rectangle goes from the point (#startX, #startY) to the point (#endX, #endY).
getter/setter pair

Static Methods

fillPath(String str) 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".
parse(String str, [bool? filled]) Geometry
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:
stringify(Geometry val) String
This static function can be used to write out a Geometry as a string that can be read by Geometry.parse.