UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

347 lines (346 loc) 18.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 __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FastBoxPlotRenderableSeries = void 0; var Deleter_1 = require("../../../Core/Deleter"); var NumberRange_1 = require("../../../Core/NumberRange"); var AxisType_1 = require("../../../types/AxisType"); var DataPointWidthMode_1 = require("../../../types/DataPointWidthMode"); var SeriesType_1 = require("../../../types/SeriesType"); var IDataSeries_1 = require("../../Model/IDataSeries"); var BoxPlotPointSeriesWrapped_1 = require("../../Model/PointSeries/BoxPlotPointSeriesWrapped"); var IThemeProvider_1 = require("../../Themes/IThemeProvider"); var SciChartSurfaceBase_1 = require("../SciChartSurfaceBase"); var BaseRenderableSeries_1 = require("./BaseRenderableSeries"); var constants_1 = require("./constants"); var BoxPlotSeriesDrawingProvider_1 = require("./DrawingProviders/BoxPlotSeriesDrawingProvider"); var PointMarkerDrawingProvider_1 = require("./DrawingProviders/PointMarkerDrawingProvider"); var BoxPlotSeriesHitTestProvider_1 = require("./HitTest/BoxPlotSeriesHitTestProvider"); /** * Defines an Box Plot Series or Box Plot chart type in the SciChart's High Performance Real-time * {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts} * @remarks * To add a line series to a {@link SciChartSurface} you need to declare both the {@link FastBoxPlotRenderableSeries | RenderableSeries} * and a {@link BoxPlotDataSeries | DataSeries}. Simplified code sample below: * * ```ts * const sciChartSurface: SciChartSurface; * const wasmContext: TSciChart; * // Create and fill the dataseries * const dataSeries = new BoxPlotDataSeries(wasmContext); * dataSeries.append(4.5, 0, 10, 4.5, 3, 7); * dataSeries.append(5.5, 1, 9, 5.5, 4, 6); * // Create the renderableSeries * const boxPlotSeries = new FastBoxPlotRenderableSeries(wasmContext); * boxPlotSeries.dataSeries = dataSeries; * // append to the SciChartSurface * sciChartSurface.renderableSeries.add(boxPlotSeries); * ``` * * --- * 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-types/fast-box-plot-renderable-series/} */ var FastBoxPlotRenderableSeries = /** @class */ (function (_super) { __extends(FastBoxPlotRenderableSeries, _super); /** * Creates an instance of the {@link FastBoxPlotRenderableSeries} * @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 IFastBoxPlotRenderableSeriesOptions} applied when constructing the series type * * --- * 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-types/fast-box-plot-renderable-series/} */ function FastBoxPlotRenderableSeries(webAssemblyContext, options) { var _this = this; var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; _this = _super.call(this, webAssemblyContext, options) || this; _this.type = SeriesType_1.ESeriesType.BoxPlotSeries; _this.dataPointWidthModeProperty = DataPointWidthMode_1.EDataPointWidthMode.Relative; _this.capProperty = { dataPointWidth: 0.25, stroke: SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.lineSeriesColor, strokeDashArray: [], strokeThickness: 2 }; _this.whiskersProperty = { stroke: SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.lineSeriesColor, strokeDashArray: [], strokeThickness: 2 }; _this.medianLineProperty = { stroke: SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.lineSeriesColor, strokeDashArray: [], strokeThickness: 4 }; _this.dataPointWidthProperty = 0.5; _this.strokeDashArrayProperty = []; _this.fillProperty = SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.columnFillBrush; _this.dataPointWidthMode = (_a = options === null || options === void 0 ? void 0 : options.dataPointWidthMode) !== null && _a !== void 0 ? _a : _this.dataPointWidthModeProperty; if (options === null || options === void 0 ? void 0 : options.cap) { _this.capProperty.dataPointWidth = (_b = options.cap.dataPointWidth) !== null && _b !== void 0 ? _b : _this.capProperty.dataPointWidth; _this.capProperty.stroke = (_c = options.cap.stroke) !== null && _c !== void 0 ? _c : _this.capProperty.stroke; _this.capProperty.strokeDashArray = (_d = options.cap.strokeDashArray) !== null && _d !== void 0 ? _d : _this.capProperty.strokeDashArray; _this.capProperty.strokeThickness = (_e = options.cap.strokeThickness) !== null && _e !== void 0 ? _e : _this.capProperty.strokeThickness; } if (options === null || options === void 0 ? void 0 : options.whiskers) { _this.whiskersProperty.stroke = (_f = options.whiskers.stroke) !== null && _f !== void 0 ? _f : _this.whiskersProperty.stroke; _this.whiskersProperty.strokeDashArray = (_g = options.whiskers.strokeDashArray) !== null && _g !== void 0 ? _g : _this.whiskersProperty.strokeDashArray; _this.whiskersProperty.strokeThickness = (_h = options.whiskers.strokeThickness) !== null && _h !== void 0 ? _h : _this.whiskersProperty.strokeThickness; } if (options === null || options === void 0 ? void 0 : options.medianLine) { _this.medianLineProperty.stroke = (_j = options.medianLine.stroke) !== null && _j !== void 0 ? _j : _this.medianLineProperty.stroke; _this.medianLineProperty.strokeDashArray = (_k = options.medianLine.strokeDashArray) !== null && _k !== void 0 ? _k : _this.medianLineProperty.strokeDashArray; _this.medianLineProperty.strokeThickness = (_l = options.medianLine.strokeThickness) !== null && _l !== void 0 ? _l : _this.medianLineProperty.strokeThickness; } _this.strokeThickness = (_m = options === null || options === void 0 ? void 0 : options.strokeThickness) !== null && _m !== void 0 ? _m : 0; _this.dataPointWidthProperty = (_o = options === null || options === void 0 ? void 0 : options.dataPointWidth) !== null && _o !== void 0 ? _o : _this.dataPointWidthProperty; _this.strokeDashArrayProperty = (_p = options === null || options === void 0 ? void 0 : options.strokeDashArray) !== null && _p !== void 0 ? _p : _this.strokeDashArrayProperty; _this.fillProperty = (_q = options === null || options === void 0 ? void 0 : options.fill) !== null && _q !== void 0 ? _q : _this.fillProperty; _this.fillLinearGradientProperty = (_r = options === null || options === void 0 ? void 0 : options.fillLinearGradient) !== null && _r !== void 0 ? _r : _this.fillLinearGradientProperty; _this.drawingProviders = [ new BoxPlotSeriesDrawingProvider_1.BoxPlotSeriesDrawingProvider(webAssemblyContext, _this), new PointMarkerDrawingProvider_1.PointMarkerDrawingProvider(webAssemblyContext, _this) ]; // Must be called here for the series type to be available if ((_s = _this.paletteProvider) === null || _s === void 0 ? void 0 : _s.onAttached) { (_t = _this.paletteProvider) === null || _t === void 0 ? void 0 : _t.onAttached(_this); } if (options === null || options === void 0 ? void 0 : options.animation) { _this.animationQueue.push(options.animation); } return _this; } /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.applyTheme = function (themeProvider) { _super.prototype.applyTheme.call(this, themeProvider); var previousThemeProvider = this.parentSurface.previousThemeProvider; if (this.stroke === previousThemeProvider.lineSeriesColor) { this.stroke = themeProvider.lineSeriesColor; } }; Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "dataPointWidthMode", { /** * Gets or sets the mode which determines how dataPointWidth is interpreted. Available values are {@link EDataPointWidthMode}. Default Relative. */ get: function () { return this.dataPointWidthModeProperty; }, set: function (value) { this.dataPointWidthModeProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.DATA_POINT_WIDTH_MODE); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "cap", { /** * Gets or sets cap properties for {@link FastBoxPlotRenderableSeries} */ get: function () { return this.capProperty; }, set: function (value) { this.capProperty = __assign(__assign({}, this.capProperty), value); this.notifyPropertyChanged(constants_1.PROPERTY.BOX_SERIES_CAP); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "whiskers", { /** * Gets or sets whiskers properties for {@link FastBoxPlotRenderableSeries} */ get: function () { return this.whiskersProperty; }, set: function (value) { this.whiskersProperty = __assign(__assign({}, this.whiskersProperty), value); this.notifyPropertyChanged(constants_1.PROPERTY.BOX_SERIES_WHISKERS); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "medianLine", { /** * Gets or sets median line properties for {@link FastBoxPlotRenderableSeries} */ get: function () { return this.medianLineProperty; }, set: function (value) { this.medianLineProperty = __assign(__assign({}, this.medianLineProperty), value); this.notifyPropertyChanged(constants_1.PROPERTY.BOX_SERIES_MEDIAN); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "dataPointWidth", { /** * The width of the box. * By default the value is treated as relative, valid values range from 0.0 - 1.0. * To specify if the value should be treated as relative, absolute, or based on range use {@link dataPointWidthMode} */ get: function () { return this.dataPointWidthProperty; }, set: function (value) { this.dataPointWidthProperty = value; this.notifyPropertyChanged(constants_1.PROPERTY.DATA_POINT_WIDTH); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "strokeDashArray", { /** * The StrokeDashArray defines the stroke or dash pattern for the box. * Accepts an array of values, e.g. [2,2] will have a line of length 2 and a gap of length 2. */ get: function () { return this.strokeDashArrayProperty; }, set: function (strokeDashArray) { this.strokeDashArrayProperty = strokeDashArray; this.notifyPropertyChanged(constants_1.PROPERTY.STROKE_DASH_ARRAY); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "fill", { /** * The box fill as an HTML color code */ get: function () { return (0, IThemeProvider_1.stripAutoColor)(this.fillProperty); }, set: function (htmlColorCode) { this.fillProperty = htmlColorCode; this.notifyPropertyChanged(constants_1.PROPERTY.FILL); }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "fillLinearGradient", { /** * Gets or sets the fill as a gradient brush */ get: function () { return this.fillLinearGradientProperty; }, set: function (gradientBrushParams) { // We need this check, to prevent creating new Texture if we set the same value if (gradientBrushParams !== this.fillLinearGradientProperty) { this.fillLinearGradientProperty = gradientBrushParams; this.notifyPropertyChanged(constants_1.PROPERTY.FILL_LINEAR_GRADIENT); } }, enumerable: false, configurable: true }); Object.defineProperty(FastBoxPlotRenderableSeries.prototype, "paletteProvider", { /** * Gets or sets the paletteProvider of Renderable Series * @remarks paletteProvider is not supported by {@link FastBoxPlotRenderableSeries} */ get: function () { // TODO implement paletting for FastBoxPlotRenderableSeries return undefined; }, set: function (paletteProvider) { throw new Error("paletteProvider is not supported by FastBoxPlotRenderableSeries!"); }, enumerable: false, configurable: true }); /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.delete = function () { _super.prototype.delete.call(this); this.pointSeries = (0, Deleter_1.deleteSafe)(this.pointSeries); }; /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.getXRange = function () { var _a; var range = _super.prototype.getXRange.call(this); var additionalValue = (0, BaseRenderableSeries_1.getDataPointWidthAdjustment)(this.dataPointWidthMode, this.dataPointWidth, this.dataSeries.count(), range, this.xAxis.getCurrentCoordinateCalculator()); var correctedRange = new NumberRange_1.NumberRange(range.min - additionalValue, range.max + additionalValue); if (!this.strokeThickness) return correctedRange; return (0, BaseRenderableSeries_1.adjustRangeByStrokeThickness)(correctedRange, this.strokeThickness, (_a = this.parentSurface.seriesViewRect) === null || _a === void 0 ? void 0 : _a.height); }; /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.getYRange = function (xVisibleRange, isXCategoryAxis) { var _a; if (isXCategoryAxis === void 0) { isXCategoryAxis = false; } var dataSeriesValueType = this.isRunningDataAnimation ? IDataSeries_1.EDataSeriesValueType.FinalAnimationValues : IDataSeries_1.EDataSeriesValueType.Default; var range = this.dataSeries.getWindowedYRange(xVisibleRange, true, isXCategoryAxis, dataSeriesValueType, this.yRangeMode); if (this.yAxis.type === AxisType_1.EAxisType.LogarithmicAxis) { return range; } else { return (0, BaseRenderableSeries_1.adjustRangeByStrokeThickness)(range, this.cap.strokeThickness, (_a = this.parentSurface.seriesViewRect) === null || _a === void 0 ? void 0 : _a.height); } }; /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.toJSON = function (excludeData) { if (excludeData === void 0) { excludeData = false; } var json = _super.prototype.toJSON.call(this, excludeData); var options = { dataPointWidthMode: this.dataPointWidthMode, cap: this.capProperty, whiskers: this.whiskersProperty, medianLine: this.medianLineProperty, dataPointWidth: this.dataPointWidth, strokeDashArray: this.strokeDashArray, fill: this.fill, fillLinearGradient: this.fillLinearGradient }; Object.assign(json.options, options); return json; }; /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.toPointSeries = function (rp) { if (rp) { throw new Error("Box Plot Series does not support resampling!"); } else { return new BoxPlotPointSeriesWrapped_1.BoxPlotPointSeriesWrapped(this.dataSeries); } }; /** @inheritDoc */ FastBoxPlotRenderableSeries.prototype.newHitTestProvider = function () { return new BoxPlotSeriesHitTestProvider_1.BoxPlotSeriesHitTestProvider(this, this.webAssemblyContext); }; return FastBoxPlotRenderableSeries; }(BaseRenderableSeries_1.BaseRenderableSeries)); exports.FastBoxPlotRenderableSeries = FastBoxPlotRenderableSeries;