@leafer-ui/display
Version:
68 lines (46 loc) • 1.96 kB
text/typescript
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
()
export class Ellipse<TInputData = IEllipseInputData> extends UI<TInputData> implements IEllipse {
public get __tag() { return 'Ellipse' }
(EllipseData)
declare public __: IEllipseData
(0)
public innerRadius?: INumber
(0)
public startAngle?: INumber
(0)
public endAngle?: INumber
public __updatePath(): void {
const { width, height, innerRadius, startAngle, endAngle } = this.__
const rx = width / 2, ry = height / 2
const path: number[] = this.__.path = []
if (innerRadius) {
if (startAngle || endAngle) {
if (innerRadius < 1) ellipse(path, rx, ry, rx * innerRadius, ry * innerRadius, 0, startAngle, endAngle, false)
ellipse(path, rx, ry, rx, ry, 0, endAngle, startAngle, true)
if (innerRadius < 1) closePath(path)
} 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)
}
// fix node
if (Platform.ellipseToCurve) this.__.path = this.getPath(true)
} else {
if (startAngle || endAngle) {
moveTo(path, rx, ry)
ellipse(path, rx, ry, rx, ry, 0, startAngle, endAngle, false)
closePath(path)
} else {
ellipse(path, rx, ry, rx, ry)
}
}
}
}