"use strict";

import {
  formatSensorThingsApiResponseForScatterPlot,
  drawScatterPlotHighcharts,
} from "./chartScatterPlot.mjs";

/**
 * Draw a scatter plot based on the selected options from a drop-down list.
 * Currently, this chart type only supports raw observations
 *
 * @param {Array} observationsComboNestedArr An array that contains non-computed (raw) observations and computed (temperature difference, dT) observations
 * @param {Object} extractedFormattedDatastreamProperties An object that contains array(s) of formatted Datastream properties
 * @returns {undefined} undefined
 */
export const drawScatterPlotBasedOnSelectedOptions = function (
  observationsComboNestedArr,
  extractedFormattedDatastreamProperties
) {
  // Extract values for x-axis and y-axis
  // x-axis values are first element of nested observations array
  const [obsXAxisArr] = observationsComboNestedArr.slice(0, 1);
  // y-axis values are rest of elements of nested observations array
  const obsYAxisNestedArr = observationsComboNestedArr.slice(1);

  // Create formatted array(s) of observations
  const formattedObservationsScatterPlotArr = obsYAxisNestedArr.map(
    (obsYAxisArr) =>
      formatSensorThingsApiResponseForScatterPlot(obsXAxisArr, obsYAxisArr)
  );

  drawScatterPlotHighcharts(
    formattedObservationsScatterPlotArr,
    extractedFormattedDatastreamProperties
  );
};
