UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

375 lines (374 loc) 18.3 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.SciChartSubSurface = void 0; var Deleter_1 = require("../../Core/Deleter"); var Rect_1 = require("../../Core/Rect"); var Thickness_1 = require("../../Core/Thickness"); var SciChartSurfaceType_1 = require("../../types/SciChartSurfaceType"); var Size_1 = require("../../types/Size"); var SubChartClippingMode_1 = require("../../types/SubChartClippingMode"); var SubSurfacePositionCoordinateMode_1 = require("../../types/SubSurfacePositionCoordinateMode"); var object_1 = require("../../utils/object"); var performance_1 = require("../../utils/performance"); var translate_1 = require("../../utils/translate"); var BrushCache_1 = require("../Drawing/BrushCache"); var sciChartSubSurfaceCommon_1 = require("./sciChartSubSurfaceCommon"); var SciChartSurface_1 = require("./SciChartSurface"); /** * @summary The {@link SciChartSubSurface} is the surface created within another surface * @description * It can be added using {@link SciChartSubSurface.createSubSurface} method. * * To update the positioning of the {@link SciChartSubSurface}, use {@link SciChartSubSurface.subPosition}; * also you can call {@link SciChartSubSurface.updateSubLayout} to refresh the layout of the sub-surface. * @remarks * It is not possible to have more than one level of nested sub-surfaces. */ var SciChartSubSurface = /** @class */ (function (_super) { __extends(SciChartSubSurface, _super); /** * Creates an instance of the {@link SciChartSubSurface} * @param webAssemblyContext The {@link TSciChart | SciChart 2D WebAssembly Context} containing native methods and * access to our WebGL2 Engine and WebAssembly numerical methods * @param options optional parameters of type {@link ISciChartSubSurfaceOptions} used to configure the {@link SciChartSubSurface} */ function SciChartSubSurface(webAssemblyContext, options) { var _this = this; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s; _this = _super.call(this, webAssemblyContext, options) || this; _this.isSubSurface = true; _this.topSectionClass = "top-section"; _this.leftSectionClass = "left-section"; _this.bottomSectionClass = "bottom-section"; _this.rightSectionClass = "right-section"; _this.isTransparentProperty = true; _this.clippingModeProperty = SubChartClippingMode_1.ESubChartClippingMode.Chart; _this.subPositionProperty = new Rect_1.Rect(0, 0, 1, 1); _this.coordinateModeProperty = SubSurfacePositionCoordinateMode_1.ESubSurfacePositionCoordinateMode.Relative; _this.isVisibleProperty = true; _this.sectionScaleProperty = 1; _this.parentSurfaceProperty = options.parentSurface; _this.subChartContainerId = (_a = options.subSurfaceOptions) === null || _a === void 0 ? void 0 : _a.subChartContainerId; _this.isTransparentProperty = (_c = (_b = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _b === void 0 ? void 0 : _b.isTransparent) !== null && _c !== void 0 ? _c : _this.isTransparent; _this.coordinateModeProperty = (_e = (_d = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _d === void 0 ? void 0 : _d.coordinateMode) !== null && _e !== void 0 ? _e : _this.coordinateMode; _this.parentXAxisIdProperty = (_g = (_f = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _f === void 0 ? void 0 : _f.parentXAxisId) !== null && _g !== void 0 ? _g : _this.parentXAxisId; _this.parentYAxisIdProperty = (_j = (_h = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _h === void 0 ? void 0 : _h.parentYAxisId) !== null && _j !== void 0 ? _j : _this.parentYAxisId; _this.sectionScaleProperty = (_l = (_k = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _k === void 0 ? void 0 : _k.sectionScale) !== null && _l !== void 0 ? _l : _this.sectionScaleProperty; _this.isVisible = (_o = (_m = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _m === void 0 ? void 0 : _m.isVisible) !== null && _o !== void 0 ? _o : _this.isVisible; _this.clippingModeProperty = (_q = (_p = options === null || options === void 0 ? void 0 : options.subSurfaceOptions) === null || _p === void 0 ? void 0 : _p.clippingMode) !== null && _q !== void 0 ? _q : _this.clippingMode; if (_this.subChartContainerId) { _this.subChartContainer = typeof _this.subChartContainerId === "string" ? document.querySelector("[id='".concat(_this.subChartContainerId, "']")) : _this.subChartContainerId; } _this.applyOptions(options.subSurfaceOptions); _this.subPosition = (_s = (_r = options.subSurfaceOptions) === null || _r === void 0 ? void 0 : _r.position) !== null && _s !== void 0 ? _s : _this.subPositionProperty; _this.backgroundFillBrushCache = new BrushCache_1.BrushCache(webAssemblyContext); return _this; } SciChartSubSurface.createSubSurface = function (parentSurface, options) { var _a; var mark = performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.AddSubSurfaceStart, { contextId: options === null || options === void 0 ? void 0 : options.id, parentContextId: parentSurface.id, level: performance_1.EPerformanceDebugLevel.Verbose }); var canvases = sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.createSubSurfaceCanvases(parentSurface); var subSurface = new SciChartSubSurface(parentSurface.webAssemblyContext2D, { canvases: canvases, parentSurface: parentSurface, subSurfaceOptions: SciChartSurface_1.SciChartSurface.resolveOptions(options) }); if (options === null || options === void 0 ? void 0 : options.theme) subSurface.applyTheme(options.theme); parentSurface.addSubChartInternal(subSurface); performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.AddSubSurfaceEnd, { contextId: subSurface.id, relatedId: (_a = mark === null || mark === void 0 ? void 0 : mark.detail) === null || _a === void 0 ? void 0 : _a.relatedId, parentContextId: parentSurface.id, level: performance_1.EPerformanceDebugLevel.Verbose }); return subSurface; }; Object.defineProperty(SciChartSubSurface.prototype, "viewRect", { get: function () { return this.getSubChartRect(); }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "clipRect", { get: function () { // using viewRect not seriesViewRect to support drawing on axes see "Subcharts / Chart in Axes" example return this.clippingMode === SubChartClippingMode_1.ESubChartClippingMode.Chart ? this.parentSurface.viewRect : this.parentSurface.seriesViewRect; }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "clippingMode", { get: function () { return this.clippingModeProperty; }, set: function (value) { if (this.clippingModeProperty !== value) { this.clippingModeProperty = value; this.notifyPropertyChanged("clippingMode"); } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "isTransparent", { /** * @inheritDoc */ get: function () { return this.isTransparentProperty; }, set: function (value) { if (this.isTransparentProperty !== value) { this.isTransparentProperty = value; this.offset = undefined; this.notifyPropertyChanged("isTransparent"); } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "coordinateMode", { /** * @inheritDoc */ get: function () { return this.coordinateModeProperty; }, set: function (coordinateMode) { if (this.coordinateMode !== coordinateMode) { this.coordinateModeProperty = coordinateMode; this.offset = undefined; this.notifyPropertyChanged("coordinateMode"); } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "parentXAxisId", { /** * @inheritDoc */ get: function () { return this.parentXAxisIdProperty; }, set: function (id) { if (this.parentXAxisIdProperty !== id) { this.parentXAxisIdProperty = id; this.offset = undefined; this.notifyPropertyChanged("parentXAxisId"); } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "parentYAxisId", { /** * @inheritDoc */ get: function () { return this.parentYAxisIdProperty; }, set: function (id) { if (this.parentYAxisIdProperty !== id) { this.parentYAxisIdProperty = id; this.offset = undefined; this.notifyPropertyChanged("parentYAxisId"); } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "subPosition", { /** * @inheritDoc */ get: function () { return this.subPositionProperty; }, set: function (value) { if (this.subPositionProperty !== value) { if (!this.parentSurface) { throw new Error("subPosition can only be changed for subCharts."); } if (!(0, object_1.areEqual)(this.subPositionProperty, value)) { this.subPositionProperty = value; this.offset = undefined; this.notifyPropertyChanged("subPosition"); } } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "isVisible", { /** * @inheritDoc */ get: function () { return this.isVisibleProperty; }, set: function (isVisible) { if (this.isVisibleProperty !== isVisible) { this.isVisibleProperty = isVisible; this.offset = undefined; this.notifyPropertyChanged("isVisible"); } }, enumerable: false, configurable: true }); Object.defineProperty(SciChartSubSurface.prototype, "sectionScale", { /** * @inheritDoc */ get: function () { return this.sectionScaleProperty; }, set: function (value) { if (this.sectionScaleProperty !== value) { this.sectionScaleProperty = value; this.offset = undefined; this.notifyPropertyChanged("sectionScale"); } }, enumerable: false, configurable: true }); /** * @inheritDoc */ SciChartSubSurface.prototype.updateSubLayout = function () { if (!this.offset || this.coordinateMode === SubSurfacePositionCoordinateMode_1.ESubSurfacePositionCoordinateMode.DataValue || this.coordinateMode.includes(SubSurfacePositionCoordinateMode_1.ESubSurfacePositionCoordinateMode.DataValue)) { // includes subchart wrapper var subChartOffset = this.calcPadding(); var unscaledSubChartOffset = new Thickness_1.Thickness((0, translate_1.translateToNotScaled)(subChartOffset.top), (0, translate_1.translateToNotScaled)(subChartOffset.right), (0, translate_1.translateToNotScaled)(subChartOffset.bottom), (0, translate_1.translateToNotScaled)(subChartOffset.left)); this.updateWrapper(unscaledSubChartOffset); var subChartWrapperOffset = this.getOffsets(this.subChartContainer); // subSurface offset (after measuring content of the wrapper) this.offset = Thickness_1.Thickness.mergeAdd(subChartOffset, subChartWrapperOffset); } }; Object.defineProperty(SciChartSubSurface.prototype, "parentSurface", { /** * @inheritDoc */ get: function () { return this.parentSurfaceProperty; }, enumerable: false, configurable: true }); /** * @inheritDoc */ SciChartSubSurface.prototype.changeViewportSize = function (pixelWidth, pixelHeight) { this.offset = undefined; this.renderSurface.viewportSize = new Size_1.Size(pixelWidth, pixelHeight); }; /** * @inheritDoc */ SciChartSubSurface.prototype.getSubChartContainer = function () { return this.subChartContainer; }; /** * @inheritDoc */ SciChartSubSurface.prototype.getSubChartRect = function () { return sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.getSubChartRect(this); }; Object.defineProperty(SciChartSubSurface.prototype, "currentWebGlRenderContext", { get: function () { return this.parentSurface.currentWebGlRenderContext; }, enumerable: false, configurable: true }); /** * @inheritDoc */ SciChartSubSurface.prototype.delete = function (clearHtml) { if (clearHtml === void 0) { clearHtml = true; } sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.deleteSubChart(this, clearHtml); this.backgroundFillBrushCache = (0, Deleter_1.deleteSafe)(this.backgroundFillBrushCache); _super.prototype.delete.call(this, false); }; SciChartSubSurface.prototype.getOptions = function () { var _a; var baseSurfaceOptions = _super.prototype.getOptions.call(this); var options = { surfaceType: SciChartSurfaceType_1.ESciChartSurfaceType.Default2D, clippingMode: this.clippingMode, isTransparent: this.isTransparent, isVisible: this.isVisible, sectionScale: this.sectionScale, position: this.subPosition, subChartContainerId: typeof this.subChartContainerId === "string" ? this.subChartContainerId : (_a = this.subChartContainerId) === null || _a === void 0 ? void 0 : _a.id, coordinateMode: this.coordinateMode, parentXAxisId: this.parentXAxisId, parentYAxisId: this.parentYAxisId }; var mergedOptions = Object.assign(baseSurfaceOptions, options); return mergedOptions; }; /** Serializes the current {@link SciChartSubSurface} to a JSON definition. See {@link ISubChartDefinition} */ SciChartSubSurface.prototype.toJSON = function (excludeData) { if (excludeData === void 0) { excludeData = false; } var options = this.getOptions(); var definition = { type: SciChartSurfaceType_1.ESciChartSurfaceType.Default2D, surface: options, xAxes: this.xAxes.asArray().map(function (axis) { return axis.toJSON(); }), yAxes: this.yAxes.asArray().map(function (axis) { return axis.toJSON(); }), series: this.renderableSeries.asArray().map(function (series) { return series.toJSON(excludeData); }), modifiers: this.chartModifiers.asArray().map(function (modifier) { return modifier.toJSON(); }), annotations: this.annotations.asArray().map(function (annotation) { return annotation.toJSON(); }) }; return definition; }; SciChartSubSurface.prototype.calcPadding = function () { return sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.calcPadding(this); }; /** * @inheritDoc */ SciChartSubSurface.prototype.applySciChartBackground = function (background, renderContext) { sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.applySciChartBackground(this, background, renderContext); }; SciChartSubSurface.prototype.updateWrapper = function (subChartOffset) { sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.updateWrapper(this, subChartOffset); }; SciChartSubSurface.prototype.getOffsets = function (subChartContainer) { return sciChartSubSurfaceCommon_1.sciChartSubSurfaceCommon.getOffsets(this, subChartContainer); }; return SciChartSubSurface; }(SciChartSurface_1.SciChartSurface)); exports.SciChartSubSurface = SciChartSubSurface;