几何路径

The GoJS Geometry class controls the "shape" of a Shape, whereas the Shape.fill and Shape.stroke and other shape properties control the colors and appearance of the shape. For common shape figures, there are predefined geometries that can be used by setting Shape.figure. However one can also define custom geometries.

One can construct any Geometry by allocating and initializing a Geometry of at least one PathFigure holding some PathSegments. But you may find that using the string representation of a Geometry is easier to write and save in a database. Use the static method Geometry,parse or the Shape.geometryString property to transform a geometry path string into a Geometry object.

See samples that make use of Geometries in the samples index.

Geometry Path String Syntax

The syntax for a geometry path string is an extension of the SVG path string syntax. The string consists of a number of commands, each a single letter followed by some command-specific numeric parameters.

Below are the possible commands along with the parameters they take. The parameter notation (x y)+ means that the command requires exactly two parameters, but there can be 1 or more sets of parameters for each command. For instance, the L (x y)+ command can be written as L 10 10 20 20 to denote two straight line segments.

Commands written with an uppercase letter indicate absolute coordinates; lowercase commands specify coordinates relative to the last command. Some commands do not care about case because they do not take coordinates as arguments.

Move commands begin a new subpath in a PathFigure. One is essential to begin a PathFigure and therefore must be the first segment type in the path string, with the exception of a Fill command (F) that can precede it. Additional sets of parameters for a move command are automatically considered Line commands, so M 10 10 20 20 is identical to M 10 10 L 20 20.


For detailed information on the SVG path strings, see the W3C's page on SVG Paths.


Additionally there are some tokens specific to GoJS:
加入 GoJS 交流群
GoJS 交流群 (769862113)