@visactor/vrender-core
Version:
## Description
71 lines (61 loc) • 2.56 kB
JavaScript
import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from "./graphic";
import { getTheme } from "./theme";
import { pointsInterpolation } from "../common/utils";
import { CustomPath2D } from "../common/custom-path2d";
import { application } from "../application";
import { POLYGON_NUMBER_TYPE } from "./constants";
const POLYGON_UPDATE_TAG_KEY = [ "points", "cornerRadius", ...GRAPHIC_UPDATE_TAG_KEY ];
export class Polygon extends Graphic {
constructor(params) {
super(params), this.type = "polygon", this.numberType = POLYGON_NUMBER_TYPE;
}
isValid() {
return super.isValid() && this._isValid();
}
_isValid() {
const {points: points} = this.attribute;
return points && points.length >= 2;
}
getGraphicTheme() {
return getTheme(this).polygon;
}
updateAABBBounds(attribute, polygonTheme, aabbBounds) {
this.updatePathProxyAABBBounds(aabbBounds) || this.updatePolygonAABBBoundsImprecise(attribute, polygonTheme, aabbBounds),
application.graphicService.updateTempAABBBounds(aabbBounds);
const {lineJoin: lineJoin = polygonTheme.lineJoin} = attribute;
return application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, "miter" === lineJoin, this),
aabbBounds;
}
updatePolygonAABBBoundsImprecise(attribute, polygonTheme, aabbBounds) {
const {points: points = polygonTheme.points} = attribute;
return points.forEach((p => {
aabbBounds.add(p.x, p.y);
})), aabbBounds;
}
_interpolate(key, ratio, lastStepVal, nextStepVal, nextAttributes) {
"points" === key && (nextAttributes.points = pointsInterpolation(lastStepVal, nextStepVal, ratio));
}
needUpdateTags(keys) {
return super.needUpdateTags(keys, POLYGON_UPDATE_TAG_KEY);
}
needUpdateTag(key) {
return super.needUpdateTag(key, POLYGON_UPDATE_TAG_KEY);
}
toCustomPath() {
const points = this.attribute.points, path = new CustomPath2D;
return points.forEach(((point, index) => {
0 === index ? path.moveTo(point.x, point.y) : path.lineTo(point.x, point.y);
})), path.closePath(), path;
}
clone() {
return new Polygon(Object.assign({}, this.attribute));
}
getNoWorkAnimateAttr() {
return Polygon.NOWORK_ANIMATE_ATTR;
}
}
Polygon.NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;
export function createPolygon(attributes) {
return new Polygon(attributes);
}
//# sourceMappingURL=polygon.js.map