scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
315 lines (314 loc) • 15.6 kB
JavaScript
"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.XyxyDataSeries = void 0;
var Deleter_1 = require("../../Core/Deleter");
var Guard_1 = require("../../Core/Guard");
var NumberRange_1 = require("../../Core/NumberRange");
var SearchMode_1 = require("../../types/SearchMode");
var ValueName_1 = require("../../types/ValueName");
var isRealNumber_1 = require("../../utils/isRealNumber");
var vectorToArray_1 = require("../../utils/vectorToArray");
var BaseDataSeries_1 = require("./BaseDataSeries");
var IDataSeries_1 = require("./IDataSeries");
/**
* XyxyDataSeries is a DataSeries for holding X, Y, X1, Y1 data in SciChart's 2D
* {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts}
* @remarks
* The {@link XyxyDataSeries} is primarily used with our {@link FastBoxRenderableSeries | JavaScript Box Chart},
* which draws arbitrary rectangles
*
* 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 XyxyDataSeries = /** @class */ (function (_super) {
__extends(XyxyDataSeries, _super);
/**
* Creates an instance of {@link XyxyDataSeries}
* @param webAssemblyContext the {@link TSciChart | SciChart WebAssembly Context} containing native methods
* and access to our underlying WebGL2 rendering engine
* @param options the {@link IXyzDataSeriesOptions} 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 XyxyDataSeries(webAssemblyContext, options) {
var _this = this;
var baseOptions = __assign(__assign({}, options), { arrayCount: 3, valueNames: [ValueName_1.EValueName.Y, ValueName_1.EValueName.X1, ValueName_1.EValueName.Y1], includeInYRange: [true, false, true] });
_this = _super.call(this, webAssemblyContext, baseOptions) || this;
/** @inheritDoc */
_this.type = IDataSeries_1.EDataSeriesType.Xyxy;
if (baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.xValues) {
Guard_1.Guard.notNull(baseOptions.yValues, "baseOptions.yValues");
Guard_1.Guard.notNull(baseOptions.x1Values, "baseOptions.x1Values");
Guard_1.Guard.notNull(baseOptions.y1Values, "baseOptions.y1Values");
_this.appendRange(baseOptions.xValues, baseOptions.yValues, baseOptions.x1Values, baseOptions.y1Values, 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);
_this.x1Values.notifyAppend(baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.fifoStartIndex);
_this.y1Values.notifyAppend(baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions.fifoStartIndex);
}
}
return _this;
}
Object.defineProperty(XyxyDataSeries.prototype, "yValues", {
get: function () {
return this.getNativeYValues();
},
enumerable: false,
configurable: true
});
Object.defineProperty(XyxyDataSeries.prototype, "x1Values", {
get: function () {
return this.getNativeYValues(1);
},
enumerable: false,
configurable: true
});
Object.defineProperty(XyxyDataSeries.prototype, "y1Values", {
get: function () {
return this.getNativeYValues(2);
},
enumerable: false,
configurable: true
});
/**
* Appends a single X, Y, X1, Y1 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 x1 The X1-value
* @param y1 The Y1-value
* @param metadata The point metadata
*/
XyxyDataSeries.prototype.append = function (x, y, x1, y1, metadata) {
_super.prototype.appendN.call(this, x, [y, x1, y1], metadata);
};
/**
* Appends a range of X, Y, X1, Y1 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 x1Values The X1-values
* @param y1Values The Y1-values
* @param metadata The array of point metadata
*/
XyxyDataSeries.prototype.appendRange = function (xValues, yValues, x1Values, y1Values, metadata) {
_super.prototype.appendRangeN.call(this, xValues, [yValues, x1Values, y1Values], metadata);
};
/**
* Updates a single Y, X1, Y1 value set 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 x1 The new X1-value
* @param y1 The new Y1-value
* @param metadata The point metadata
*/
XyxyDataSeries.prototype.update = function (index, y, x1, y1, metadata) {
_super.prototype.updateN.call(this, index, [y, x1, y1], metadata);
};
/**
* Updates a single X, Y, X1, Y1 value set 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 x1 The new X1-value
* @param y1 The new Y1-value
* @param metadata The point metadata
*/
XyxyDataSeries.prototype.updateXyz = function (index, x, y, x1, y1, metadata) {
_super.prototype.updateXyN.call(this, index, x, [y, x1, y1], metadata);
};
/**
* Inserts a single X,Y,X1,Y1 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 Xvalue
* @param y the YValue
* @param x1 The X1-value
* @param y1 The Y1-value
* @param metadata The point metadata
*/
XyxyDataSeries.prototype.insert = function (startIndex, x, y, x1, y1, metadata) {
_super.prototype.insertN.call(this, startIndex, x, [y, x1, y1], metadata);
};
/**
* Inserts a range of X,Y, X1, Y1 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 x1Values The X1-values
* @param y1Values The Y1-values
* @param metadata The array of point metadata
*/
XyxyDataSeries.prototype.insertRange = function (startIndex, xValues, yValues, x1Values, y1Values, metadata) {
_super.prototype.insertRangeN.call(this, startIndex, xValues, [yValues, x1Values, y1Values], metadata);
};
/** @inheritDoc */
XyxyDataSeries.prototype.getIndicesRange = function (xRange, isCategoryData, downSearchMode, upSearchMode) {
if (isCategoryData === void 0) { isCategoryData = false; }
if (downSearchMode === void 0) { downSearchMode = SearchMode_1.ESearchMode.RoundDown; }
if (upSearchMode === void 0) { upSearchMode = SearchMode_1.ESearchMode.RoundUp; }
var vector1 = isCategoryData ? this.getNativeIndexes() : this.xValues;
var first = (0, BaseDataSeries_1.getIndicesRange)(this.webAssemblyContext, vector1, xRange, this.dataDistributionCalculator.isSortedAscending, downSearchMode, upSearchMode);
var vector2 = isCategoryData ? this.getNativeIndexes() : this.x1Values;
var second = (0, BaseDataSeries_1.getIndicesRange)(this.webAssemblyContext, vector2, xRange, this.dataDistributionCalculator.isSortedAscending, downSearchMode, upSearchMode);
return first.union(second);
};
/** @inheritDoc */
XyxyDataSeries.prototype.getXRange = function (dataSeriesValueType) {
var xValues = this.getXValues(dataSeriesValueType);
var x1Values = this.getXyxyValues(dataSeriesValueType).x1Values;
var temp;
if (this.count() === 1) {
var xValue = xValues.get(0);
var x1Value = x1Values.get(0);
var min = Math.min(xValue, x1Value);
var max = Math.max(xValue, x1Value);
if (min === max) {
min -= 1;
max += 1;
}
return new NumberRange_1.NumberRange(min, max);
}
else if (this.count() > 1) {
var min = void 0;
var max = void 0;
var minMax = void 0;
var minMax1 = void 0;
try {
// containsNaN is always false for xValues
minMax = this.webAssemblyContext.NumberUtil.MinMax(xValues, false);
minMax1 = this.webAssemblyContext.NumberUtil.MinMax(x1Values, false);
min = Math.min(minMax.minD, minMax1.minD);
max = Math.max(minMax.maxD, minMax1.maxD);
if (!(0, isRealNumber_1.isRealNumber)(min) || !(0, isRealNumber_1.isRealNumber)(max)) {
return new NumberRange_1.NumberRange(0, 0);
}
}
finally {
(0, Deleter_1.deleteSafe)(minMax);
(0, Deleter_1.deleteSafe)(minMax1);
}
if (min === max) {
return new NumberRange_1.NumberRange(min - 1, max + 1);
}
else if (min > max) {
temp = min;
min = max;
max = temp;
}
return new NumberRange_1.NumberRange(min, max);
}
return new NumberRange_1.NumberRange(0, 0);
};
/** @inheritDoc */
XyxyDataSeries.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);
// const x1Values: number[] = new Array(dataSize);
// const y1Values: 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);
// x1Values[i] = (this.x1Values as SCRTFifoVector).getRaw(i);
// y1Values[i] = (this.y1Values as SCRTFifoVector).getRaw(i);
// }
// } else {
// for (let i = 0; i < dataSize; i++) {
// xValues[i] = this.xValues.get(i);
// yValues[i] = this.yValues.get(i);
// x1Values[i] = this.x1Values.get(i);
// y1Values[i] = this.y1Values.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 x1Values = (0, vectorToArray_1.vectorToArray)(this.x1Values, this.webAssemblyContext);
var y1Values = (0, vectorToArray_1.vectorToArray)(this.y1Values, this.webAssemblyContext);
var options = {
xValues: xValues,
yValues: yValues,
x1Values: x1Values,
y1Values: y1Values
};
Object.assign(json, options);
}
return json;
};
XyxyDataSeries.prototype.getXyxyValues = function (dataSeriesValueType) {
var yValues;
var x1Values;
var y1Values;
switch (dataSeriesValueType) {
case IDataSeries_1.EDataSeriesValueType.FinalAnimationValues:
yValues = this.yFinalAnimationValuesArray[0];
x1Values = this.yFinalAnimationValuesArray[1];
y1Values = this.yFinalAnimationValuesArray[2];
break;
case IDataSeries_1.EDataSeriesValueType.InitialAnimationValues:
yValues = this.yInitialAnimationValuesArray[0];
x1Values = this.yInitialAnimationValuesArray[1];
y1Values = this.yInitialAnimationValuesArray[2];
break;
default:
yValues = this.yValues;
x1Values = this.x1Values;
y1Values = this.y1Values;
}
return { yValues: yValues, x1Values: x1Values, y1Values: y1Values };
};
return XyxyDataSeries;
}(BaseDataSeries_1.BaseDataSeries));
exports.XyxyDataSeries = XyxyDataSeries;