import { INumber } from '@leafer/interface' import { PathCommandDataHelper, Platform, dataProcessor, pathType, registerUI } from '@leafer/core' import { IEllipse, IEllipseInputData, IEllipseData } from '@leafer-ui/interface' import { EllipseData } from '@leafer-ui/data' import { UI } from './UI' const { moveTo, closePath, ellipse } = PathCommandDataHelper @registerUI() export class Ellipse extends UI implements IEllipse { public get __tag() { return 'Ellipse' } @dataProcessor(EllipseData) declare public __: IEllipseData @pathType(0) public innerRadius?: INumber @pathType(0) public startAngle?: INumber @pathType(0) public endAngle?: INumber public __updatePath(): void { const data = this.__, { width, height, innerRadius, startAngle, endAngle } = data const rx = width / 2, ry = height / 2 const path: number[] = data.path = [] let open: boolean if (innerRadius) { if (startAngle || endAngle) { if (innerRadius < 1) ellipse(path, rx, ry, rx * innerRadius, ry * innerRadius, 0, startAngle, endAngle, false) else open = true // 画弧线时,不能闭合路径 ellipse(path, rx, ry, rx, ry, 0, endAngle, startAngle, true) } else { if (innerRadius < 1) { ellipse(path, rx, ry, rx * innerRadius, ry * innerRadius) moveTo(path, width, ry) } ellipse(path, rx, ry, rx, ry, 0, 360, 0, true) } } else { if (startAngle || endAngle) { moveTo(path, rx, ry) ellipse(path, rx, ry, rx, ry, 0, startAngle, endAngle, false) } else { ellipse(path, rx, ry, rx, ry) } } if (!open) closePath(path) // fix node if (Platform.ellipseToCurve || data.__useArrow || data.cornerRadius) data.path = this.getPath(true) } }