UNPKG

ag-charts-community

Version:

Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue

160 lines 5.04 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Node } from "./node"; import { Path2D } from "./path2D"; import { BBox } from "./bbox"; /** * Acts as `Group` node but with specified bounds that form a rectangle. * Any parts of the child nodes outside that rectangle will not be visible. * Unlike the `Group` node, the `ClipRect` node cannot be transformed. */ var ClipRect = /** @class */ (function (_super) { __extends(ClipRect, _super); function ClipRect() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.isContainerNode = true; _this.path = new Path2D(); _this._enabled = true; _this._dirtyPath = true; _this._x = 0; _this._y = 0; _this._width = 10; _this._height = 10; return _this; } ClipRect.prototype.containsPoint = function (x, y) { var point = this.transformPoint(x, y); return point.x >= this.x && point.x <= this.x + this.width && point.y >= this.y && point.y <= this.y + this.height; }; Object.defineProperty(ClipRect.prototype, "enabled", { get: function () { return this._enabled; }, set: function (value) { if (this._enabled !== value) { this._enabled = value; this.dirty = true; } }, enumerable: true, configurable: true }); Object.defineProperty(ClipRect.prototype, "dirtyPath", { get: function () { return this._dirtyPath; }, set: function (value) { if (this._dirtyPath !== value) { this._dirtyPath = value; if (value) { this.dirty = true; } } }, enumerable: true, configurable: true }); Object.defineProperty(ClipRect.prototype, "x", { get: function () { return this._x; }, set: function (value) { if (this._x !== value) { this._x = value; this.dirtyPath = true; } }, enumerable: true, configurable: true }); Object.defineProperty(ClipRect.prototype, "y", { get: function () { return this._y; }, set: function (value) { if (this._y !== value) { this._y = value; this.dirtyPath = true; } }, enumerable: true, configurable: true }); Object.defineProperty(ClipRect.prototype, "width", { get: function () { return this._width; }, set: function (value) { if (this._width !== value) { this._width = value; this.dirtyPath = true; } }, enumerable: true, configurable: true }); Object.defineProperty(ClipRect.prototype, "height", { get: function () { return this._height; }, set: function (value) { if (this._height !== value) { this._height = value; this.dirtyPath = true; } }, enumerable: true, configurable: true }); ClipRect.prototype.updatePath = function () { var path = this.path; path.clear(); path.rect(this.x, this.y, this.width, this.height); this.dirtyPath = false; }; ClipRect.prototype.computeBBox = function () { var _a = this, x = _a.x, y = _a.y, width = _a.width, height = _a.height; return new BBox(x, y, width, height); }; ClipRect.prototype.render = function (ctx) { if (this.enabled) { if (this.dirtyPath) { this.updatePath(); } this.path.draw(ctx); ctx.clip(); } var children = this.children; var n = children.length; for (var i = 0; i < n; i++) { ctx.save(); var child = children[i]; if (child.visible) { child.render(ctx); } ctx.restore(); } // debug // this.computeBBox().render(ctx, { // label: this.id, // resetTransform: true, // fillStyle: 'rgba(0, 0, 0, 0.5)' // }); }; ClipRect.className = 'ClipRect'; return ClipRect; }(Node)); export { ClipRect }; //# sourceMappingURL=clipRect.js.map