UNPKG

ag-charts-community

Version:

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

168 lines 5.67 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var hdpiCanvas_1 = require("../canvas/hdpiCanvas"); var id_1 = require("../util/id"); var Scene = /** @class */ (function () { // As a rule of thumb, constructors with no parameters are preferred. // A few exceptions are: // - we absolutely need to know something at construction time (document) // - knowing something at construction time meaningfully improves performance (width, height) function Scene(document, width, height) { var _this = this; if (document === void 0) { document = window.document; } this.id = id_1.createId(this); this._dirty = false; this.animationFrameId = 0; this._root = null; this.debug = { renderFrameIndex: false, renderBoundingBoxes: false }; this._frameIndex = 0; this.render = function () { var _a; var _b = _this, ctx = _b.ctx, root = _b.root, pendingSize = _b.pendingSize; _this.animationFrameId = 0; if (pendingSize) { (_a = _this.canvas).resize.apply(_a, __spread(pendingSize)); _this.pendingSize = undefined; } if (root && !root.visible) { _this.dirty = false; return; } // start with a blank canvas, clear previous drawing ctx.clearRect(0, 0, _this.width, _this.height); if (root) { ctx.save(); if (root.visible) { root.render(ctx); } ctx.restore(); } _this._frameIndex++; if (_this.debug.renderFrameIndex) { ctx.fillStyle = 'white'; ctx.fillRect(0, 0, 40, 15); ctx.fillStyle = 'black'; ctx.fillText(_this.frameIndex.toString(), 2, 10); } _this.dirty = false; }; this.canvas = new hdpiCanvas_1.HdpiCanvas(document, width, height); this.ctx = this.canvas.context; } Object.defineProperty(Scene.prototype, "container", { get: function () { return this.canvas.container; }, set: function (value) { this.canvas.container = value; }, enumerable: true, configurable: true }); Scene.prototype.download = function (fileName) { this.canvas.download(fileName); }; Scene.prototype.getDataURL = function (type) { return this.canvas.getDataURL(type); }; Object.defineProperty(Scene.prototype, "width", { get: function () { return this.pendingSize ? this.pendingSize[0] : this.canvas.width; }, enumerable: true, configurable: true }); Object.defineProperty(Scene.prototype, "height", { get: function () { return this.pendingSize ? this.pendingSize[1] : this.canvas.height; }, enumerable: true, configurable: true }); Scene.prototype.resize = function (width, height) { width = Math.round(width); height = Math.round(height); if (width === this.width && height === this.height) { return; } this.pendingSize = [width, height]; this.dirty = true; }; Object.defineProperty(Scene.prototype, "dirty", { get: function () { return this._dirty; }, set: function (dirty) { if (dirty) { if (!this._dirty) { this.animationFrameId = requestAnimationFrame(this.render); } } else if (this.animationFrameId) { cancelAnimationFrame(this.animationFrameId); this.animationFrameId = 0; } this._dirty = dirty; }, enumerable: true, configurable: true }); Object.defineProperty(Scene.prototype, "root", { get: function () { return this._root; }, set: function (node) { if (node === this._root) { return; } if (this._root) { this._root._setScene(); } this._root = node; if (node) { // If `node` is the root node of another scene ... if (node.parent === null && node.scene && node.scene !== this) { node.scene.root = null; } node._setScene(this); } this.dirty = true; }, enumerable: true, configurable: true }); Object.defineProperty(Scene.prototype, "frameIndex", { get: function () { return this._frameIndex; }, enumerable: true, configurable: true }); Scene.className = 'Scene'; return Scene; }()); exports.Scene = Scene; //# sourceMappingURL=scene.js.map