UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

85 lines (81 loc) 3.97 kB
import { isEqual, merge } from "@visactor/vutils"; import { BaseModel } from "./base-model"; import { LayoutItem } from "../layout/layout-item"; export class LayoutModel extends BaseModel { constructor() { super(...arguments), this.layoutType = "normal", this.layoutLevel = 0, this.layoutZIndex = 0, this._forceLayoutTag = !1, this._layout = null, this._orient = null, this._layoutRect = { width: 0, height: 0 }, this._layoutStartPos = { x: 0, y: 0 }, this._isLayout = !0, this.getGraphicBounds = () => this._layout ? { x1: this._layout.getLayoutStartPoint().x, y1: this._layout.getLayoutStartPoint().y, x2: this._layout.getLayoutStartPoint().x + this._layout.getLayoutRect().width, y2: this._layout.getLayoutStartPoint().y + this._layout.getLayoutRect().height } : { x1: 0, x2: 0, y1: 0, y2: 0 }, this._transformLayoutRect = null, this._transformLayoutPosition = null, this._transformLayoutPadding = null; } get layoutOrient() { return this._orient; } set layoutOrient(v) { this._orient = v, this._layout && (this._layout.layoutOrient = v); } initLayout() { "none" !== this.layoutType && (this._layout = new LayoutItem(this, { layoutType: this.layoutType, layoutLevel: this.layoutLevel, layoutOrient: this._orient, transformLayoutRect: this._transformLayoutRect, transformLayoutPosition: this._transformLayoutPosition, transformLayoutPadding: this._transformLayoutPadding }), this._orient && "radius" !== this._orient && "angle" !== this._orient && this._layout && (this._layout.layoutOrient = this._orient)); } onLayoutStart(layoutRect, viewRect) { this._isLayout = !0, super.onLayoutStart(layoutRect, viewRect); } onLayoutEnd() { super.onLayoutEnd(), this.updateLayoutAttribute(); const layoutRect = this.getLayoutRect(); !this._forceLayoutTag && isEqual(this._lastLayoutRect, layoutRect) || (this._lastLayoutRect = Object.assign({}, layoutRect)), this._forceLayoutTag = !1, this._isLayout = !1; } afterSetLayoutStartPoint(_pos) {} _forceLayout() { var _a, _b; this._isLayout || (null === (_a = this._layout) || void 0 === _a || _a.setWillLayoutTag(), this._forceLayoutTag = !0, null === (_b = this._option.globalInstance.getChart()) || void 0 === _b || _b.setLayoutTag(!0)); } getLayoutStartPoint() { return this._layout ? this._layout.getLayoutStartPoint() : this._layoutStartPos; } setLayoutStartPosition(pos) { return this._layout ? this._layout.setLayoutStartPosition(pos) : this._layoutStartPos = merge(this._layoutStartPos, pos); } getLayoutRect() { return this._layout ? this._layout.getLayoutRect() : this._layoutRect; } setLayoutRect(rect, levelMap) { return this._layout ? this._layout.setLayoutRect(rect) : this._lastLayoutRect = merge(this._layoutRect, rect); } getLastComputeOutBounds() { var _a; return null === (_a = this._layout) || void 0 === _a ? void 0 : _a.getLastComputeOutBounds(); } setAttrFromSpec() { var _a, _b, _c, _d, _e; super.setAttrFromSpec(), this.layoutClip = null !== (_a = this._spec.clip) && void 0 !== _a ? _a : this.layoutClip, this.layoutZIndex = null !== (_b = this._spec.zIndex) && void 0 !== _b ? _b : this.layoutZIndex, this.layoutType = null !== (_c = this._spec.layoutType) && void 0 !== _c ? _c : this.layoutType, this._orient = null !== (_d = this._spec.orient) && void 0 !== _d ? _d : this._orient, this.layoutLevel = null !== (_e = this._spec.layoutLevel) && void 0 !== _e ? _e : this.layoutLevel; } } //# sourceMappingURL=layout-model.js.map