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
Properties
- bounds ↔ Rect
-
Available on Geometry, provided by the Geometry$Typings extension
This read-only property returns a rectangle that contains all points within the Geometry. The result will always contain the origin (0, 0).getter/setter pair - defaultStretch ↔ EnumValue
-
Available on Geometry, provided by the Geometry$Typings extension
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.getter/setter pair - endX ↔ num
-
Available on Geometry, provided by the Geometry$Typings extension
Gets or sets the ending X coordinate of the Geometry if it is of type Geometry.Line|Line, Geometry.Rectangle|Rectangle, or Geometry.Ellipse|Ellipse. The initial value is zero.getter/setter pair - endY ↔ num
-
Available on Geometry, provided by the Geometry$Typings extension
Gets or sets the ending Y coordinate of the Geometry if it is of type Geometry.Line|Line, Geometry.Rectangle|Rectangle, or Geometry.Ellipse|Ellipse. The initial value is zero.getter/setter pair -
figures
↔ List<
PathFigure> -
Available on Geometry, provided by the Geometry$Typings extension
Gets or sets the List of PathFigures that describes the content of the path for Geometries of type Geometry.Path|Path.getter/setter pair -
flattenedLengths
↔ Array<
Array< num> > -
Available on Geometry, provided by the Geometry$Typings extension
(undocumented) Flattened lengths represents a series of lengths of the paths making up a Geometry. The inner arrays consist of a sequence of PathSegment lengths making up a PathFigure, while the outer array represents the whole Geometry of these PathFigures.getter/setter pair -
flattenedSegments
↔ Array<
Array< num> > -
Available on Geometry, provided by the Geometry$Typings extension
(undocumented) Flattened segments represents a series of points making up a Geometry. The inner arrays consist of a sequence of PathSegment coordinates making up a PathFigure, while the outer array represents the whole Geometry of these PathFigures.getter/setter pair - flattenedTotalLength ↔ num
-
Available on Geometry, provided by the Geometry$Typings extension
(undocumented) This read-only property returns the approximate length of the path. This is the overall distance of all the PathSegments that make up the geometry.getter/setter pair - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- spot1 ↔ Spot
-
Available on Geometry, provided by the Geometry$Typings extension
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. The default value is Spot.TopLeft, at the top-left point of the bounds of the Shape.getter/setter pair - spot2 ↔ Spot
-
Available on Geometry, provided by the Geometry$Typings extension
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. The default value is Spot.BottomRight, at the bottom-right point of the bounds of the Shape.getter/setter pair - startX ↔ num
-
Available on Geometry, provided by the Geometry$Typings extension
Gets or sets the starting X coordinate of the Geometry if it is of type Geometry.Line|Line, Geometry.Rectangle|Rectangle, or Geometry.Ellipse|Ellipse. The initial value is zero.getter/setter pair - startY ↔ num
-
Available on Geometry, provided by the Geometry$Typings extension
Gets or sets the starting Y coordinate of the Geometry if it is of type Geometry.Line|Line, Geometry.Rectangle|Rectangle, or Geometry.Ellipse|Ellipse. The initial value is zero.getter/setter pair - type ↔ EnumValue
-
Available on Geometry, provided by the Geometry$Typings extension
Gets or sets the type of the Geometry. The default type is Geometry.Path. Other permissible values are Geometry.Line, Geometry.Ellipse, or Geometry.Rectangle.getter/setter pair
Methods
-
add(
PathFigure figure) → Geometry -
Available on Geometry, provided by the Geometry$Typings extension
Add a PathFigure to the #figures list. @param {PathFigure} figure a newly allocated unshared PathFigure that will become owned by this Geometry @return {Geometry} this @since 1.5 -
computeBoundsWithoutOrigin(
) → Rect -
Available on Geometry, provided by the Geometry$Typings extension
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. @return {Rect} @since 1.1 -
containsPoint(
Point p, [num? sw]) → bool -
Available on Geometry, provided by the Geometry$Typings extension
Returns true if the Geometry contains the point. @param {Point} p in local geometry coordinates @param {number=} sw half the stroke width that a Shape has or that you want to pretend it has @return {boolean} @since 2.2 -
copy(
) → Geometry -
Available on Geometry, provided by the Geometry$Typings extension
Create a copy of this Geometry, with the same values and figures. @expose @return {Geometry} -
equalsApprox(
Geometry g) → bool -
Available on Geometry, provided by the Geometry$Typings extension
(undocumented) @param {Geometry} g @return {boolean} -
getAngleAlongPath(
num fraction) → num -
Available on Geometry, provided by the Geometry$Typings extension
Returns the slope expressed as an angle at the fractional distance (0-1) along this Geometry's path, in local coordinates. @param {number} fraction A fractional amount between 0 and 1, inclusive. @return {number} @since 2.1 -
getFractionForPoint(
Point pt) → num -
Available on Geometry, provided by the Geometry$Typings extension
Returns the fractional distance (0-1) along this Geometry's path for a nearby point. @param {Point} pt A Point, in local coordinates, near this Geometry. @return {number} A fractional amount between 0 and 1, inclusive. @since 2.1 -
getPointAlongPath(
num fraction, [Point? result]) → Point -
Available on Geometry, provided by the Geometry$Typings extension
Returns the point at the fractional distance (0-1) along this Geometry's path. @param {number} fraction A fractional amount between 0 and 1, inclusive. @param {Point=} result an optional Point that is modified and returned; otherwise it allocates and returns a new Point. @return {Point} the Point, in local coordinates, of the fractional distance along the path. @since 2.1 -
normalize(
) → Point -
Available on Geometry, provided by the Geometry$Typings extension
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. @return {Point} @since 1.1 -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offset(
num x, num y) → Geometry -
Available on Geometry, provided by the Geometry$Typings extension
Offsets the Geometry in place by a given (x, y) amount @param {number} x The x-axis offset factor. @param {number} y The y-axis offset factor. @return {Geometry} this @since 1.1 -
rotate(
num angle, [num? x, num? y]) → Geometry -
Available on Geometry, provided by the Geometry$Typings extension
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. @param {number} angle The angle to rotate by. @param {number=} x The optional X point to rotate the geometry about. If no point is given, this value is 0. @param {number=} y The optional Y point to rotate the geometry about. If no point is given, this value is 0. @return {Geometry} this @since 1.1 -
scale(
num x, num y) → Geometry -
Available on Geometry, provided by the Geometry$Typings extension
Scales the Geometry in place by a given (x, y) scale factor. -
setSpots(
num f1x, num f1y, num f2x, num f2y, [num? o1x, num? o1y, num? o2x, num? o2y]) → Geometry -
Available on Geometry, provided by the Geometry$Typings extension
(undocumented) Set #spot1 and #spot2 without allocating new Spots. @param {number} f1x spot1.x @param {number} f1y spot1.y @param {number} f2x spot2.x @param {number} f2y spot2.y @param {number=} o1x offset1.x, default is zero @param {number=} o1y offset1.y, default is zero @param {number=} o2x offset2.x, default is zero @param {number=} o2y offset2.y, default is zero @return {Geometry} this -
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.