diff options
Diffstat (limited to 'src/poly.js')
-rw-r--r-- | src/poly.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/poly.js b/src/poly.js new file mode 100644 index 0000000..e8edbed --- /dev/null +++ b/src/poly.js @@ -0,0 +1,30 @@ +// Add polygon-specific functions + +// Get array +export function array () { + return this._array || (this._array = new PointArray(this.attr('points'))) +} + +// Plot new path +export function plot (p) { + return (p == null) ? this.array() + : this.clear().attr('points', typeof p === 'string' ? p + : (this._array = new PointArray(p))) +} + +// Clear array cache +export function clear () { + delete this._array + return this +} + +// Move by left top corner +export function move (x, y) { + return this.attr('points', this.array().move(x, y)) +} + +// Set element size to given width and height +export function size (width, height) { + let p = proportionalSize(this, width, height) + return this.attr('points', this.array().size(p.width, p.height)) +} |