"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.XyxDataSeries = 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");
/**
 * XyxDataSeries is a DataSeries for holding X, Y, X1 data in SciChart's 2D
 * {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts}
 * @remarks
 * The {@link XyxDataSeries} 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 XyxDataSeries = /** @class */ (function (_super) {
    __extends(XyxDataSeries, _super);
    /**
     * Creates an instance of {@link XyxDataSeries}
     * @param webAssemblyContext the {@link TSciChart | SciChart WebAssembly Context} containing native methods
     * and access to our underlying WebGL2 rendering engine
     * @param options the {@link IXyxDataSeriesOptions} 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 XyxDataSeries(webAssemblyContext, options) {
        var _this = this;
        var baseOptions = __assign(__assign({}, options), { arrayCount: 2, valueNames: [ValueName_1.EValueName.Y, ValueName_1.EValueName.X1], includeInYRange: [true, false] });
        _this = _super.call(this, webAssemblyContext, baseOptions) || this;
        /** @inheritDoc */
        _this.type = IDataSeries_1.EDataSeriesType.Xyx;
        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");
            _this.appendRange(baseOptions.xValues, baseOptions.yValues, baseOptions.x1Values, 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);
            }
        }
        return _this;
    }
    Object.defineProperty(XyxDataSeries.prototype, "yValues", {
        get: function () {
            return this.getNativeYValues();
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(XyxDataSeries.prototype, "x1Values", {
        get: function () {
            return this.getNativeYValues(1);
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Appends a single X, Y, X1 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 metadata The point metadata
     */
    XyxDataSeries.prototype.append = function (x, y, x1, metadata) {
        _super.prototype.appendN.call(this, x, [y, x1], metadata);
    };
    /**
     * Appends a range of X, Y, X1 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 metadata The array of point metadata
     */
    XyxDataSeries.prototype.appendRange = function (xValues, yValues, x1Values, metadata) {
        _super.prototype.appendRangeN.call(this, xValues, [yValues, x1Values], 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 metadata The point metadata
     */
    XyxDataSeries.prototype.update = function (index, y, x1, metadata) {
        _super.prototype.updateN.call(this, index, [y, x1], metadata);
    };
    /**
     * Updates a single X, Y, X1 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 metadata The point metadata
     */
    XyxDataSeries.prototype.updateXyz = function (index, x, y, x1, metadata) {
        _super.prototype.updateXyN.call(this, index, x, [y, x1], metadata);
    };
    /**
     * Inserts a single X,Y,X1 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 metadata The point metadata
     */
    XyxDataSeries.prototype.insert = function (startIndex, x, y, x1, metadata) {
        _super.prototype.insertN.call(this, startIndex, x, [y, x1], metadata);
    };
    /**
     * Inserts a range of X,Y,X1 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 metadata The array of point metadata
     */
    XyxDataSeries.prototype.insertRange = function (startIndex, xValues, yValues, x1Values, metadata) {
        _super.prototype.insertRangeN.call(this, startIndex, xValues, [yValues, x1Values], metadata);
    };
    /** @inheritDoc */
    XyxDataSeries.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);
            // 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);
            //     }
            // } 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);
            //     }
            // }
            //  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 options = {
                xValues: xValues,
                yValues: yValues,
                x1Values: x1Values
            };
            Object.assign(json, options);
        }
        return json;
    };
    return XyxDataSeries;
}(BaseDataSeries_1.BaseDataSeries));
exports.XyxDataSeries = XyxDataSeries;
