UNPKG

ag-charts-community

Version:

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

122 lines 4.16 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 { BBox } from "./bbox"; import { Matrix } from "./matrix"; var Group = /** @class */ (function (_super) { __extends(Group, _super); function Group() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.isContainerNode = true; _this._opacity = 1; return _this; } Object.defineProperty(Group.prototype, "opacity", { get: function () { return this._opacity; }, set: function (value) { value = Math.min(1, Math.max(0, value)); if (this._opacity !== value) { this._opacity = value; this.dirty = true; } }, enumerable: true, configurable: true }); // We consider a group to be boundless, thus any point belongs to it. Group.prototype.containsPoint = function (x, y) { return true; }; Group.prototype.computeBBox = function () { var left = Infinity; var right = -Infinity; var top = Infinity; var bottom = -Infinity; if (this.dirtyTransform) { this.computeTransformMatrix(); } this.children.forEach(function (child) { if (!child.visible) { return; } var bbox = child.computeBBox(); if (!bbox) { return; } if (!(child instanceof Group)) { if (child.dirtyTransform) { child.computeTransformMatrix(); } var matrix = Matrix.flyweight(child.matrix); var parent_1 = child.parent; while (parent_1) { matrix.preMultiplySelf(parent_1.matrix); parent_1 = parent_1.parent; } matrix.transformBBox(bbox, 0, bbox); } var x = bbox.x; var y = bbox.y; if (x < left) { left = x; } if (y < top) { top = y; } if (x + bbox.width > right) { right = x + bbox.width; } if (y + bbox.height > bottom) { bottom = y + bbox.height; } }); return new BBox(left, top, right - left, bottom - top); }; Group.prototype.render = function (ctx) { // A group can have `scaling`, `rotation`, `translation` properties // that are applied to the canvas context before children are rendered, // so all children can be transformed at once. if (this.dirtyTransform) { this.computeTransformMatrix(); } this.matrix.toContext(ctx); var children = this.children; var n = children.length; ctx.globalAlpha *= this.opacity; if (this.dirtyZIndex) { this.dirtyZIndex = false; children.sort(function (a, b) { return a.zIndex - b.zIndex; }); } for (var i = 0; i < n; i++) { var child = children[i]; if (child.visible) { ctx.save(); child.render(ctx); ctx.restore(); } } // debug // this.computeBBox().render(ctx, { // label: this.id, // resetTransform: true, // fillStyle: 'rgba(0, 0, 0, 0.5)' // }); }; Group.className = 'Group'; return Group; }(Node)); export { Group }; //# sourceMappingURL=group.js.map