@visactor/vrender-core
Version:
## Description
87 lines (76 loc) • 3.13 kB
JavaScript
import { isString, isNil } from "@visactor/vutils";
import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from "./graphic";
import { CustomPath2D } from "../common/custom-path2d";
import { getTheme } from "./theme";
import { application } from "../application";
import { PATH_NUMBER_TYPE } from "./constants";
import { updateBoundsOfCommonOuterBorder } from "./graphic-service/common-outer-boder-bounds";
const PATH_UPDATE_TAG_KEY = [ "path", "customPath", ...GRAPHIC_UPDATE_TAG_KEY ];
export class Path extends Graphic {
constructor(params) {
super(params), this.type = "path", this.numberType = PATH_NUMBER_TYPE;
}
get pathShape() {
return this.tryUpdateAABBBounds(), this.getParsedPathShape();
}
isValid() {
return super.isValid() && this._isValid();
}
_isValid() {
const {path: path} = this.attribute;
return null != path && "" !== path;
}
getParsedPathShape() {
const pathTheme = this.getGraphicTheme();
if (!this.valid) return pathTheme.path;
const attribute = this.attribute;
return attribute.path instanceof CustomPath2D ? attribute.path : (isNil(this.cache) && this.doUpdatePathShape(),
this.cache instanceof CustomPath2D ? this.cache : pathTheme.path);
}
getGraphicTheme() {
return getTheme(this).path;
}
updateAABBBounds(attribute, pathTheme, aabbBounds) {
if (!this.updatePathProxyAABBBounds(aabbBounds)) {
const pathShape = this.getParsedPathShape();
aabbBounds.union(pathShape.getBounds());
}
const {tb1: tb1, tb2: tb2} = application.graphicService.updateTempAABBBounds(aabbBounds);
updateBoundsOfCommonOuterBorder(attribute, pathTheme, tb1), aabbBounds.union(tb1),
tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);
const {lineJoin: lineJoin = pathTheme.lineJoin} = attribute;
return application.graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, "miter" === lineJoin, this),
aabbBounds;
}
doUpdateAABBBounds(full) {
return this.doUpdatePathShape(), super.doUpdateAABBBounds(full);
}
doUpdatePathShape() {
const attribute = this.attribute;
isString(attribute.path, !0) ? this.cache = (new CustomPath2D).fromString(attribute.path) : attribute.customPath && (this.cache = new CustomPath2D,
attribute.customPath(this.cache, this));
}
needUpdateTags(keys) {
return super.needUpdateTags(keys, PATH_UPDATE_TAG_KEY);
}
needUpdateTag(key) {
return super.needUpdateTag(key, PATH_UPDATE_TAG_KEY);
}
toCustomPath() {
return (new CustomPath2D).fromCustomPath2D(this.getParsedPathShape(), 0, 0);
}
clone() {
return new Path(Object.assign({}, this.attribute));
}
getNoWorkAnimateAttr() {
return Path.NOWORK_ANIMATE_ATTR;
}
}
Path.NOWORK_ANIMATE_ATTR = Object.assign({
path: 1,
customPath: 1
}, NOWORK_ANIMATE_ATTR);
export function createPath(attributes) {
return new Path(attributes);
}
//# sourceMappingURL=path.js.map