import { TypeContext , TypeElement , } from '@idraw/types' ; import { rotateElement } from './../transform' ; import { clearContext } from './base' ; export function drawCircle ( ctx , elem ) { clearContext ( ctx ) ; rotateElement ( ctx , elem , ( ctx ) => { const { x , y , w , h , desc } = elem ; const { bgColor = '#000000' , borderColor = '#000000' , borderWidth = 0 , } = desc ; const a = w / 2 ; const b = h / 2 ; const centerX = x + a ; const centerY = y + b ; if ( borderWidth && borderWidth > 0 ) { const ba = borderWidth / 2 + a ; const bb = borderWidth / 2 + b ; ctx . beginPath ( ) ; ctx . setStrokeStyle ( borderColor ) ; ctx . setLineWidth ( borderWidth ) ; ctx . ellipse ( centerX , centerY , ba , bb , 0 , 0 , 2 * Math . PI ) ; ctx . closePath ( ) ; ctx . stroke ( ) ; } ctx . beginPath ( ) ; ctx . setFillStyle ( bgColor ) ; ctx . ellipse ( centerX , centerY , a , b , 0 , 0 , 2 * Math . PI ) ; ctx . closePath ( ) ; ctx . fill ( ) ; } ) ; }