aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Ellipse.js
blob: b0ee4bf45993c876e21987dbf608f370fbd28d0b (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
import { extend, nodeOrNew, register } from '../utils/adopter.js'
import { proportionalSize } from '../utils/utils.js'
import { registerMethods } from '../utils/methods.js'
import SVGNumber from '../types/SVGNumber.js'
import Shape from './Shape.js'
import * as circled from '../modules/core/circled.js'

export default class Ellipse extends Shape {
  constructor (node) {
    super(nodeOrNew('ellipse', node), Ellipse)
  }

  size (width, height) {
    var p = proportionalSize(this, width, height)

    return this
      .rx(new SVGNumber(p.width).divide(2))
      .ry(new SVGNumber(p.height).divide(2))
  }
}

extend(Ellipse, circled)

registerMethods('Container', {
  // Create an ellipse
  ellipse: function (width, height) {
    return this.put(new Ellipse()).size(width, height).move(0, 0)
  }
})

register(Ellipse)