Commit 1501726b authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Move function to a different module file

Function that formats observations for line chart or column chart
parent 48389746
...@@ -17,10 +17,9 @@ import { ...@@ -17,10 +17,9 @@ import {
extractPropertiesFromFormattedDatastreamMetadata, extractPropertiesFromFormattedDatastreamMetadata,
} from "./src_modules/fetchedDataProcessing.mjs"; } from "./src_modules/fetchedDataProcessing.mjs";
import { import { formatSensorThingsApiResponseForLineOrColumnChart } from "./src_modules/chartHelpers.mjs";
formatSensorThingsApiResponseForLineOrColumnChart,
drawLineChartHighcharts, import { drawLineChartHighcharts } from "./src_modules/chartLine.mjs";
} from "./src_modules/chartLine.mjs";
import { drawColumnChartHighcharts } from "./src_modules/chartColumn.mjs"; import { drawColumnChartHighcharts } from "./src_modules/chartColumn.mjs";
......
...@@ -177,6 +177,21 @@ const checkForAndDeleteUniqueObservationsFromLargerArray = function ( ...@@ -177,6 +177,21 @@ const checkForAndDeleteUniqueObservationsFromLargerArray = function (
} }
}; };
/**
* Format the response from SensorThings API to make it suitable for use in a line chart or column chart
* @param {Array} obsArray Array of observations (timestamp + value) that is response from SensorThings API
* @returns {Array} Array of formatted observations suitable for use in a line chart
*/
const formatSensorThingsApiResponseForLineOrColumnChart = function (obsArray) {
if (!obsArray) return;
return obsArray.map((result) => {
const timestampObs = new Date(result[0].slice(0, -1)).getTime(); // slice() removes trailing "Z" character in timestamp
const valueObs = result[1];
return [timestampObs, valueObs];
});
};
/** /**
* Convert a hexadecimal color code obtained from the Highcharts object (`Highcharts.getOptions().colors`) to its equivalent RGB color code * Convert a hexadecimal color code obtained from the Highcharts object (`Highcharts.getOptions().colors`) to its equivalent RGB color code
* @param {String} hexCode Input hex color code * @param {String} hexCode Input hex color code
...@@ -406,6 +421,7 @@ const removeTransparencyFromColor = function (rgbaColor) { ...@@ -406,6 +421,7 @@ const removeTransparencyFromColor = function (rgbaColor) {
export { export {
chartExportOptions, chartExportOptions,
checkForAndDeleteUniqueObservationsFromLargerArray, checkForAndDeleteUniqueObservationsFromLargerArray,
formatSensorThingsApiResponseForLineOrColumnChart,
createCombinedTextDelimitedByAmpersand, createCombinedTextDelimitedByAmpersand,
createCombinedTextDelimitedByComma, createCombinedTextDelimitedByComma,
extractSamplingRateFromDatastreamName, extractSamplingRateFromDatastreamName,
......
...@@ -7,21 +7,6 @@ import { ...@@ -7,21 +7,6 @@ import {
createTooltipDateString, createTooltipDateString,
} from "./chartHelpers.mjs"; } from "./chartHelpers.mjs";
/**
* Format the response from SensorThings API to make it suitable for use in a line chart or column chart
* @param {Array} obsArray Array of observations (timestamp + value) that is response from SensorThings API
* @returns {Array} Array of formatted observations suitable for use in a line chart
*/
const formatSensorThingsApiResponseForLineOrColumnChart = function (obsArray) {
if (!obsArray) return;
return obsArray.map((result) => {
const timestampObs = new Date(result[0].slice(0, -1)).getTime(); // slice() removes trailing "Z" character in timestamp
const valueObs = result[1];
return [timestampObs, valueObs];
});
};
/** /**
* Creates an options object for each series drawn in the line chart * Creates an options object for each series drawn in the line chart
* @param {Array} formattedObsArraysForLineChart An array of formatted observation array(s) from one or more datastreams * @param {Array} formattedObsArraysForLineChart An array of formatted observation array(s) from one or more datastreams
...@@ -162,7 +147,4 @@ const drawLineChartHighcharts = function ( ...@@ -162,7 +147,4 @@ const drawLineChartHighcharts = function (
}); });
}; };
export { export { drawLineChartHighcharts };
formatSensorThingsApiResponseForLineOrColumnChart,
drawLineChartHighcharts,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment