UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

899 lines (898 loc) 83.1 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.getDataPointWidthAdjustment = exports.adjustRangeByStrokeThickness = exports.getDelta = exports.getDataPointWidth = exports.BaseRenderableSeries = void 0; var classFactory_1 = require("../../../Builder/classFactory"); var AnimationFiniteStateMachine_1 = require("../../../Core/Animations/AnimationFiniteStateMachine"); var DeletableEntity_1 = require("../../../Core/DeletableEntity"); var Deleter_1 = require("../../../Core/Deleter"); var EventHandler_1 = require("../../../Core/EventHandler"); var IWithXYAxes_1 = require("../../../Core/IWithXYAxes"); var NumberRange_1 = require("../../../Core/NumberRange"); var Rect_1 = require("../../../Core/Rect"); var AnimationType_1 = require("../../../types/AnimationType"); var BaseType_1 = require("../../../types/BaseType"); var ColumnMode_1 = require("../../../types/ColumnMode"); var DataLabelProviderType_1 = require("../../../types/DataLabelProviderType"); var DataPointWidthMode_1 = require("../../../types/DataPointWidthMode"); var DefaultRenderLayer_1 = require("../../../types/DefaultRenderLayer"); var PaletteProviderType_1 = require("../../../types/PaletteProviderType"); var PointMarkerType_1 = require("../../../types/PointMarkerType"); var SeriesType_1 = require("../../../types/SeriesType"); var SurfaceType_1 = require("../../../types/SurfaceType"); var YRangeMode_1 = require("../../../types/YRangeMode"); var guid_1 = require("../../../utils/guid"); var performance_1 = require("../../../utils/performance"); var WebGlRenderContext2D_1 = require("../../Drawing/WebGlRenderContext2D"); var BaseDataSeries_1 = require("../../Model/BaseDataSeries"); var BoxPlotSeriesInfo_1 = require("../../Model/ChartData/BoxPlotSeriesInfo"); var HeatmapSeriesInfo_1 = require("../../Model/ChartData/HeatmapSeriesInfo"); var HlcSeriesInfo_1 = require("../../Model/ChartData/HlcSeriesInfo"); var OhlcSeriesInfo_1 = require("../../Model/ChartData/OhlcSeriesInfo"); var XySeriesInfo_1 = require("../../Model/ChartData/XySeriesInfo"); var XyySeriesInfo_1 = require("../../Model/ChartData/XyySeriesInfo"); var XyzSeriesInfo_1 = require("../../Model/ChartData/XyzSeriesInfo"); var IDataSeries_1 = require("../../Model/IDataSeries"); var IPaletteProvider_1 = require("../../Model/IPaletteProvider"); var XyPointSeriesWrapped_1 = require("../../Model/PointSeries/XyPointSeriesWrapped"); var ExtremeResamplerHelper_1 = require("../../Numerics/Resamplers/ExtremeResamplerHelper"); var ResamplingMode_1 = require("../../Numerics/Resamplers/ResamplingMode"); var ResamplingParams_1 = require("../../Numerics/Resamplers/ResamplingParams"); var RenderPassData_1 = require("../../Services/RenderPassData"); var IThemeProvider_1 = require("../../Themes/IThemeProvider"); var SciChartDefaults_1 = require("../SciChartDefaults"); var SciChartSurfaceBase_1 = require("../SciChartSurfaceBase"); var DpiHelper_1 = require("../TextureManager/DpiHelper"); var animationHelpers_1 = require("./Animations/animationHelpers"); var constants_1 = require("./constants"); var RolloverModifierRenderableSeriesProps_1 = require("./RolloverModifier/RolloverModifierRenderableSeriesProps"); var SeriesHoveredArgs_1 = require("./SeriesHoveredArgs"); var SeriesSelectedArgs_1 = require("./SeriesSelectedArgs"); var SeriesVisibleChangedArgs_1 = require("./SeriesVisibleChangedArgs"); /** * @summary Defines the base class to a Render Series (or Chart Type) in SciChart's High Performance Real-time * {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts} * @remarks * A RenderableSeries defines how data should be rendered. e.g. as a Line Chart, Mountain Chart, Candlestick Chart etc... * This is independent from the {@link BaseDataSeries | DataSeries} which stores the data to render * * See derived types of {@link BaseDataSeries} to find out what data-series are available. * See derived types of {@link IRenderableSeries} to find out what 2D JavaScript Chart types are available. */ var BaseRenderableSeries = /** @class */ (function (_super) { __extends(BaseRenderableSeries, _super); /** * Creates an instance of the {@link BaseRenderableSeries} * @param webAssemblyContext The {@link TSciChart | SciChart WebAssembly Context} containing * native methods and access to our WebGL2 WebAssembly Drawing Engine * @param options optional parameters of type {@link IBaseRenderableSeriesOptions} applied when constructing the series type */ function BaseRenderableSeries(webAssemblyContext, options) { var _this = this; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z; _this = _super.call(this) || this; /** @inheritDoc */ _this.isCollection = false; /** @inheritDoc */ _this.isPolar = false; /** @inheritDoc */ _this.rolloverModifierProps = new RolloverModifierRenderableSeriesProps_1.RolloverModifierRenderableSeriesProps(_this); /** @inheritDoc */ _this.rolloverModifierProps1 = new RolloverModifierRenderableSeriesProps_1.RolloverModifierRenderableSeriesProps(_this, true); /** @inheritDoc */ _this.selected = new EventHandler_1.EventHandler(); /** @inheritDoc */ _this.hovered = new EventHandler_1.EventHandler(); /** @inheritDoc */ _this.isVisibleChanged = new EventHandler_1.EventHandler(); _this.animationQueue = []; _this.paletteProviderProperty = IPaletteProvider_1.DefaultPaletteProvider.createEmpty(); // used to track if registered types were used for function properties, so they can be serialized _this.typeMap = new Map(); _this.opacityProperty = 1; _this.drawingProvidersProperty = []; _this.strokeThicknessProperty = 2; _this.strokeProperty = SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.lineSeriesColor; _this.drawNaNAsProperty = WebGlRenderContext2D_1.ELineDrawMode.DiscontinuousLine; _this.isVisibleProperty = true; _this.isDigitalLineProperty = false; _this.resamplingModeProperty = ResamplingMode_1.EResamplingMode.Auto; _this.resamplingPrecisionProperty = 0; _this.clipToYRangeProperty = false; _this.yRangeModeProperty = YRangeMode_1.EYRangeMode.Drawn; _this.yArrayFilterProperty = undefined; _this.seriesNameProperty = undefined; _this.surfaceRenderOrderProperty = undefined; _this.renderLayerProperty = DefaultRenderLayer_1.EDefaultRenderLayer.SeriesLayer; _this.renderOrderProperty = undefined; _this.isStacked = false; _this.webAssemblyContext = webAssemblyContext; _this.id = (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : (0, guid_1.generateGuid)(); // It is very important to add bind(this) first line in constructor, // otherwise dataSeries passed through the options does not work! _this.dataSeriesDataChanged = _this.dataSeriesDataChanged.bind(_this); _this.effectPropertyChanged = _this.effectPropertyChanged.bind(_this); _this.invalidateParent = _this.invalidateParent.bind(_this); _this.getDataPointWidth = _this.getDataPointWidth.bind(_this); _this.updateAnimationProperties = _this.updateAnimationProperties.bind(_this); _this.beforeAnimationStart = _this.beforeAnimationStart.bind(_this); _this.afterAnimationComplete = _this.afterAnimationComplete.bind(_this); // Need to set dataSeries (not just dataSeriesProperty) because of dataChanged.subscribe _this.dataSeries = (_b = options === null || options === void 0 ? void 0 : options.dataSeries) !== null && _b !== void 0 ? _b : _this.dataSeriesProperty; if (options === null || options === void 0 ? void 0 : options.pointMarker) { if (!("drawSprite" in options.pointMarker)) { if (options.pointMarker.type === PointMarkerType_1.EPointMarkerType.Custom) { options.pointMarker = (0, classFactory_1.createType)(BaseType_1.EBaseType.PointMarker, options.pointMarker.customType, webAssemblyContext, options.pointMarker.options); } else { options.pointMarker = (0, classFactory_1.createType)(BaseType_1.EBaseType.PointMarker, options.pointMarker.type, webAssemblyContext, options.pointMarker.options); } } } _this.pointMarkerProperty = (_c = options === null || options === void 0 ? void 0 : options.pointMarker) !== null && _c !== void 0 ? _c : _this.pointMarkerProperty; _this.strokeProperty = (_d = options === null || options === void 0 ? void 0 : options.stroke) !== null && _d !== void 0 ? _d : _this.strokeProperty; _this.strokeThicknessProperty = (_e = options === null || options === void 0 ? void 0 : options.strokeThickness) !== null && _e !== void 0 ? _e : _this.strokeThicknessProperty; _this.opacityProperty = (_f = options === null || options === void 0 ? void 0 : options.opacity) !== null && _f !== void 0 ? _f : _this.opacityProperty; _this.xAxisIdProperty = (_g = options === null || options === void 0 ? void 0 : options.xAxisId) !== null && _g !== void 0 ? _g : _this.xAxisIdProperty; _this.yAxisIdProperty = (_h = options === null || options === void 0 ? void 0 : options.yAxisId) !== null && _h !== void 0 ? _h : _this.yAxisIdProperty; _this.isVisibleProperty = (_j = options === null || options === void 0 ? void 0 : options.isVisible) !== null && _j !== void 0 ? _j : _this.isVisibleProperty; _this.isDigitalLineProperty = (_k = options === null || options === void 0 ? void 0 : options.isDigitalLine) !== null && _k !== void 0 ? _k : _this.isDigitalLineProperty; _this.resamplingModeProperty = (_l = options === null || options === void 0 ? void 0 : options.resamplingMode) !== null && _l !== void 0 ? _l : _this.resamplingModeProperty; _this.resamplingPrecisionProperty = (_m = options === null || options === void 0 ? void 0 : options.resamplingPrecision) !== null && _m !== void 0 ? _m : _this.resamplingPrecisionProperty; _this.surfaceRenderOrderProperty = (_o = options === null || options === void 0 ? void 0 : options.surfaceRenderOrder) !== null && _o !== void 0 ? _o : _this.surfaceRenderOrderProperty; _this.renderLayerProperty = (_p = options === null || options === void 0 ? void 0 : options.renderLayer) !== null && _p !== void 0 ? _p : _this.renderLayerProperty; _this.renderOrderProperty = (_q = options === null || options === void 0 ? void 0 : options.renderOrder) !== null && _q !== void 0 ? _q : _this.renderOrderProperty; _this.renderNextToProperty = (_r = options === null || options === void 0 ? void 0 : options.renderNextTo) !== null && _r !== void 0 ? _r : _this.renderNextToProperty; if (options === null || options === void 0 ? void 0 : options.effect) { if (!("getNativeEffect" in options.effect)) { options.effect = (0, classFactory_1.createType)(BaseType_1.EBaseType.ShaderEffect, options.effect.type, webAssemblyContext, options.effect.options); } } _this.effectProperty = options === null || options === void 0 ? void 0 : options.effect; if (options === null || options === void 0 ? void 0 : options.paletteProvider) { if (!("onAttached" in options.paletteProvider)) { if (options.paletteProvider.type === PaletteProviderType_1.EPaletteProviderType.Custom) { options.paletteProvider = (0, classFactory_1.createType)(BaseType_1.EBaseType.PaletteProvider, options.paletteProvider.customType, webAssemblyContext, options.paletteProvider.options); } else { options.paletteProvider = (0, classFactory_1.createType)(BaseType_1.EBaseType.PaletteProvider, options.paletteProvider.type, webAssemblyContext, options.paletteProvider.options); } } } _this.paletteProviderProperty = (_s = options === null || options === void 0 ? void 0 : options.paletteProvider) !== null && _s !== void 0 ? _s : _this.paletteProviderProperty; // PaletteProvider.onAttached must be called by the top level series, as the series type is not available here _this.drawNaNAsProperty = (_t = options === null || options === void 0 ? void 0 : options.drawNaNAs) !== null && _t !== void 0 ? _t : _this.drawNaNAsProperty; _this.hitTestProvider = _this.newHitTestProvider(); _this.isSelected = (_u = options === null || options === void 0 ? void 0 : options.isSelected) !== null && _u !== void 0 ? _u : false; _this.isHovered = (_v = options === null || options === void 0 ? void 0 : options.isHovered) !== null && _v !== void 0 ? _v : false; _this.clipToYRangeProperty = (_w = options === null || options === void 0 ? void 0 : options.clipToYRange) !== null && _w !== void 0 ? _w : _this.clipToYRangeProperty; _this.yRangeModeProperty = (_x = options === null || options === void 0 ? void 0 : options.yRangeMode) !== null && _x !== void 0 ? _x : _this.yRangeModeProperty; _this.yArrayFilterProperty = (_y = options === null || options === void 0 ? void 0 : options.yArrayFilter) !== null && _y !== void 0 ? _y : _this.yArrayFilterProperty; _this.seriesNameProperty = (_z = options === null || options === void 0 ? void 0 : options.seriesName) !== null && _z !== void 0 ? _z : _this.seriesNameProperty; if (options === null || options === void 0 ? void 0 : options.onIsVisibleChanged) { if (typeof options.onIsVisibleChanged === "string") { _this.typeMap.set("onIsVisibleChanged", options.onIsVisibleChanged); var visibleChanged_1 = (0, classFactory_1.getFunction)(BaseType_1.EBaseType.OptionFunction, options.onIsVisibleChanged); _this.isVisibleChanged.subscribe(function (args) { return visibleChanged_1(args.sourceSeries, args.isVisible); }); } else { var onIsVisibleChangedCallback_1 = options === null || options === void 0 ? void 0 : options.onIsVisibleChanged; _this.isVisibleChanged.subscribe(function (args) { return onIsVisibleChangedCallback_1(args.sourceSeries, args.isVisible); }); } } if (options === null || options === void 0 ? void 0 : options.onSelectedChanged) { if (typeof options.onSelectedChanged === "string") { _this.typeMap.set("onSelectedChanged", options.onSelectedChanged); var selectionChanged_1 = (0, classFactory_1.getFunction)(BaseType_1.EBaseType.OptionFunction, options.onSelectedChanged); _this.selected.subscribe(function (args) { return selectionChanged_1(args.sourceSeries, args.isSelected); }); } else { var onSelectedChangedCallback_1 = options === null || options === void 0 ? void 0 : options.onSelectedChanged; _this.selected.subscribe(function (args) { return onSelectedChangedCallback_1(args.sourceSeries, args.isSelected); }); } } if (options === null || options === void 0 ? void 0 : options.onHoveredChanged) { if (typeof options.onHoveredChanged === "string") { _this.typeMap.set("onHoveredChanged", options.onHoveredChanged); var hoveredChanged_1 = (0, classFactory_1.getFunction)(BaseType_1.EBaseType.OptionFunction, options.onHoveredChanged); _this.hovered.subscribe(function (args) { return hoveredChanged_1(args.sourceSeries, args.hovered); }); } else { var hoveredChanged_2 = options === null || options === void 0 ? void 0 : options.onHoveredChanged; _this.hovered.subscribe(function (args) { return hoveredChanged_2(args.sourceSeries, args.hovered); }); } } if (options === null || options === void 0 ? void 0 : options.animation) { if (!("toJSON" in options.animation)) { if (options.animation.type === AnimationType_1.EAnimationType.Custom) { options.animation = (0, classFactory_1.createType)(BaseType_1.EBaseType.Animation, options.animation.customType, webAssemblyContext, options.animation.options); } else { options.animation = (0, classFactory_1.createType)(BaseType_1.EBaseType.Animation, options.animation.type, webAssemblyContext, options.animation.options); } } } _this.onDpiChanged = _this.onDpiChanged.bind(_this); _this.resamplerHelper = new ExtremeResamplerHelper_1.ExtremeResamplerHelper(webAssemblyContext); if (options === null || options === void 0 ? void 0 : options.dataLabelProvider) { if (!("draw" in options.dataLabelProvider)) { if (options.dataLabelProvider.type === DataLabelProviderType_1.EDataLabelProviderType.Custom) { options.dataLabelProvider = (0, classFactory_1.createType)(BaseType_1.EBaseType.DataLabelProvider, options.dataLabelProvider.customType, webAssemblyContext, options.dataLabelProvider.options); } else { options.dataLabelProvider = (0, classFactory_1.createType)(BaseType_1.EBaseType.DataLabelProvider, options.dataLabelProvider.type, webAssemblyContext, options.dataLabelProvider.options); } } } _this.dataLabelProviderProperty = options === null || options === void 0 ? void 0 : options.dataLabelProvider; if (_this.dataLabelProviderProperty) { _this.dataLabelProviderProperty.onAttach(webAssemblyContext, _this); } _this.addDrawingProviders(webAssemblyContext, options); return _this; } /** @inheritDoc */ BaseRenderableSeries.prototype.applyTheme = function (themeProvider) { var previousThemeProvider = this.parentSurface.previousThemeProvider; if (this.rolloverModifierProps.tooltipTextColor === previousThemeProvider.textAnnotationForeground) { this.rolloverModifierProps.tooltipTextColor = themeProvider.textAnnotationForeground; } if (this.rolloverModifierProps.tooltipColor === previousThemeProvider.textAnnotationBackground) { this.rolloverModifierProps.tooltipColor = themeProvider.textAnnotationBackground; } if (this.rolloverModifierProps.markerColor === previousThemeProvider.textAnnotationBackground) { this.rolloverModifierProps.markerColor = themeProvider.textAnnotationBackground; } }; Object.defineProperty(BaseRenderableSeries.prototype, "parentSurface", { /** @inheritDoc */ get: function () { return this.parentSurfaceProperty; }, /** @inheritDoc */ set: function (value) { this.parentSurfaceProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.PARENT_SURFACE); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "drawingProviders", { /** @inheritDoc */ get: function () { return this.drawingProvidersProperty; }, /** @inheritDoc */ set: function (value) { this.drawingProvidersProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.DRAWING_PROVIDERS); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "isSelected", { /** @inheritDoc */ get: function () { return this.isSelectedProperty; }, /** @inheritDoc */ set: function (isSelected) { var _a; if (this.valueChanged(this.isSelectedProperty, isSelected)) { this.isSelectedProperty = isSelected; (_a = this.selected) === null || _a === void 0 ? void 0 : _a.raiseEvent(new SeriesSelectedArgs_1.SeriesSelectedArgs(this, isSelected)); this.notifyPropertyChanged(constants_1.PROPERTY.IS_SELECTED); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "isHovered", { /** @inheritDoc */ get: function () { return this.isHoveredProperty; }, /** @inheritDoc */ set: function (isHovered) { var _a; if (this.valueChanged(this.isHoveredProperty, isHovered)) { this.isHoveredProperty = isHovered; (_a = this.hovered) === null || _a === void 0 ? void 0 : _a.raiseEvent(new SeriesHoveredArgs_1.SeriesHoveredArgs(this, isHovered)); this.notifyPropertyChanged(constants_1.PROPERTY.HOVERED); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "paletteProvider", { /** @inheritDoc */ get: function () { return this.paletteProviderProperty; }, /** @inheritDoc */ set: function (paletteProvider) { this.setPaletteProvider(paletteProvider); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "isDigitalLine", { /** @inheritDoc */ get: function () { return this.isDigitalLineProperty; }, /** @inheritDoc */ set: function (isDigitalLine) { this.isDigitalLineProperty = isDigitalLine; this.notifyPropertyChanged(constants_1.PROPERTY.IS_DIGITAL_LINE); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "isVisible", { /** @inheritDoc */ get: function () { return this.isVisibleProperty; }, /** @inheritDoc */ set: function (isVisible) { var _a; if (this.valueChanged(this.isVisibleProperty, isVisible)) { this.isVisibleProperty = isVisible; if (!isVisible) { if (this.rolloverModifierProps.marker && this.rolloverModifierProps.tooltip) { this.rolloverModifierProps.marker.suspendInvalidate(); this.rolloverModifierProps.tooltip.suspendInvalidate(); this.rolloverModifierProps.marker.isHidden = true; this.rolloverModifierProps.tooltip.isHidden = true; this.rolloverModifierProps.tooltip.x1 = undefined; this.rolloverModifierProps.tooltip.y1 = undefined; } // TODO should be more general than looking at series type if (this.type === SeriesType_1.ESeriesType.BandSeries && this.rolloverModifierProps1.marker && this.rolloverModifierProps1.tooltip) { this.rolloverModifierProps1.marker.suspendInvalidate(); this.rolloverModifierProps1.tooltip.suspendInvalidate(); this.rolloverModifierProps1.marker.isHidden = true; this.rolloverModifierProps1.tooltip.isHidden = true; this.rolloverModifierProps1.tooltip.x1 = undefined; this.rolloverModifierProps1.tooltip.y1 = undefined; } } else { // Force rebuild of resample params and indexRange this.resamplingParams = undefined; } (_a = this.isVisibleChanged) === null || _a === void 0 ? void 0 : _a.raiseEvent(new SeriesVisibleChangedArgs_1.SeriesVisibleChangedArgs(this, isVisible)); this.notifyPropertyChanged(constants_1.PROPERTY.IS_VISIBLE); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "pointMarker", { /** @inheritDoc */ get: function () { return this.pointMarkerProperty; }, /** @inheritDoc */ set: function (pointMarker) { if (this.pointMarkerProperty) { this.pointMarkerProperty.invalidateParentCallback = undefined; } this.pointMarkerProperty = pointMarker; this.notifyPropertyChanged(constants_1.PROPERTY.POINT_MARKER); if (this.pointMarkerProperty) { this.pointMarkerProperty.invalidateParentCallback = this.invalidateParent; } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "drawNaNAs", { /** @inheritDoc */ get: function () { return this.drawNaNAsProperty; }, /** @inheritDoc */ set: function (drawNaNAs) { this.drawNaNAsProperty = drawNaNAs; this.notifyPropertyChanged(constants_1.PROPERTY.DRAW_NAN_AS); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "stroke", { /** @inheritDoc */ get: function () { return (0, IThemeProvider_1.stripAutoColor)(this.strokeProperty); }, /** @inheritDoc */ set: function (htmlColorCode) { if (this.strokeProperty !== htmlColorCode) { this.strokeProperty = htmlColorCode; this.notifyPropertyChanged(constants_1.PROPERTY.STROKE); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "strokeThickness", { /** @inheritDoc */ get: function () { return this.strokeThicknessProperty; }, /** @inheritDoc */ set: function (value) { if (this.strokeThicknessProperty !== value) { this.strokeThicknessProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.STROKE_THICKNESS); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "opacity", { /** @inheritDoc */ get: function () { return this.opacityProperty; }, /** @inheritDoc */ set: function (value) { if (this.opacityProperty !== value) { this.opacityProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.OPACITY); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "xAxisId", { /** @inheritDoc */ get: function () { return this.xAxisIdProperty; }, /** @inheritDoc */ set: function (id) { if (id !== this.xAxisIdProperty) { this.xAxisIdProperty = id; this.xAxisProperty = undefined; this.notifyPropertyChanged(constants_1.PROPERTY.XAXIS_ID); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "xAxis", { /** @inheritDoc */ get: function () { return this.xAxisProperty; }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "yAxis", { /** @inheritDoc */ get: function () { return this.yAxisProperty; }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "yAxisId", { /** @inheritDoc */ get: function () { return this.yAxisIdProperty; }, /** @inheritDoc */ set: function (id) { if (id !== this.yAxisIdProperty) { this.yAxisIdProperty = id; this.yAxisProperty = undefined; this.notifyPropertyChanged(constants_1.PROPERTY.YAXIS_ID); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "dataSeries", { /** @inheritDoc */ get: function () { return this.dataSeriesProperty; }, /** @inheritDoc */ set: function (dataSeries) { var _a, _b; if (this.dataSeriesProperty) { var xAxis = this.xAxis; if (xAxis && xAxis.isCategoryAxis) { xAxis.clearCoordCalcCache(); } } (_a = this.dataSeriesProperty) === null || _a === void 0 ? void 0 : _a.dataChanged.unsubscribe(this.dataSeriesDataChanged); this.dataSeriesProperty = dataSeries; (_b = this.dataSeriesProperty) === null || _b === void 0 ? void 0 : _b.dataChanged.subscribe(this.dataSeriesDataChanged); this.notifyPropertyChanged(constants_1.PROPERTY.DATA_SERIES); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "enableDrawingOptimisations", { /** @inheritDoc */ get: function () { return this.resamplingModeProperty !== ResamplingMode_1.EResamplingMode.None; }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "effect", { /** * Gets an optional {@link ShaderEffect} for modifying the render output of this {@link IRenderableSeries} * @remarks Options include {@link GlowEffect} and {@link ShadowEffect}. Apply an effect to see how it modifies rendering! */ get: function () { return this.effectProperty; }, /** * Sets an optional {@link ShaderEffect} for modifying the render output of this {@link IRenderableSeries} * @remarks Options include {@link GlowEffect} and {@link ShadowEffect}. Apply an effect to see how it modifies rendering! */ set: function (effect) { var _a, _b; (_a = this.effectProperty) === null || _a === void 0 ? void 0 : _a.propertyChanged.unsubscribe(this.effectPropertyChanged); this.effectProperty = effect; (_b = this.effectProperty) === null || _b === void 0 ? void 0 : _b.propertyChanged.subscribe(this.effectPropertyChanged); this.notifyPropertyChanged(constants_1.PROPERTY.EFFECT); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "resamplingMode", { /** @inheritDoc */ get: function () { return this.resamplingModeProperty; }, /** @inheritDoc */ set: function (value) { this.resamplingModeProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.RESAMPLING_MODE); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "resamplingPrecision", { /** @inheritDoc */ get: function () { return this.resamplingPrecisionProperty; }, /** @inheritDoc */ set: function (value) { this.resamplingPrecisionProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.RESAMPLING_PRECISION); }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "clipToYRange", { /** * If true, the drawing will be clipped to the visibleRange of the associated Y Axis. * This is only really relevant if you are using Stacked Y Axes and do not want the series to be drawn outside that axis range */ get: function () { return this.clipToYRangeProperty; }, set: function (value) { if (this.clipToYRangeProperty !== value) { this.clipToYRangeProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.CLIPTOYRANGE); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "yRangeMode", { /** @inheritDoc */ get: function () { return this.yRangeModeProperty; }, set: function (value) { if (this.yRangeModeProperty !== value) { this.yRangeModeProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.YRANGEMODE); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "yArrayFilter", { /** @inheritDoc */ get: function () { return this.yArrayFilterProperty; }, set: function (value) { if (this.yArrayFilterProperty !== value) { this.yArrayFilterProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.YARRAYFILTER); } }, enumerable: false, configurable: true }); Object.defineProperty(BaseRenderableSeries.prototype, "seriesName", { /** @inheritDoc */ get: function () { var _a; return (_a = this.seriesNameProperty) !== null && _a !== void 0 ? _a : this.getDataSeriesName(); }, set: function (value) { if (this.seriesNameProperty !== value) { this.seriesNameProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.SERIES_NAME); } }, enumerable: false, configurable: true }); /** @inheritDoc */ BaseRenderableSeries.prototype.getSurfaceRenderOrder = function () { var _a, _b; return (_a = this.surfaceRenderOrderProperty) !== null && _a !== void 0 ? _a : (_b = this.parentSurface) === null || _b === void 0 ? void 0 : _b.getSurfaceRenderOrder(); }; /** @inheritDoc */ BaseRenderableSeries.prototype.setSurfaceRenderOrder = function (value) { if (this.surfaceRenderOrderProperty != value) { this.surfaceRenderOrderProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.SURFACE_RENDER_ORDER); } }; /** * The render layer grouping within which the series will be draw. Defaults to EDefaultRenderLayer.SeriesLayer (5) */ BaseRenderableSeries.prototype.getRenderLayer = function () { if (this.renderLayerProperty === DefaultRenderLayer_1.EDefaultRenderLayer.SeriesLayer) { if (this.isSelected) return DefaultRenderLayer_1.EDefaultRenderLayer.SelectedSeriesLayer; if (this.isHovered) return DefaultRenderLayer_1.EDefaultRenderLayer.HoveredSeriesLayer; } return this.renderLayerProperty; }; /** * The render layer grouping within which the series will be draw. Defaults to EDefaultRenderLayer.SeriesLayer (5) */ BaseRenderableSeries.prototype.setRenderLayer = function (value) { if (this.renderLayerProperty != value) { this.renderLayerProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.RENDER_LAYER); } }; /** @inheritDoc */ BaseRenderableSeries.prototype.getRenderOrder = function () { return this.renderOrderProperty; }; /** @inheritDoc */ BaseRenderableSeries.prototype.setRenderOrder = function (value) { if (this.renderOrderProperty != value) { this.renderOrderProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.RENDER_LAYER); } }; /** @inheritDoc */ BaseRenderableSeries.prototype.setRenderNextTo = function (renderable, offset) { if (offset === void 0) { offset = 0; } if (renderable === undefined) { this.renderNextToProperty = undefined; } else { this.renderNextToProperty = { renderable: renderable, offset: offset }; } }; /** @inheritDoc */ BaseRenderableSeries.prototype.getRenderNextTo = function () { return this.renderNextToProperty; }; Object.defineProperty(BaseRenderableSeries.prototype, "isSpline", { /** @inheritDoc */ get: function () { return [SeriesType_1.ESeriesType.SplineBandSeries, SeriesType_1.ESeriesType.SplineLineSeries, SeriesType_1.ESeriesType.SplineMountainSeries].includes(this.type); }, enumerable: false, configurable: true }); BaseRenderableSeries.prototype.getResamplingParams = function () { return this.resamplingParams; }; /** @inheritDoc */ BaseRenderableSeries.prototype.draw = function (renderContext, renderPassData) { var _this = this; var _a, _b, _c, _d, _e, _f, _g, _h; var mark = performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.DrawSingleSeriesStart, { contextId: this.id, parentContextId: (_a = this.parentSurface) === null || _a === void 0 ? void 0 : _a.id, level: performance_1.EPerformanceDebugLevel.Verbose }); this.currentRenderPassData = renderPassData; (_b = this.hitTestProvider) === null || _b === void 0 ? void 0 : _b.update(renderPassData); if (this.canDraw) { var nativeContext = renderContext.getNativeContext(); var viewRect_1 = (_c = this.parentSurface) === null || _c === void 0 ? void 0 : _c.seriesViewRect; try { renderContext.pushShaderEffect(this.effect); if (this.clipToYRange) { var _j = renderPassData.xCoordinateCalculator, x = _j.offset, width = _j.viewportDimension; var _k = renderPassData.yCoordinateCalculator, y = _k.offset, height = _k.viewportDimension; if (renderPassData.isVerticalChart) { var clipRect = new Rect_1.Rect(viewRect_1.x + y, viewRect_1.y + x, height, width); renderContext.setClipRect(clipRect); } else { var clipRect = new Rect_1.Rect(viewRect_1.x + x, viewRect_1.y + y, width, height); renderContext.setClipRect(clipRect); } } this.drawingProviders.forEach(function (dp) { var _a; if ((_a = _this.xAxis) === null || _a === void 0 ? void 0 : _a.isVerticalChart) { // For the vertical chart because passing verticalChart arg into the engine rotates render context // we need to reset it to avoid double rotation if (viewRect_1) renderContext.setTranslationRotationAndClip(viewRect_1, viewRect_1.x, viewRect_1.y); } if (_this.renderDataTransform && _this.renderDataTransform.drawingProviders.includes(dp)) { var transformedRPD = _this.renderDataTransform.runTransform(renderPassData); dp.draw(renderContext, transformedRPD); } else { dp.draw(renderContext, renderPassData); } }); } finally { if (this.clipToYRange) { // Reset clip rect renderContext.setClipRect(viewRect_1); } renderContext.popShaderEffect(); } if (this.dataLabelProvider) { var dlmark = performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.GenerateDataLabelsStart, { contextId: this.id, parentContextId: (_d = this.parentSurface) === null || _d === void 0 ? void 0 : _d.id, level: performance_1.EPerformanceDebugLevel.Verbose }); this.dataLabelProvider.generateDataLabels(renderContext, renderPassData); // Don't draw Text here. Renderer will call draw once all text has been created to allow for global layout adjustments performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.GenerateDataLabelsEnd, { contextId: this.id, parentContextId: (_e = this.parentSurface) === null || _e === void 0 ? void 0 : _e.id, relatedId: (_f = dlmark === null || dlmark === void 0 ? void 0 : dlmark.detail) === null || _f === void 0 ? void 0 : _f.relatedId, level: performance_1.EPerformanceDebugLevel.Verbose }); } } this.resamplingParams = undefined; performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.DrawSingleSeriesEnd, { contextId: this.id, parentContextId: (_g = this.parentSurface) === null || _g === void 0 ? void 0 : _g.id, relatedId: (_h = mark === null || mark === void 0 ? void 0 : mark.detail) === null || _h === void 0 ? void 0 : _h.relatedId, level: performance_1.EPerformanceDebugLevel.Verbose }); }; /** @inheritDoc */ BaseRenderableSeries.prototype.delete = function () { this.drawingProviders.forEach(function (dp) { return dp.delete(); }); this.drawingProviders = []; this.dataSeries = (0, Deleter_1.deleteSafe)(this.dataSeries); this.effect = (0, Deleter_1.deleteSafe)(this.effect); this.pointMarker = (0, Deleter_1.deleteSafe)(this.pointMarker); this.resamplerHelper = (0, Deleter_1.deleteSafe)(this.resamplerHelper); this.pointSeries = (0, Deleter_1.deleteSafe)(this.pointSeries); this.dataLabelProviderProperty = (0, Deleter_1.deleteSafe)(this.dataLabelProvider); this.renderDataTransformProperty = (0, Deleter_1.deleteSafe)(this.renderDataTransform); }; /** @inheritDoc */ BaseRenderableSeries.prototype.getXRange = function () { return this.dataSeries.getXRange(IDataSeries_1.EDataSeriesValueType.Default); }; /** @inheritDoc */ BaseRenderableSeries.prototype.getYRange = function (xVisibleRange, isXCategoryAxis) { if (isXCategoryAxis === void 0) { isXCategoryAxis = false; } var dataSeriesValueType = this.isRunningDataAnimation ? IDataSeries_1.EDataSeriesValueType.FinalAnimationValues : IDataSeries_1.EDataSeriesValueType.Default; // We can't just check and use this.pointSeries because it may be filled, but out of date. var pointSeries = this.getResampledPointSeries(isXCategoryAxis); // if there is a transform as well, it will run off this.pointSeries if (this.renderDataTransform && this.renderDataTransform.useForYRange) { this.updateTransformedValues(dataSeriesValueType); // TODO transforms probably need a way to provide their own YRange method, as you don't know what shape the data is here. return (0, BaseDataSeries_1.getWindowedYRange)(this.webAssemblyContext, this.transformedRenderPassData.pointSeries.xValues, this.transformedRenderPassData.pointSeries.yValues, pointSeries && isXCategoryAxis ? new NumberRange_1.NumberRange(0, pointSeries.count - 1) : xVisibleRange, true, isXCategoryAxis, this.dataSeries.dataDistributionCalculator.isSortedAscending, this.dataSeries.dataDistributionCalculator.containsNaN); } // Use resampled data for autoRange if possible if (pointSeries) { return (0, BaseDataSeries_1.getWindowedYRange)(this.webAssemblyContext, pointSeries.xValues, pointSeries.yValues, isXCategoryAxis ? new NumberRange_1.NumberRange(0, pointSeries.count - 1) : xVisibleRange, true, isXCategoryAxis, this.dataSeries.dataDistributionCalculator.isSortedAscending, this.dataSeries.dataDistributionCalculator.containsNaN); } return this.dataSeries.getWindowedYRange(xVisibleRange, true, isXCategoryAxis, dataSeriesValueType, this.yRangeMode); }; BaseRenderableSeries.prototype.getResampledPointSeries = function (isXCategoryAxis) { var _a, _b; if (isXCategoryAxis === void 0) { isXCategoryAxis = false; } var pointSeries; if (((_a = this.parentSurface) === null || _a === void 0 ? void 0 : _a.renderSurface) && this.supportsResampling) { var prevRPD = this.getCurrentRenderPassData(); if (!this.resamplingParams) { var _c = this.parentSurface.renderSurface.viewportSize, width = _c.width, height = _c.height; var viewRect = (_b = this.parentSurface.seriesViewRect) !== null && _b !== void 0 ? _b : Rect_1.Rect.create(0, 0, width, height); var xAxis = this.xAxis; var rp = new ResamplingParams_1.ResamplingParams(viewRect, this, xAxis); if (this.needsResampling(rp)) { var resamplingHash = ExtremeResamplerHelper_1.ExtremeResamplerHelper.calculateResamplingHash(this, rp); var useFromCache = Boolean(prevRPD && prevRPD.resamplingHash === resamplingHash); // Resample if necessary. This also sets this.pointSeries pointSeries = useFromCache ? prevRPD.pointSeries : this.toPointSeries(rp); this.currentRenderPassData = new RenderPassData_1.RenderPassData(this.getIndicesRange(this.xAxis.visibleRange, isXCategoryAxis), this.xAxis.getCurrentCoordinateCalculator, this.yAxis.getCurrentCoordinateCalculator, this.xAxis.isVerticalChart, pointSeries, resamplingHash); } } else if (this.resamplingParams.resampleRequired) { // toPointSeries has been run this render and currentRenderPassData has been set. pointSeries = this.currentRenderPassData.pointSeries; } } return pointSeries; }; /** @inheritDoc */ BaseRenderableSeries.prototype.notifyPropertyChanged = function (propertyName) { this.drawingProviders.forEach(function (dp) { return dp.onSeriesPropertyChange(propertyName); }); this.invalidateParent(); }; /** * @description Calculates data point width in pixels * @param xCoordCalc * @param widthFraction * @param widthMode */ BaseRenderableSeries.prototype.getDataPointWidth = function (xCoordCalc, widthFraction, widthMode) { var xValues = this.dataSeries.getNativeXValues(); var seriesViewRectWidth = xCoordCalc.viewportDimension; var isCategoryAxis = xCoordCalc.isCategoryCoordinateCalculator; if (widthMode === DataPointWidthMode_1.EDataPointWidthMode.Range) { var range = xCoordCalc.visibleMax - xCoordCalc.visibleMin; // This treats dataPointWidth as "xRange per column" return (xCoordCalc.viewportDimension / range) * widthFraction; } else if (widthMode === DataPointWidthMode_1.EDataPointWidthMode.Absolute) { return widthFraction; } else { // Relative var candleWidth = Math.floor((0, exports.getDataPointWidth)(xValues, xCoordCalc, seriesViewRectWidth, widthFraction, isCategoryAxis, this.dataSeries.dataDistributionCalculator.isSortedAscending, this.webAssemblyContext)); if (candleWidth % 2 !== 0) { candleWidth -= 1; } if (candleWidth <= 1) { candleWidth = 1; } return candleWidth;