summaryrefslogtreecommitdiffstats
path: root/src/modules/core/poly.js
blob: 56703a510d1cee4f7ce7dae3caca1fbbeb5c5bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { proportionalSize } from '../../utils/utils.js'
import PointArray from '../../types/PointArray.js'

// 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 ) )

}