summaryrefslogtreecommitdiffstats
path: root/src/elements/Ellipse.js
blob: e1e1fe0d2ba61232bf9d1bd83e5a4941bae47ef0 (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
42
43
44
import {
  extend,
  nodeOrNew,
  register,
  wrapWithAttrCheck
} 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 ), node )

  }

  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: wrapWithAttrCheck( function ( width, height ) {

    return this.put( new Ellipse() ).size( width, height ).move( 0, 0 )

  } )
} )

register( Ellipse )