aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Polygon.js
blob: 0c99aa76a01284434e46e02cb7991939c3b076c1 (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
import {
  extend,
  nodeOrNew,
  register,
  wrapWithAttrCheck
} from '../utils/adopter.js'
import { registerMethods } from '../utils/methods.js'
import PointArray from '../types/PointArray.js'
import Shape from './Shape.js'
import * as pointed from '../modules/core/pointed.js'
import * as poly from '../modules/core/poly.js'

export default class Polygon extends Shape {
  // Initialize node
  constructor (node, attrs = node) {
    super(nodeOrNew('polygon', node), attrs)
  }
}

registerMethods({
  Container: {
    // Create a wrapped polygon element
    polygon: wrapWithAttrCheck(function (p) {
      // make sure plot is called as a setter
      return this.put(new Polygon()).plot(p || new PointArray())
    })
  }
})

extend(Polygon, pointed)
extend(Polygon, poly)
register(Polygon, 'Polygon')