diff --git a/public/js/appChart.js b/public/js/appChart.js index 5fffe09ad7a2840eb87351772b3f3f2ebe505373..d7acae3a18fd261662c3cce4bf6c46f9c1dca31f 100644 --- a/public/js/appChart.js +++ b/public/js/appChart.js @@ -179,32 +179,24 @@ const drawChartUsingSelectedOptions = async function () { selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ); - // Create copies of the arrays of building(s) + data point(s) + sampling rate - const selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr = [ - ...selectedBuildingsDataPointsSamplingRateAbbrevNestedArr, - ]; - - const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr = [ - ...selectedBuildingsDataPointsSamplingRateAbbrevNestedArr, - ]; - - // Check if we have raw observations + // Check whether we have dT (temperature difference), if so, delete these options, + // then compute abbreviations for raw observations const selectedBuildingsDataPointsSamplingRateAbbrevRawObsArr = checkIfSelectedOptionsContainTemperatureDifference( - selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) ? deleteTemperatureDifferenceOptions( - selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) - : selectedBuildingsDataPointsSamplingRateAbbrevRawObsCopyArr; + : selectedBuildingsDataPointsSamplingRateAbbrevNestedArr; // Check if we have dT (temperature difference) const selectedBuildingsDataPointsSamplingRateAbbrevTempDiffArr = checkIfSelectedOptionsContainTemperatureDifference( - selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) ? extractTemperatureDifferenceOptions( - selectedBuildingsDataPointsSamplingRateAbbrevTempDiffCopyArr + selectedBuildingsDataPointsSamplingRateAbbrevNestedArr ) : []; diff --git a/public/js/src_modules/dropDownListHelpers.mjs b/public/js/src_modules/dropDownListHelpers.mjs index 3f2a8ffca7993aca7491faf1063bf615b000b661..50ffbb8a267c94d0562e976187a1bb36fb0ef079 100644 --- a/public/js/src_modules/dropDownListHelpers.mjs +++ b/public/js/src_modules/dropDownListHelpers.mjs @@ -180,31 +180,28 @@ const getIndexesOfTemperatureDifferenceOptions = function ( const deleteTemperatureDifferenceOptions = function ( buildingDataPointSamplingRateAbbrevArr ) { + // Create a copy of the input array, will be modified in place + const buildingDataPointSamplingRateAbbrevCopyArr = [ + ...buildingDataPointSamplingRateAbbrevArr, + ]; + // Calculate the index(es) that we wish to delete const foundIndexesArr = getIndexesOfTemperatureDifferenceOptions( - buildingDataPointSamplingRateAbbrevArr + buildingDataPointSamplingRateAbbrevCopyArr ); // Delete the index(es) of `dT`, modifies the array in place // Note: The resulting array is sparse foundIndexesArr.forEach( - (foundIndex) => delete buildingDataPointSamplingRateAbbrevArr[foundIndex] + (foundIndex) => + delete buildingDataPointSamplingRateAbbrevCopyArr[foundIndex] ); - // Array to store our final result - const buildingDataPointFinalArr = []; - // Remove the empty sub array(s) that makes entire array sparse // Note: `empty` does not mean `undefined` or `null` - buildingDataPointSamplingRateAbbrevArr.forEach( - (bldgDataPntSmplingRateAbbrvArr) => { - if (typeof bldgDataPntSmplingRateAbbrvArr === "object") { - buildingDataPointFinalArr.push(bldgDataPntSmplingRateAbbrvArr); - } - } + return buildingDataPointSamplingRateAbbrevCopyArr.filter( + (bldgDataPntSamplingRate) => typeof bldgDataPntSamplingRate === "object" ); - - return buildingDataPointFinalArr; }; /**