Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
afecef1a
Commit
afecef1a
authored
Jun 02, 2021
by
Pithon Kabiro
Browse files
Edit heatmap chart drawing function / Highcharts
parent
4012e285
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/js/appChart.js
View file @
afecef1a
...
@@ -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
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment