SVGPath

SVGPath

Class representing an SVG Path

Constructor

new SVGPath(path)

Turn any string representing an SVG path into an array of SVG path commands.

Because SVGPath extend the native JavaScript Array object, all its methods can be used to easily manipulate the path. That said, be carful when using those methods as some can mutate the path (i.e. splice) when other doesn't (i.e. slice).

Parameters:
Name Type Description
path string

The string representation of the path

Source:

Methods

(static) toAbsolute(path) → {SVGPath}

Create a new path matching the current one but with absolute commands only

Parameters:
Name Type Description
path SVGPath

The path to convert

Source:

(static) toRelative(path, origin) → {SVGPath}

Create a new path matching the current one but with relative commands only

Parameters:
Name Type Description
path SVGPath

The path to convert

origin SVGCoordinates

The point of origin to resolve coordinates

Source:

push()

Overload the inherited Array.prototype.push to make sure we only add SVGPathCommand within an SVGPath

Source:

toAbsolute() → {SVGPath}

Mutate all the commands of the current path to make them absolute

Source:

toRelative(origin) → {SVGPath}

Mutate all the commands of the current path to make them relative

Parameters:
Name Type Description
origin SVGCoordinates

The point of origin to resolve coordinates

Source:

toString(compact) → {String}

Return a string representation of the path

Note that if the compact flag is set to true, the string representation will be somewhat compacted. The main effects are that value separators are reduced to the maximum and implicite command syntax are used whenever possible.

On the other hand, a non compact representation—if the compact flag is set to false—is a little more human friendly with each command placed on a new line.

IMPORTANT: If the current SVGPath is invalide (the first command is not an SVGPathMCommand object), the string representation will be made valid by adding an implicite M0,0 command at the start of the string.

Parameters:
Name Type Description
compact Boolean

Indicate if the string representation must be optimized (true) or more human friendly (false)

Source:

unshift()

Overload the inherited Array.prototype.unshift to make sure we only add SVGPathCommand within an SVGPath

Source: