Class: plygn

plygn

Shortcut for creating SVG polygons

new plygn(options){plygn}

Initializes a new plygn instance.
Name Type Description
options Object Options used to customize the plygn
Name Type Default Description
parent * optional SVGElement which to append the plygn's polygon element
id String optional The id of the instance. Auto-generated when not provided
x Number 0 optional Origin of the polygon along the x-axis
y Number 0 optional Origin of the polygon along the y-axis
points Array optional A 2d array of points used to draw the polygon relative to its origin. Each index in the parent array should contian an arry with two numbers for x and y.
fill String 'transparent' optional The default fill color
stroke String '#000000' optional The default stroke color
strokeWidth Number 1 optional The default stroke width
attr Object optional Attributes to apply to the plygn's polygon element.
css Object optional CSS Properties to apply to the plygn's polygon element.
Returns:
Type Description
plygn A new plygn instance.

Requires

Members

readonlycoordsArray

An 2d array of coordinates used to draw the polygon relative to its origin

dasharray*

The stroke-dasharray of the polygon

dashoffset*

The stroke-dashoffset of the polygon

readonlyelSVGElement

The polygon element associated with this instance

fillString

The plygn's fill color

readonlyidString

The id of this instance's polygon element

readonlyparentSVGElement

The parent of the polygon element

pointsArray

An 2d array of points used to draw the polygon relative to its origin

readonlypointsArray

An 2d array of coordinares used to draw the star relative to its origin

sliceString

Control how much of the polygon's stroke is drawn. Space-delimited values define a slice, ie '10 30'. A single value asserts 0 as the starting value. Accepts percentages for relative values

strokeString

The plygn's stroke color

strokeWidthNumber

The plygn's stroke width

xNumber

The origin of the polygon along the x-axis

yNumber

The origin of the polygon along the y-axis

Methods

staticplygn.getElInstance(el){plygn}

returns the plygn instance associated with the provided element's id attribute
Name Type Description
el Element The element with the lookup id
Returns:
Type Description
plygn The associate plygn, if it exists

staticplygn.getInstance(id){plygn}

returns the plygn instance associated with the id
Name Type Description
id String The lookup id
Returns:
Type Description
plygn The associate plygn, if it exists

addPoint(coords, index){plygn}

Add a new point to the plygn.
Name Type Description
coords Array The new point coordinates
index int optional The insertion index, defaults to the number of points. When negative, becomes the sum of itself and the number points
Returns:
Type Description
plygn The plygn instance

getPoint(index){Array}

Returns the point at the specified index
Name Type Default Description
index int -1 optional The index of the target point. When negative, becomes the sum of itself and the number points
Returns:
Type Description
Array The point at the specified index

removePoint(index){Array}

Remove the point at the specified index
Name Type Default Description
index int -1 optional The index target point. When negative, becomes the sum of itself and the number points
Returns:
Type Description
Array The removed point coordinates

setPoint(coords, index){Array}

Updates the point at the specified index
Name Type Default Description
coords Array The new point coordinates
index int -1 optional The index of the target point. When negative, becomes the sum of itself and the number points
Returns:
Type Description
Array The updated point
Updates the points attribute of the polygon element.