@visactor/vrender-core
Version:
## Description
95 lines (89 loc) • 4.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.createArea = exports.Area = void 0;
const graphic_1 = require("./graphic"), custom_path2d_1 = require("../common/custom-path2d"), utils_1 = require("../common/utils"), theme_1 = require("./theme"), application_1 = require("../application"), constants_1 = require("./constants"), AREA_UPDATE_TAG_KEY = [ "segments", "points", "curveType", "curveTension", ...graphic_1.GRAPHIC_UPDATE_TAG_KEY ];
class Area extends graphic_1.Graphic {
constructor(params) {
super(params), this.type = "area", this.numberType = constants_1.AREA_NUMBER_TYPE;
}
isValid() {
return super.isValid() && this._isValid();
}
_isValid() {
if (this.pathProxy) return !0;
const {points: points, segments: segments} = this.attribute;
return segments ? 0 !== segments.length : !!points && 0 !== points.length;
}
getGraphicTheme() {
return (0, theme_1.getTheme)(this).area;
}
updateAABBBounds(attribute, areaTheme, aabbBounds) {
this.updatePathProxyAABBBounds(aabbBounds) || (attribute.segments ? this.updateAreaAABBBoundsBySegments(attribute, areaTheme, aabbBounds) : this.updateAreaAABBBoundsByPoints(attribute, areaTheme, aabbBounds)),
application_1.application.graphicService.updateTempAABBBounds(aabbBounds);
const {lineJoin: lineJoin = areaTheme.lineJoin} = attribute;
return application_1.application.graphicService.transformAABBBounds(attribute, aabbBounds, areaTheme, "miter" === lineJoin, this),
aabbBounds;
}
updateAreaAABBBoundsByPoints(attribute, areaTheme, aabbBounds, graphic) {
const {points: points = areaTheme.points} = attribute, b = aabbBounds;
return points.forEach((p => {
var _a, _b;
b.add(p.x, p.y), b.add(null !== (_a = p.x1) && void 0 !== _a ? _a : p.x, null !== (_b = p.y1) && void 0 !== _b ? _b : p.y);
})), b;
}
updateAreaAABBBoundsBySegments(attribute, areaTheme, aabbBounds, graphic) {
const {segments: segments = areaTheme.segments} = attribute, b = aabbBounds;
return segments.forEach((s => {
s.points.forEach((p => {
var _a, _b;
b.add(p.x, p.y), b.add(null !== (_a = p.x1) && void 0 !== _a ? _a : p.x, null !== (_b = p.y1) && void 0 !== _b ? _b : p.y);
}));
})), b;
}
_interpolate(key, ratio, lastStepVal, nextStepVal, nextAttributes) {
"points" === key && (nextAttributes.points = (0, utils_1.pointsInterpolation)(lastStepVal, nextStepVal, ratio));
}
needUpdateTags(keys) {
return super.needUpdateTags(keys, AREA_UPDATE_TAG_KEY);
}
needUpdateTag(key) {
return super.needUpdateTag(key, AREA_UPDATE_TAG_KEY);
}
toCustomPath() {
const path = new custom_path2d_1.CustomPath2D, attribute = this.attribute, segments = attribute.segments, parsePoints = points => {
if (points && points.length) {
let isFirst = !0;
const basePoints = [];
if (points.forEach((point => {
var _a, _b;
!1 !== point.defined && (isFirst ? path.moveTo(point.x, point.y) : path.lineTo(point.x, point.y),
basePoints.push({
x: null !== (_a = point.x1) && void 0 !== _a ? _a : point.x,
y: null !== (_b = point.y1) && void 0 !== _b ? _b : point.y
}), isFirst = !1);
})), basePoints.length) {
for (let i = basePoints.length - 1; i >= 0; i--) path.lineTo(basePoints[i].x, basePoints[i].y);
path.closePath();
}
}
};
return attribute.points ? parsePoints(attribute.points) : segments && segments.length && segments.forEach((seg => {
parsePoints(seg.points);
})), path;
}
clone() {
return new Area(Object.assign({}, this.attribute));
}
getNoWorkAnimateAttr() {
return Area.NOWORK_ANIMATE_ATTR;
}
}
function createArea(attributes) {
return new Area(attributes);
}
exports.Area = Area, Area.NOWORK_ANIMATE_ATTR = Object.assign({
segments: 1,
curveType: 1
}, graphic_1.NOWORK_ANIMATE_ATTR), exports.createArea = createArea;
//# sourceMappingURL=area.js.map