UNPKG

@visactor/vrender-core

Version:
76 lines (64 loc) 3.44 kB
import { epsilon, pi2 } from "@visactor/vutils"; import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from "./graphic"; import { CustomPath2D } from "../common/custom-path2d"; import { circleBounds } from "../common/utils"; import { getTheme } from "./theme"; import { application } from "../application"; import { CIRCLE_NUMBER_TYPE } from "./constants"; import { updateBoundsOfCommonOuterBorder } from "./graphic-service/common-outer-boder-bounds"; const CIRCLE_UPDATE_TAG_KEY = [ "radius", "startAngle", "endAngle", ...GRAPHIC_UPDATE_TAG_KEY ]; export class Circle extends Graphic { constructor(params = { radius: 1 }) { super(params), this.type = "circle", this.numberType = CIRCLE_NUMBER_TYPE; } isValid() { return super.isValid() && this._isValid(); } _isValid() { const {startAngle: startAngle, endAngle: endAngle, radius: radius} = this.attribute; return this._validNumber(startAngle) && this._validNumber(endAngle) && this._validNumber(radius); } getGraphicTheme() { return getTheme(this).circle; } updateAABBBounds(attribute, circleTheme, aabbBounds, full) { this.updatePathProxyAABBBounds(aabbBounds) || (full ? this.updateCircleAABBBoundsImprecise(attribute, circleTheme, aabbBounds) : this.updateCircleAABBBoundsAccurate(attribute, circleTheme, aabbBounds)); const {tb1: tb1, tb2: tb2} = application.graphicService.updateTempAABBBounds(aabbBounds); return updateBoundsOfCommonOuterBorder(attribute, circleTheme, tb1), aabbBounds.union(tb1), tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2), application.graphicService.transformAABBBounds(attribute, aabbBounds, circleTheme, !1, this), aabbBounds; } updateCircleAABBBoundsImprecise(attribute, circleTheme, aabbBounds) { const {radius: radius = circleTheme.radius} = attribute; return aabbBounds.set(-radius, -radius, radius, radius), aabbBounds; } updateCircleAABBBoundsAccurate(attribute, circleTheme, aabbBounds) { const {startAngle: startAngle = circleTheme.startAngle, endAngle: endAngle = circleTheme.endAngle, radius: radius = circleTheme.radius} = attribute; return endAngle - startAngle > pi2 - epsilon ? aabbBounds.set(-radius, -radius, radius, radius) : circleBounds(startAngle, endAngle, radius, aabbBounds), aabbBounds; } needUpdateTags(keys) { return super.needUpdateTags(keys, CIRCLE_UPDATE_TAG_KEY); } needUpdateTag(key) { return super.needUpdateTag(key, CIRCLE_UPDATE_TAG_KEY); } toCustomPath() { var _a, _b, _c; const attribute = this.attribute, radius = null !== (_a = attribute.radius) && void 0 !== _a ? _a : this.getDefaultAttribute("radius"), startAngle = null !== (_b = attribute.startAngle) && void 0 !== _b ? _b : this.getDefaultAttribute("startAngle"), endAngle = null !== (_c = attribute.endAngle) && void 0 !== _c ? _c : this.getDefaultAttribute("endAngle"), path = new CustomPath2D; return path.arc(0, 0, radius, startAngle, endAngle), path; } clone() { return new Circle(Object.assign({}, this.attribute)); } getNoWorkAnimateAttr() { return Circle.NOWORK_ANIMATE_ATTR; } } Circle.NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR; export function createCircle(attributes) { return new Circle(attributes); } //# sourceMappingURL=circle.js.map