Commit afecef1a authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Edit heatmap chart drawing function / Highcharts

parent 4012e285
...@@ -19,36 +19,37 @@ const PARAM_FILTER2 = ...@@ -19,36 +19,37 @@ const PARAM_FILTER2 =
"resultTime ge 2020-06-01T00:00:00.000Z and resultTime le 2021-01-01T00:00:00.000Z"; "resultTime ge 2020-06-01T00:00:00.000Z and resultTime le 2021-01-01T00:00:00.000Z";
/** /**
* Draw a heatmap using Highcharts library * Format the response from SensorThings API to make it suitable for heatmap
* @param {*} obsArray - Response from SensorThings API as array * @param {*} obsArray - Response from SensorThings API as array
* @returns {Array}
*/
const formatSTAResponseForHeatMap = function (obsArray) {
const dataSTAFormatted = [];
obsArray.forEach((obs) => {
// Get the date/time string; first element in input array; remove trailing "Z"
const obsDateTimeInput = obs[0].slice(0, -1);
// Get the "date" part of an observation
const obsDateInput = obs[0].slice(0, 10);
// Create Date objects
const obsDateTime = new Date(obsDateTimeInput);
const obsDate = new Date(obsDateInput);
// x-axis -> timestamp; will be the same for observations from the same date
const timestamp = Date.parse(obsDate);
// y-axis -> hourOfDay
const hourOfDay = obsDateTime.getHours();
// value -> the observation's value; second element in input array
const value = obs[1];
dataSTAFormatted.push([timestamp, hourOfDay, value]);
});
return dataSTAFormatted;
};
/**
* Draw a heatmap using Highcharts library
* @param {*} obsArray - Response from SensorThings API
* @returns {void} * @returns {void}
*/ */
const drawHeatMapHC = function (obsArray) { const drawHeatMapHC = function (obsArray) {
/**
* Format the response from SensorThings API to make it suitable for heatmap
* @returns {Array}
*/
const formatSTAResponseForHeatMap = function () {
const dataSTAFormatted = [];
obsArray.forEach((obs) => {
// Get the date/time string; first element in input array; remove trailing "Z"
const obsDateTimeInput = obs[0].slice(0, -1);
// Get the "date" part of an observation
const obsDateInput = obs[0].slice(0, 10);
// Create Date objects
const obsDateTime = new Date(obsDateTimeInput);
const obsDate = new Date(obsDateInput);
// x-axis -> timestamp; will be the same for observations from the same date
const timestamp = Date.parse(obsDate);
// y-axis -> hourOfDay
const hourOfDay = obsDateTime.getHours();
// value -> the observation's value; second element in input array
const value = obs[1];
dataSTAFormatted.push([timestamp, hourOfDay, value]);
});
return dataSTAFormatted;
};
Highcharts.chart("chart-heatmap", { Highcharts.chart("chart-heatmap", {
chart: { chart: {
type: "heatmap", type: "heatmap",
...@@ -122,7 +123,7 @@ const drawHeatMapHC = function (obsArray) { ...@@ -122,7 +123,7 @@ const drawHeatMapHC = function (obsArray) {
series: [ series: [
{ {
data: formatSTAResponseForHeatMap(), data: formatSTAResponseForHeatMap(obsArray),
boostThreshold: 100, boostThreshold: 100,
borderWidth: 0, borderWidth: 0,
nullColor: "#525252", nullColor: "#525252",
...@@ -200,6 +201,5 @@ followNextLink( ...@@ -200,6 +201,5 @@ followNextLink(
console.log(err); console.log(err);
}) })
.then((observationArr) => { .then((observationArr) => {
// drawHeatMapAC2(observationArr);
drawHeatMapHC(observationArr); drawHeatMapHC(observationArr);
}); });
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