UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

350 lines (349 loc) 19 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.BoxPlotDataSeries = void 0; var NumberRange_1 = require("../../Core/NumberRange"); var SearchMode_1 = require("../../types/SearchMode"); var ValueName_1 = require("../../types/ValueName"); var YRangeMode_1 = require("../../types/YRangeMode"); var vectorToArray_1 = require("../../utils/vectorToArray"); var BaseDataSeries_1 = require("./BaseDataSeries"); var IDataSeries_1 = require("./IDataSeries"); /** * BoxPlotDataSeries is a DataSeries for holding maximum, upperQuartile, median, lowerQuartile data in SciChart's * {@link https://www.scichart.com/javascript-chart-features | JavaScript Stock Charts} * @remarks * The BoxPlotDataSeries is primarily used with the {@link FastBoxPlotRenderableSeries | JavaScript Candlestick Chart} * * A DataSeries stores the data to render. This is independent from the {@link IRenderableSeries | RenderableSeries} * which defines how that data should be rendered. * * 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. * * --- * 📚 Docs: {@link */ var BoxPlotDataSeries = /** @class */ (function (_super) { __extends(BoxPlotDataSeries, _super); /** * Creates an instance of {@link BoxPlotDataSeries} * @param webAssemblyContext the {@link TSciChart | SciChart WebAssembly Context} containing native methods * and access to our underlying WebGL2 rendering engine * @param options the {@link IBoxPlotDataSeriesOptions} which can be passed to configure the DataSeries at construct time */ function BoxPlotDataSeries(webAssemblyContext, options) { var _this = _super.call(this, webAssemblyContext, __assign(__assign({}, options), { arrayCount: 5, valueNames: [ ValueName_1.EValueName.BoxPlotMedian, ValueName_1.EValueName.BoxPlotMax, ValueName_1.EValueName.BoxPlotUpper, ValueName_1.EValueName.BoxPlotLower, ValueName_1.EValueName.BoxPlotMinimum ], includeInYRange: [true, true, true, true, true] })) || this; /** @inheritDoc */ _this.type = IDataSeries_1.EDataSeriesType.BoxPlot; if (options === null || options === void 0 ? void 0 : options.xValues) { _this.appendRange(options.xValues, options.maximumValues, options.upperQuartileValues, options.medianValues, options.lowerQuartileValues, options.minimumValues, options.metadata); if ((options === null || options === void 0 ? void 0 : options.fifoCapacity) && (options === null || options === void 0 ? void 0 : options.fifoStartIndex)) { _this.xValues.notifyAppend(options === null || options === void 0 ? void 0 : options.fifoStartIndex); _this.medianValues.notifyAppend(options === null || options === void 0 ? void 0 : options.fifoStartIndex); _this.maximumValues.notifyAppend(options === null || options === void 0 ? void 0 : options.fifoStartIndex); _this.upperQuartileValues.notifyAppend(options === null || options === void 0 ? void 0 : options.fifoStartIndex); _this.lowerQuartileValues.notifyAppend(options === null || options === void 0 ? void 0 : options.fifoStartIndex); _this.minimumValues.notifyAppend(options === null || options === void 0 ? void 0 : options.fifoStartIndex); } } return _this; } Object.defineProperty(BoxPlotDataSeries.prototype, "yValues", { get: function () { return this.getNativeYValues(); }, enumerable: false, configurable: true }); Object.defineProperty(BoxPlotDataSeries.prototype, "medianValues", { get: function () { return this.getNativeYValues(); }, enumerable: false, configurable: true }); Object.defineProperty(BoxPlotDataSeries.prototype, "maximumValues", { get: function () { return this.getNativeMaximumValues(); }, enumerable: false, configurable: true }); Object.defineProperty(BoxPlotDataSeries.prototype, "upperQuartileValues", { get: function () { return this.getNativeUpperQuartileValues(); }, enumerable: false, configurable: true }); Object.defineProperty(BoxPlotDataSeries.prototype, "lowerQuartileValues", { get: function () { return this.getNativeLowerQuartileValues(); }, enumerable: false, configurable: true }); Object.defineProperty(BoxPlotDataSeries.prototype, "minimumValues", { get: function () { return this.getNativeMinimumValues(); }, enumerable: false, configurable: true }); /** * Gets a native / WebAssembly vector of Maximum-values in the DataSeries */ BoxPlotDataSeries.prototype.getNativeMaximumValues = function () { return this.getNativeYValues(1); }; /** * Gets a native / WebAssembly vector of Upper Quartile-values in the DataSeries */ BoxPlotDataSeries.prototype.getNativeUpperQuartileValues = function () { return this.getNativeYValues(2); }; /** * Gets a native / WebAssembly vector of Median-values in the DataSeries */ BoxPlotDataSeries.prototype.getNativeMedianValues = function () { return this.getNativeYValues(); }; /** * Gets a native / WebAssembly vector of lower Quartile-values in the DataSeries */ BoxPlotDataSeries.prototype.getNativeLowerQuartileValues = function () { return this.getNativeYValues(3); }; /** * Gets a native / WebAssembly vector of Minimum-values in the DataSeries */ BoxPlotDataSeries.prototype.getNativeMinimumValues = function () { return this.getNativeYValues(4); }; /** * Appends a single X, Maximum, UpperQuartile, Median, lowerQuartile, Minimum point to the DataSeries * @remarks * For best performance on drawing large datasets, use the {@link appendRange} method * * Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param x X-value. * @param maximum The Maximum value for this BoxPlot bar * @param upperQuartile The UpperQuartile value for this BoxPlot bar * @param median The Median value for this BoxPlot bar * @param lowerQuartile The lowerQuartile value for this BoxPlot bar * @param minimum The Minimum value for this BoxPlot bar * @param metadata The point metadata */ BoxPlotDataSeries.prototype.append = function (x, maximum, upperQuartile, median, lowerQuartile, minimum, metadata) { _super.prototype.appendN.call(this, x, [median, maximum, upperQuartile, lowerQuartile, minimum], metadata); }; /** * Appends arrays of X (Date), maximum, upperQuartile, median, lowerQuartile, minimum point to the DataSeries * @remarks * This method is considerably upperQuartileer performance than {@link append} which appends a single point * X-value is a Date, encoded as a Unix Timestamp. * * Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param xValues X-values are Dates, encoded as a Unix Timestamp. * @param maximumValues The maximum values for this BoxPlot bar * @param upperQuartileValues The upperQuartile values for this BoxPlot bar * @param medianValues The median values for this BoxPlot bar * @param lowerQuartileValues The lowerQuartile values for this BoxPlot bar * @param minimumValues The Minimum values for this BoxPlot bar * @param metadata The array of point metadata */ BoxPlotDataSeries.prototype.appendRange = function (xValues, maximumValues, upperQuartileValues, medianValues, lowerQuartileValues, minimumValues, metadata) { _super.prototype.appendRangeN.call(this, xValues, [medianValues, maximumValues, upperQuartileValues, lowerQuartileValues, minimumValues], metadata); }; /** * Updates a single maximum, upperQuartile, median, lowerQuartile, minimum value by X-index * @remarks Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param index the index to update * @param maximum The new maximum value * @param upperQuartile The new upperQuartile value * @param median The new median value * @param lowerQuartile The new lowerQuartile value * @param minimum The new minimum value * @param metadata The point metadata */ BoxPlotDataSeries.prototype.update = function (index, median, maximum, upperQuartile, lowerQuartile, minimum, metadata) { _super.prototype.updateN.call(this, index, [median, maximum, upperQuartile, lowerQuartile, minimum], metadata); }; /** * Updates a single X, maximum, upperQuartile, median, lowerQuartile, minimum value by X-index. Might also need to set isSorted = false * @remarks Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param index the index to update * @param x The new X value * @param maximum The new maximum value * @param upperQuartile The new upperQuartile value * @param median The new median value * @param lowerQuartile The new lowerQuartile value * @param minimum The new minimum value * @param metadata The point metadata */ BoxPlotDataSeries.prototype.updateXBoxPlot = function (index, x, maximum, upperQuartile, median, lowerQuartile, minimum, metadata) { _super.prototype.updateXyN.call(this, index, x, [median, maximum, upperQuartile, lowerQuartile, minimum], metadata); }; /** * Inserts a single Date, maximum, upperQuartile, median, lowerQuartile, minimum value at the X-index * @remarks Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param startIndex the index to insert at * @param x the X-value (date) encoded as a Unix Timestamp * @param maximum The maximum value * @param upperQuartile The upperQuartile value * @param median The median value * @param lowerQuartile The lowerQuartile value * @param minimum The minimum value * @param metadata The point metadata */ BoxPlotDataSeries.prototype.insert = function (startIndex, x, maximum, upperQuartile, median, lowerQuartile, minimum, metadata) { _super.prototype.insertN.call(this, startIndex, x, [median, maximum, upperQuartile, lowerQuartile, minimum], metadata); }; /** * Inserts a range of Date, maximum, upperQuartile, median, lowerQuartile, minimum value at the X-index * @remarks Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param startIndex the index to insert at * @param xValues the X-values (dates) encoded as a Unix Timestamp * @param maximumValues The maximum values * @param upperQuartileValues The upperQuartile values * @param medianValues The median values * @param lowerQuartileValues The lowerQuartile values * @param minimumValues The minimum values * @param metadata The array of point metadata */ BoxPlotDataSeries.prototype.insertRange = function (startIndex, xValues, maximumValues, upperQuartileValues, medianValues, lowerQuartileValues, minimumValues, metadata) { _super.prototype.insertRangeN.call(this, startIndex, xValues, [medianValues, maximumValues, upperQuartileValues, lowerQuartileValues, minimumValues], metadata); }; /** @inheritDoc */ BoxPlotDataSeries.prototype.getWindowedYRange = function (xRange, getPositiveRange, isXCategoryAxis, dataSeriesValueType, yRangeMode) { if (isXCategoryAxis === void 0) { isXCategoryAxis = false; } if (dataSeriesValueType === void 0) { dataSeriesValueType = IDataSeries_1.EDataSeriesValueType.Default; } if (yRangeMode === void 0) { yRangeMode = YRangeMode_1.EYRangeMode.Visible; } var _a = this.getBoxPlotValues(dataSeriesValueType), maximumValues = _a.maximumValues, minimumValues = _a.minimumValues; if (this.count() === 1) { return new NumberRange_1.NumberRange(maximumValues.get(0), minimumValues.get(0)); } var indicesRange = isXCategoryAxis ? xRange : this.getIndicesRange(xRange, false, yRangeMode === YRangeMode_1.EYRangeMode.Visible ? SearchMode_1.ESearchMode.RoundUp : SearchMode_1.ESearchMode.RoundDown, yRangeMode === YRangeMode_1.EYRangeMode.Visible ? SearchMode_1.ESearchMode.RoundDown : SearchMode_1.ESearchMode.RoundUp); var yMin = Number.MAX_VALUE; var yMax = Number.NEGATIVE_INFINITY; var iMin = Math.max(indicesRange.min, 0); var iMax = Math.min(indicesRange.max, this.count() - 1); if (iMax < iMin) { return undefined; } for (var i = iMin; i <= iMax; i++) { var maxVal = maximumValues.get(i); var minVal = minimumValues.get(i); if (minVal < yMin) { yMin = minVal; } if (maxVal > yMax) { yMax = maxVal; } } return new NumberRange_1.NumberRange(yMin, yMax); }; /** @inheritDoc */ BoxPlotDataSeries.prototype.getOptions = function (excludeData) { if (excludeData === void 0) { excludeData = false; } var json = _super.prototype.getOptions.call(this, excludeData); if (!excludeData) { // const dataSize = this.count(); // const xValues: number[] = new Array(dataSize); // const maximumValues: number[] = new Array(dataSize); // const upperQuartileValues: number[] = new Array(dataSize); // const medianValues: number[] = new Array(dataSize); // const lowerQuartileValues: number[] = new Array(dataSize); // const minimumValues: number[] = new Array(dataSize); // if (this.fifoCapacity && this.fifoSweeping) { // for (let i = 0; i < dataSize; i++) { // xValues[i] = (this.xValues as SCRTFifoVector).getRaw(i); // maximumValues[i] = (this.maximumValues as SCRTFifoVector).getRaw(i); // lowerQuartileValues[i] = (this.yValues as SCRTFifoVector).getRaw(i); // upperQuartileValues[i] = (this.upperQuartileValues as SCRTFifoVector).getRaw(i); // medianValues[i] = (this.medianValues as SCRTFifoVector).getRaw(i); // minimumValues[i] = (this.minimumValues as SCRTFifoVector).getRaw(i); // } // } else { // for (let i = 0; i < dataSize; i++) { // xValues[i] = this.xValues.get(i); // maximumValues[i] = this.maximumValues.get(i); // lowerQuartileValues[i] = this.lowerQuartileValues.get(i); // upperQuartileValues[i] = this.upperQuartileValues.get(i); // medianValues[i] = this.medianValues.get(i); // minimumValues[i] = this.minimumValues.get(i); // } // } var xValues = (0, vectorToArray_1.vectorToArray)(this.xValues, this.webAssemblyContext); var maximumValues = (0, vectorToArray_1.vectorToArray)(this.maximumValues, this.webAssemblyContext); var upperQuartileValues = (0, vectorToArray_1.vectorToArray)(this.upperQuartileValues, this.webAssemblyContext); var medianValues = (0, vectorToArray_1.vectorToArray)(this.medianValues, this.webAssemblyContext); var lowerQuartileValues = (0, vectorToArray_1.vectorToArray)(this.lowerQuartileValues, this.webAssemblyContext); var minimumValues = (0, vectorToArray_1.vectorToArray)(this.minimumValues, this.webAssemblyContext); var options = { xValues: xValues, maximumValues: maximumValues, upperQuartileValues: upperQuartileValues, medianValues: medianValues, lowerQuartileValues: lowerQuartileValues, minimumValues: minimumValues }; Object.assign(json, options); } return json; }; BoxPlotDataSeries.prototype.getBoxPlotValues = function (dataSeriesValueType) { var maximumValues; var minimumValues; switch (dataSeriesValueType) { case IDataSeries_1.EDataSeriesValueType.FinalAnimationValues: maximumValues = this.yFinalAnimationValuesArray[1]; minimumValues = this.yFinalAnimationValuesArray[4]; break; case IDataSeries_1.EDataSeriesValueType.InitialAnimationValues: maximumValues = this.yInitialAnimationValuesArray[1]; minimumValues = this.yInitialAnimationValuesArray[4]; break; default: maximumValues = this.maximumValues; minimumValues = this.minimumValues; } return { maximumValues: maximumValues, minimumValues: minimumValues }; }; return BoxPlotDataSeries; }(BaseDataSeries_1.BaseDataSeries)); exports.BoxPlotDataSeries = BoxPlotDataSeries;