# polygon

The polygon element defines a closed shape consisting of a set of connected straight line segments. The last point is connected to the first point.

For open shapes, see the polyline element.

Usually, this element is created with:

const polygon = parentElement.add('polygon')

It's possible to create it as a disconnected element with gySVG('polygon') and attach it to the SVG document with .attachTo().

More info: mdn (opens new window) | w3c (opens new window)

# .points()

polygon.points( points )

Set this attribute defines the list of points (pairs of x,y absolute coordinates) required to draw the polygon.

  • argument: {Array<Array<number,number>>|string} points An array of arrays with [x, y] values.

  • returns: {gySVGObject} The original object

const points = element.points();

Get the points current value.

  • returns: {Array}

# .pathLength()

polygon.pathLength( length )

Set this attribute lets specify the total length for the path, in user units.

  • argument: {number} length The total length

  • returns: {gySVGObject} The original object

const pathLength = element.pathLength();

Get the pathLength current value.