UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

230 lines (229 loc) 11.4 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.XyDataSeries = void 0; var Guard_1 = require("../../Core/Guard"); var ValueName_1 = require("../../types/ValueName"); var vectorToArray_1 = require("../../utils/vectorToArray"); var BaseDataSeries_1 = require("./BaseDataSeries"); var IDataSeries_1 = require("./IDataSeries"); var XyPointSeriesResampled_1 = require("./PointSeries/XyPointSeriesResampled"); var XyPointSeriesWrapped_1 = require("./PointSeries/XyPointSeriesWrapped"); /** * @summary XyDataSeries is a DataSeries for holding X, Y data in SciChart's 2D * {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts} * @description * The XyDataSeries is primarily used with our {@link FastLineRenderableSeries | JavaScript Line Chart}, * but can also be used by the {@link XyScatterRenderableSeries | JavaScript Scatter Chart} or * {@link FastMountainRenderableSeries | JavaScript Mountain/Area Chart} and {@link FastMountainRenderableSeries | JavaScript Column Chart}. * * To instantiate an {@link XyDataSeries}, use the following code: * ```ts * const xyDataSeries = new XyDataSeries(wasmContext); * xyDataSeries.append(1, 2); // Append a single x,y point * xyDataSeries.appendRange([3, 4], [3, 4]); // Append multiple x,y points (faster) * xyDataSeries.insert(0, 9, 10); // Insert a point at index 0 * xyDataSeries.update(0, 11, 12); // Update a point at index 0 * xyDataSeries.removeAt(0); // Remove a point at index 0 * xyDataSeries.clear(); // Clear the dataseries * xyDataSeries.delete(); // Delete the dataseries and native (WebAssembly) memory * ``` * @remarks * 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 https://www.scichart.com/documentation/js/v4/2d-charts/chart-types/data-series-api/data-series-api-overview/} */ var XyDataSeries = /** @class */ (function (_super) { __extends(XyDataSeries, _super); /** * Creates an instance of {@link XyDataSeries} * @param webAssemblyContext the {@link TSciChart | SciChart WebAssembly Context} containing native methods * and access to our underlying WebGL2 WebAssembly rendering engine * @param options the {@link IXyDataSeriesOptions} which can be passed to configure the DataSeries at construct time * * --- * 📚 Docs: {@link https://www.scichart.com/documentation/js/v4/2d-charts/chart-types/data-series-api/data-series-api-overview/} */ function XyDataSeries(webAssemblyContext, options) { var _this = this; var baseOptions = __assign(__assign({}, options), { arrayCount: 1, valueNames: [ValueName_1.EValueName.Y], includeInYRange: [true] }); _this = _super.call(this, webAssemblyContext, baseOptions) || this; /** * @inheritDoc */ _this.type = IDataSeries_1.EDataSeriesType.Xy; if (baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.xValues) { Guard_1.Guard.notNull(baseOptions.yValues, "options.yValues"); _this.appendRange(baseOptions.xValues, baseOptions.yValues, baseOptions.metadata); if ((baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.fifoCapacity) && (baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.fifoStartIndex)) { _this.xValues.notifyAppend(baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.fifoStartIndex); _this.yValues.notifyAppend(baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.fifoStartIndex); } } return _this; } Object.defineProperty(XyDataSeries.prototype, "yValues", { get: function () { return this.getNativeYValues(); }, enumerable: false, configurable: true }); /** * Appends a single X, Y 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 The X-value * @param y The Y-value * @param metadata The point metadata */ XyDataSeries.prototype.append = function (x, y, metadata) { _super.prototype.appendN.call(this, x, [y], metadata, undefined); }; /** * Appends a range of X, Y points to the DataSeries * @remarks * This method is considerably higher performance than {@link append} which appends a single point * * Any changes of the DataSeries will trigger a redraw on the parent {@link SciChartSurface} * @param xValues The X-values * @param yValues The Y-values * @param metadata The array of point metadata */ XyDataSeries.prototype.appendRange = function (xValues, yValues, metadata) { _super.prototype.appendRangeN.call(this, xValues, [yValues], metadata); }; /** * Updates a single Y-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 y The new Y value * @param metadata The point metadata */ XyDataSeries.prototype.update = function (index, y, metadata) { _super.prototype.updateN.call(this, index, [y], metadata); }; /** * Updates a single X, Y-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 y The new Y value * @param metadata The point metadata */ XyDataSeries.prototype.updateXy = function (index, x, y, metadata) { _super.prototype.updateXyN.call(this, index, x, [y], metadata); }; /** * @summary Inserts a single X,Y value at the start index * @remarks * For best performance on drawing large datasets, use the {@link insertRange} method * * 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 * @param y the Y value * @param metadata The point metadata */ XyDataSeries.prototype.insert = function (startIndex, x, y, metadata) { _super.prototype.insertN.call(this, startIndex, x, [y], metadata); }; /** * @summary Inserts a range of X,Y values at the startIndex * @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 XValues * @param yValues the YValues * @param metadata The array of point metadata */ XyDataSeries.prototype.insertRange = function (startIndex, xValues, yValues, metadata) { _super.prototype.insertRangeN.call(this, startIndex, xValues, [yValues], metadata); }; XyDataSeries.prototype.toPointSeries = function (rp, pointSeries, resamplerHelper) { if (rp) { if (!pointSeries) { pointSeries = new XyPointSeriesResampled_1.XyPointSeriesResampled(this.webAssemblyContext, rp.xVisibleRange); } else { pointSeries.xRange = rp.xVisibleRange; } Guard_1.Guard.notNull(resamplerHelper, "resamplerHelper"); var result = resamplerHelper.resampleIntoPointSeries(this.webAssemblyContext, rp, this.getNativeXValues(), this.getNativeYValues(), pointSeries.intIndexes, pointSeries.indexes, pointSeries.xValues, pointSeries.yValues, false); pointSeries.fifoStartIndex = result.OutputSplitIndex; // This is now done in the resampling above // this.pointSeries.updateIndexes(); pointSeries.clearIntIndexes(); // console.log("resampling ", this.type, this.pointSeries.count); // this.pointSeries.debugOutputForUnitTests(); return pointSeries; } else { // console.log("NOT resampling ", this.type, this.dataSeries.count()); return new XyPointSeriesWrapped_1.XyPointSeriesWrapped(this); } }; XyDataSeries.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 yValues: number[] = new Array(dataSize); // if (this.fifoCapacity && this.fifoSweeping) { // for (let i = 0; i < dataSize; i++) { // xValues[i] = (this.xValues as SCRTFifoVector).getRaw(i); // yValues[i] = (this.yValues as SCRTFifoVector).getRaw(i); // } // } else { // for (let i = 0; i < dataSize; i++) { // xValues[i] = this.xValues.get(i); // yValues[i] = this.yValues.get(i); // } // } // Vroom Vroom! var xValues = (0, vectorToArray_1.vectorToArray)(this.xValues, this.webAssemblyContext); var yValues = (0, vectorToArray_1.vectorToArray)(this.yValues, this.webAssemblyContext); var options = { xValues: xValues, yValues: yValues }; Object.assign(json, options); } return json; }; return XyDataSeries; }(BaseDataSeries_1.BaseDataSeries)); exports.XyDataSeries = XyDataSeries;