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
559e7982
Commit
559e7982
authored
Oct 11, 2021
by
Pithon Kabiro
Browse files
Rewrite multiple 'if' statements using 'switch'
parent
04eb3a11
Changes
10
Hide whitespace changes
Inline
Side-by-side
public/js/appChart.js
View file @
559e7982
...
@@ -24,6 +24,8 @@ import { drawColumnChartHighcharts } from "./src_modules/chartColumn.mjs";
...
@@ -24,6 +24,8 @@ import { drawColumnChartHighcharts } from "./src_modules/chartColumn.mjs";
import
{
import
{
showLoadingSpinner
,
showLoadingSpinner
,
hideLoadingSpinner
,
hideLoadingSpinner
,
disableDrawChartButton
,
enableDrawChartButton
,
}
from
"
./src_modules/loadingIndicator.mjs
"
;
}
from
"
./src_modules/loadingIndicator.mjs
"
;
import
{
vanillaSelectBox
}
from
"
./thirdparty/vanillaSelectBox.mjs
"
;
import
{
vanillaSelectBox
}
from
"
./thirdparty/vanillaSelectBox.mjs
"
;
...
@@ -138,7 +140,7 @@ const drawChartUsingSelectedOptions = async function () {
...
@@ -138,7 +140,7 @@ const drawChartUsingSelectedOptions = async function () {
const
selectedOptionsAllDropDownLists
=
const
selectedOptionsAllDropDownLists
=
getSelectedOptionsFromAllDropDownLists
();
getSelectedOptionsFromAllDropDownLists
();
// Note: The aggregation type + duration
and chart type
are the first and
// Note: The
chart type amd
aggregation type + duration are the first and
// third elements respectively, we have ignored the second and fourth elements
// third elements respectively, we have ignored the second and fourth elements
const
[
selectedChartTypeArr
,
,
selectedAggregationTypeDurationArr
]
=
const
[
selectedChartTypeArr
,
,
selectedAggregationTypeDurationArr
]
=
selectedOptionsAllDropDownLists
;
selectedOptionsAllDropDownLists
;
...
@@ -178,71 +180,74 @@ const drawChartUsingSelectedOptions = async function () {
...
@@ -178,71 +180,74 @@ const drawChartUsingSelectedOptions = async function () {
);
);
// Create copies of the arrays of building(s) + data point(s) + sampling rate
// Create copies of the arrays of building(s) + data point(s) + sampling rate
const
selectedBuildingsDataPointsSamplingRateAbbrev
NonComputed
CopyArr
=
[
const
selectedBuildingsDataPointsSamplingRateAbbrev
RawObs
CopyArr
=
[
...
selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
,
...
selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
,
];
];
const
selectedBuildingsDataPointsSamplingRateAbbrev
Computed
CopyArr
=
[
const
selectedBuildingsDataPointsSamplingRateAbbrev
TempDiff
CopyArr
=
[
...
selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
,
...
selectedBuildingsDataPointsSamplingRateAbbrevNestedArr
,
];
];
// Check if we have
non-computed
// Check if we have
raw observations
const
selectedBuildingsDataPointsSamplingRateAbbrev
NonComputed
Arr
=
const
selectedBuildingsDataPointsSamplingRateAbbrev
RawObs
Arr
=
checkIfSelectedOptionsContainTemperatureDifference
(
checkIfSelectedOptionsContainTemperatureDifference
(
selectedBuildingsDataPointsSamplingRateAbbrev
NonComputed
CopyArr
selectedBuildingsDataPointsSamplingRateAbbrev
RawObs
CopyArr
)
)
?
deleteTemperatureDifferenceOptions
(
?
deleteTemperatureDifferenceOptions
(
selectedBuildingsDataPointsSamplingRateAbbrev
NonComputed
CopyArr
selectedBuildingsDataPointsSamplingRateAbbrev
RawObs
CopyArr
)
)
:
selectedBuildingsDataPointsSamplingRateAbbrev
NonComputed
CopyArr
;
:
selectedBuildingsDataPointsSamplingRateAbbrev
RawObs
CopyArr
;
// Check if we have
computed / dT
// Check if we have
dT (temperature difference)
const
selectedBuildingsDataPointsSamplingRateAbbrev
Computed
Arr
=
const
selectedBuildingsDataPointsSamplingRateAbbrev
TempDiff
Arr
=
checkIfSelectedOptionsContainTemperatureDifference
(
checkIfSelectedOptionsContainTemperatureDifference
(
selectedBuildingsDataPointsSamplingRateAbbrev
Computed
CopyArr
selectedBuildingsDataPointsSamplingRateAbbrev
TempDiff
CopyArr
)
)
?
extractTemperatureDifferenceOptions
(
?
extractTemperatureDifferenceOptions
(
selectedBuildingsDataPointsSamplingRateAbbrev
Computed
CopyArr
selectedBuildingsDataPointsSamplingRateAbbrev
TempDiff
CopyArr
)
)
:
[];
:
[];
// Display the loading indicator
// Display the loading indicator
showLoadingSpinner
();
showLoadingSpinner
();
// Fetch the observations + metadata / non-computed
// Disable the 'draw chart' button
const
observationsPlusMetadataNonComputedArr
=
disableDrawChartButton
();
selectedBuildingsDataPointsSamplingRateAbbrevNonComputedArr
.
length
===
0
// Fetch the observations + metadata / raw observations
const
observationsRawPlusMetadataArr
=
selectedBuildingsDataPointsSamplingRateAbbrevRawObsArr
.
length
===
0
?
[[],
[]]
?
[[],
[]]
:
await
getMetadataPlusObservationsFromSingleOrMultipleDatastreams
(
:
await
getMetadataPlusObservationsFromSingleOrMultipleDatastreams
(
BASE_URL
,
BASE_URL
,
QUERY_PARAMS_COMBINED
,
QUERY_PARAMS_COMBINED
,
selectedBuildingsDataPointsSamplingRateAbbrev
NonComputed
Arr
selectedBuildingsDataPointsSamplingRateAbbrev
RawObs
Arr
);
);
// Fetch the observations + metadata /
computed
(dT)
// Fetch the observations + metadata /
temperature difference
(dT)
const
observationsPlusMetadata
Computed
Arr
=
const
observations
TempDiff
PlusMetadataArr
=
selectedBuildingsDataPointsSamplingRateAbbrev
Computed
Arr
.
length
===
0
selectedBuildingsDataPointsSamplingRateAbbrev
TempDiff
Arr
.
length
===
0
?
[[],
[]]
?
[[],
[]]
:
await
calculateVorlaufMinusRuecklaufTemperature
(
:
await
calculateVorlaufMinusRuecklaufTemperature
(
BASE_URL
,
BASE_URL
,
QUERY_PARAMS_COMBINED
,
QUERY_PARAMS_COMBINED
,
extractBuildingPlusSamplingRate
(
extractBuildingPlusSamplingRate
(
selectedBuildingsDataPointsSamplingRateAbbrev
Computed
Arr
selectedBuildingsDataPointsSamplingRateAbbrev
TempDiff
Arr
)
)
);
);
// Extract the combined arrays for observations and metadata /
non-computed
// Extract the combined arrays for observations and metadata /
raw observations
const
[
observationsNes
tedNonCompu
tedArr
,
metadata
NestedNonCompu
tedArr
]
=
const
[
observations
Raw
NestedArr
,
metadata
TempDiffNes
tedArr
]
=
observationsPlusMetadata
NonComputed
Arr
;
observations
Raw
PlusMetadataArr
;
// Extract the combined arrays for observations and metadata /
computed
(dT)
// Extract the combined arrays for observations and metadata /
temperature difference
(dT)
const
[
observationsNestedComputedArr
,
metadataNestedComputedArr
]
=
const
[
observationsNestedComputedArr
,
metadataNestedComputedArr
]
=
observationsPlusMetadata
Computed
Arr
;
observations
TempDiff
PlusMetadataArr
;
// Create a combined array of observations and metadata
// Create a combined array of observations and metadata
const
observationsPlusMetadataCombined
=
[
const
observationsPlusMetadataCombined
=
[
[...
observationsNes
tedNonCompu
tedArr
,
...
observationsNestedComputedArr
],
[...
observations
Raw
NestedArr
,
...
observationsNestedComputedArr
],
[...
metadata
NestedNonCompu
tedArr
,
...
metadataNestedComputedArr
],
[...
metadata
TempDiffNes
tedArr
,
...
metadataNestedComputedArr
],
];
];
const
[
observationsComboNestedArr
,
metadataComboNestedArr
]
=
const
[
observationsComboNestedArr
,
metadataComboNestedArr
]
=
...
@@ -253,8 +258,8 @@ const drawChartUsingSelectedOptions = async function () {
...
@@ -253,8 +258,8 @@ const drawChartUsingSelectedOptions = async function () {
(
metadataObj
)
=>
formatDatastreamMetadataForChart
(
metadataObj
)
(
metadataObj
)
=>
formatDatastreamMetadataForChart
(
metadataObj
)
);
);
// Extract the formatted metadata properties - used by ALL chart types
// Extract the formatted metadata properties
for the raw observations
- used by ALL chart types
const
e
xtractedFormattedDatastreamProperties
=
const
rawObservationsE
xtractedFormattedDatastreamProperties
=
extractPropertiesFromFormattedDatastreamMetadata
(
extractPropertiesFromFormattedDatastreamMetadata
(
formattedMetadataNestedArr
,
formattedMetadataNestedArr
,
false
false
...
@@ -272,111 +277,125 @@ const drawChartUsingSelectedOptions = async function () {
...
@@ -272,111 +277,125 @@ const drawChartUsingSelectedOptions = async function () {
const
aggregationStartDate
=
"
2020-01-01
"
;
const
aggregationStartDate
=
"
2020-01-01
"
;
const
aggregationEndDate
=
"
2020-12-31
"
;
const
aggregationEndDate
=
"
2020-12-31
"
;
// Extract observations within the user-specified start and end date - used by MULTIPLE chart types
// Create final array of observations- used by MULTIPLE chart types
const
observationsAggregationNestedArr
=
observationsComboNestedArr
.
map
(
// If we are performing aggregation, it was envisioned that the user would
(
obsArr
)
=>
// select observations that fall within a start and end date
extractObservationsWithinDatesInterval
(
const
observationsComboNestedFinalArr
=
obsArr
,
selectedAggregationType
===
"
None (raw data)
"
"
60min
"
,
?
observationsComboNestedArr
aggregationStartDate
,
:
observationsComboNestedArr
.
map
((
observationsArr
)
=>
aggregationEndDate
extractObservationsWithinDatesInterval
(
)
observationsArr
,
);
selectedSamplingRateAbbrev
,
aggregationStartDate
,
aggregationEndDate
)
);
// Unique calendar dates - used by MULTIPLE chart types
// Unique calendar dates - used by MULTIPLE chart types
const
uniqueCalendarDatesNestedArr
=
observations
Aggregation
NestedArr
.
map
(
const
uniqueCalendarDatesNestedArr
=
observations
Combo
Nested
Final
Arr
.
map
(
(
observationsArr
)
=>
(
observationsArr
)
=>
extractUniqueCalendarDatesFromTimestamp
(
observationsArr
)
extractUniqueCalendarDatesFromTimestamp
(
observationsArr
)
);
);
for
(
const
selectedChartType
of
selectedChartTypeArr
)
{
for
(
const
selectedChartType
of
selectedChartTypeArr
)
{
if
(
selectedChartType
===
"
Heatmap
"
)
{
switch
(
selectedChartType
)
{
// We are interested in raw observations
// We are interested in raw observations ONLY
if
(
case
"
Heatmap
"
:
selectedAggregationOptionsAreValid
&&
if
(
selectedBuildingDataPointsOptionsAreValid
selectedAggregationOptionsAreValid
&&
)
{
selectedBuildingDataPointsOptionsAreValid
drawHeatmapBasedOnSelectedOptions
(
)
{
observationsComboNestedArr
,
drawHeatmapBasedOnSelectedOptions
(
extractedFormattedDatastreamProperties
observationsComboNestedFinalArr
,
);
rawObservationsExtractedFormattedDatastreamProperties
}
}
if
(
selectedChartType
===
"
Scatter Plot
"
)
{
// We are interested in raw observations
if
(
selectedAggregationOptionsAreValid
&&
selectedBuildingDataPointsOptionsAreValid
)
{
drawScatterPlotFromChartSelection
(
observationsComboNestedArr
,
extractedFormattedDatastreamProperties
);
}
}
if
(
selectedChartType
===
"
Line
"
)
{
// We are interested in raw observations or aggregated observations
// Raw observations
if
(
selectedAggregationType
===
"
None (raw data)
"
)
{
// Create formatted array(s) for observations
const
formattedRawObservationsLineChartNestedArr
=
observationsComboNestedArr
.
map
((
observationsArr
)
=>
formatSensorThingsApiResponseForLineOrColumnChart
(
observationsArr
)
);
);
}
drawLineChartHighcharts
(
break
;
formattedRawObservationsLineChartNestedArr
,
extractedFormattedDatastreamProperties
// We are interested in raw observations ONLY
);
case
"
Scatter Plot
"
:
}
if
(
// Aggregated observations
selectedAggregationOptionsAreValid
&&
else
{
selectedBuildingDataPointsOptionsAreValid
drawLineChartBasedOnSelectedAggregationOptions
(
)
{
selectedAggregationType
,
drawScatterPlotFromChartSelection
(
selectedAggregationDuration
,
observationsComboNestedFinalArr
,
observationsAggregationNestedArr
,
rawObservationsExtractedFormattedDatastreamProperties
selectedSamplingRateAbbrev
,
);
uniqueCalendarDatesNestedArr
,
}
formattedMetadataNestedArr
break
;
);
}
// We are interested in BOTH raw observations and aggregated observations
}
case
"
Line
"
:
// Raw observations
if
(
selectedChartType
===
"
Column
"
)
{
if
(
selectedAggregationType
===
"
None (raw data)
"
)
{
// We are interested in raw observations or aggregated observations
// Create formatted array(s) for observations
const
formattedRawObservationsLineChartNestedArr
=
// Raw observations
observationsComboNestedFinalArr
.
map
((
observationsArr
)
=>
if
(
selectedAggregationType
===
"
None (raw data)
"
)
{
formatSensorThingsApiResponseForLineOrColumnChart
(
// Create formatted array(s) for observations
observationsArr
const
formattedRawObservationsColumnChartNestedArr
=
)
observationsComboNestedArr
.
map
((
observationsArr
)
=>
);
formatSensorThingsApiResponseForLineOrColumnChart
(
observationsArr
)
drawLineChartHighcharts
(
formattedRawObservationsLineChartNestedArr
,
rawObservationsExtractedFormattedDatastreamProperties
);
);
}
// Aggregated observations
else
{
drawLineChartBasedOnSelectedAggregationOptions
(
selectedAggregationType
,
selectedAggregationDuration
,
observationsComboNestedFinalArr
,
selectedSamplingRateAbbrev
,
uniqueCalendarDatesNestedArr
,
formattedMetadataNestedArr
);
}
break
;
// We are interested in BOTH raw observations and aggregated observations
case
"
Column
"
:
// Raw observations
if
(
selectedAggregationType
===
"
None (raw data)
"
)
{
// Create formatted array(s) for observations
const
formattedRawObservationsColumnChartNestedArr
=
observationsComboNestedFinalArr
.
map
((
observationsArr
)
=>
formatSensorThingsApiResponseForLineOrColumnChart
(
observationsArr
)
);
drawColumnChartHighcharts
(
formattedRawObservationsColumnChartNestedArr
,
rawObservationsExtractedFormattedDatastreamProperties
);
}
// Aggregated observations
else
{
drawColumnChartBasedOnSelectedAggregationOptions
(
selectedAggregationType
,
selectedAggregationDuration
,
observationsComboNestedFinalArr
,
selectedSamplingRateAbbrev
,
uniqueCalendarDatesNestedArr
,
formattedMetadataNestedArr
);
}
break
;
drawColumnChartHighcharts
(
default
:
formattedRawObservationsColumnChartNestedArr
,
throw
new
Error
(
"
None of the chart type options were selected
"
);
extractedFormattedDatastreamProperties
);
}
// Aggregated observations
else
{
drawColumnChartBasedOnSelectedAggregationOptions
(
selectedAggregationType
,
selectedAggregationDuration
,
observationsAggregationNestedArr
,
selectedSamplingRateAbbrev
,
uniqueCalendarDatesNestedArr
,
formattedMetadataNestedArr
);
}
}
}
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
}
finally
{
}
finally
{
// Enable the 'draw chart' button
enableDrawChartButton
();
// Hide the loading indicator
// Hide the loading indicator
hideLoadingSpinner
();
hideLoadingSpinner
();
}
}
...
...
public/js/src_modules/aggregate.mjs
View file @
559e7982
...
@@ -5,6 +5,16 @@ import {
...
@@ -5,6 +5,16 @@ import {
extractObservationValuesWithinMonthInterval
,
extractObservationValuesWithinMonthInterval
,
}
from
"
./aggregateHelpers.mjs
"
;
}
from
"
./aggregateHelpers.mjs
"
;
/**
* Remove `null` observation values from an array of observation values
*
* @param {Array} obsValuesArr An array of observation values
* @returns {Array} An array with `null` observation values removed
*/
const
filterOutNullObservationValues
=
function
(
obsValuesArr
)
{
return
obsValuesArr
.
filter
((
obs
)
=>
obs
!==
null
);
};
/**
/**
* Calculate the minimum observation values that fall within a time interval delimited by a start date and end date
* Calculate the minimum observation values that fall within a time interval delimited by a start date and end date
* @param {Array} obsValuesForDaysIntervalArr An array of observation values that fall within our time interval
* @param {Array} obsValuesForDaysIntervalArr An array of observation values that fall within our time interval
...
@@ -13,7 +23,10 @@ import {
...
@@ -13,7 +23,10 @@ import {
const
calculateMinimumObservationValuesWithinDatesInterval
=
function
(
const
calculateMinimumObservationValuesWithinDatesInterval
=
function
(
obsValuesForDaysIntervalArr
obsValuesForDaysIntervalArr
)
{
)
{
return
Math
.
min
(...
obsValuesForDaysIntervalArr
);
// If the observation value is `null`, skip the calculation
return
obsValuesForDaysIntervalArr
.
reduce
((
previousValue
,
obsValue
)
=>
obsValue
===
null
?
null
:
Math
.
min
(
previousValue
,
obsValue
)
);
};
};
/**
/**
...
@@ -24,7 +37,10 @@ const calculateMinimumObservationValuesWithinDatesInterval = function (
...
@@ -24,7 +37,10 @@ const calculateMinimumObservationValuesWithinDatesInterval = function (
const
calculateMaximumObservationValuesWithinDatesInterval
=
function
(
const
calculateMaximumObservationValuesWithinDatesInterval
=
function
(
obsValuesForDaysIntervalArr
obsValuesForDaysIntervalArr
)
{
)
{
return
Math
.
max
(...
obsValuesForDaysIntervalArr
);
// If the observation value is `null`, skip the calculation
return
obsValuesForDaysIntervalArr
.
reduce
((
previousValue
,
obsValue
)
=>
obsValue
===
null
?
null
:
Math
.
max
(
previousValue
,
obsValue
)
);
};
};
/**
/**
...
@@ -35,8 +51,10 @@ const calculateMaximumObservationValuesWithinDatesInterval = function (
...
@@ -35,8 +51,10 @@ const calculateMaximumObservationValuesWithinDatesInterval = function (
const
calculateSumOfObservationValuesWithinDatesInterval
=
function
(
const
calculateSumOfObservationValuesWithinDatesInterval
=
function
(
obsValuesForDaysIntervalArr
obsValuesForDaysIntervalArr
)
{
)
{
return
obsValuesForDaysIntervalArr
.
reduce
(
// Remove the `null` observation values before calculating the sum
(
accumulator
,
obsValue
)
=>
accumulator
+
obsValue
return
filterOutNullObservationValues
(
obsValuesForDaysIntervalArr
).
reduce
(
(
previousValue
,
obsValue
)
=>
previousValue
+
obsValue
,
0
);
);
};
};
...
@@ -48,10 +66,11 @@ const calculateSumOfObservationValuesWithinDatesInterval = function (
...
@@ -48,10 +66,11 @@ const calculateSumOfObservationValuesWithinDatesInterval = function (
const
calculateAverageOfObservationValuesWithinDatesInterval
=
function
(
const
calculateAverageOfObservationValuesWithinDatesInterval
=
function
(
obsValuesForDaysIntervalArr
obsValuesForDaysIntervalArr
)
{
)
{
// The observation values array should only include non-`null` values
return
(
return
(
calculateSumOfObservationValuesWithinDatesInterval
(
calculateSumOfObservationValuesWithinDatesInterval
(
obsValuesForDaysIntervalArr
obsValuesForDaysIntervalArr
)
/
obsValuesForDaysIntervalArr
.
length
)
/
filterOutNullObservationValues
(
obsValuesForDaysIntervalArr
)
.
length
);
);
};
};
...
@@ -63,7 +82,10 @@ const calculateAverageOfObservationValuesWithinDatesInterval = function (
...
@@ -63,7 +82,10 @@ const calculateAverageOfObservationValuesWithinDatesInterval = function (
const
calculateMinimumObservationValuesWithinMonthInterval
=
function
(
const
calculateMinimumObservationValuesWithinMonthInterval
=
function
(
obsValuesForMonthIntervalArr
obsValuesForMonthIntervalArr
)
{
)
{
return
Math
.
min
(...
obsValuesForMonthIntervalArr
);
// If the observation value is `null`, skip the calculation
return
obsValuesForMonthIntervalArr
.
reduce
((
previousValue
,
obsValue
)
=>
obsValue
===
null
?
null
:
Math
.
min
(
previousValue
,
obsValue
)
);
};
};
/**
/**
...
@@ -74,7 +96,10 @@ const calculateMinimumObservationValuesWithinMonthInterval = function (
...
@@ -74,7 +96,10 @@ const calculateMinimumObservationValuesWithinMonthInterval = function (
const
calculateMaximumObservationValuesWithinMonthInterval
=
function
(
const
calculateMaximumObservationValuesWithinMonthInterval
=
function
(
obsValuesForMonthIntervalArr
obsValuesForMonthIntervalArr
)
{
)
{
return
Math
.
max
(...
obsValuesForMonthIntervalArr
);
// If the observation value is `null`, skip the calculation
return
obsValuesForMonthIntervalArr
.
reduce
((
previousValue
,
obsValue
)
=>
obsValue
===
null
?
null
:
Math
.
max
(
previousValue
,
obsValue
)
);
};
};
/**
/**
...
@@ -85,8 +110,10 @@ const calculateMaximumObservationValuesWithinMonthInterval = function (
...
@@ -85,8 +110,10 @@ const calculateMaximumObservationValuesWithinMonthInterval = function (
const
calculateSumOfObservationValuesWithinMonthInterval
=
function
(
const
calculateSumOfObservationValuesWithinMonthInterval
=
function
(
obsValuesForMonthIntervalArr
obsValuesForMonthIntervalArr
)
{
)
{
return
obsValuesForMonthIntervalArr
.
reduce
(
// Remove the `null` observation values before calculating the sum
(
accumulator
,
obsValue
)
=>
accumulator
+
obsValue
return
filterOutNullObservationValues
(
obsValuesForMonthIntervalArr
).
reduce
(
(
previousValue
,
obsValue
)
=>
previousValue
+
obsValue
,
0
);
);
};
};
...
@@ -98,10 +125,11 @@ const calculateSumOfObservationValuesWithinMonthInterval = function (
...
@@ -98,10 +125,11 @@ const calculateSumOfObservationValuesWithinMonthInterval = function (
const
calculateAverageOfObservationValuesWithinMonthInterval
=
function
(
const
calculateAverageOfObservationValuesWithinMonthInterval
=
function
(
obsValuesForMonthIntervalArr
obsValuesForMonthIntervalArr
)
{
)
{
// The observation values array should only include non-`null` values
return
(
return
(
calculateSumOfObservationValuesWithinMonthInterval
(
calculateSumOfObservationValuesWithinMonthInterval
(
obsValuesForMonthIntervalArr
obsValuesForMonthIntervalArr
)
/
obsValuesForMonthIntervalArr
.
length
)
/
filterOutNullObservationValues
(
obsValuesForMonthIntervalArr
)
.
length
);
);
};
};
...
...
public/js/src_modules/chartColumn.mjs
View file @
559e7982
...
@@ -131,10 +131,12 @@ const drawColumnChartHighcharts = function (
...
@@ -131,10 +131,12 @@ const drawColumnChartHighcharts = function (
title
:
{
title
:
{
text
:
textChartTitle
,
text
:
textChartTitle
,
"
align
"
:
"
center
"
,
},
},
subtitle
:
{
subtitle
:
{
text
:
textChartSubtitle
,
text
:
textChartSubtitle
,
"
align
"
:
"
center
"
,
},
},
xAxis
:
{
xAxis
:
{
...
@@ -143,7 +145,6 @@ const drawColumnChartHighcharts = function (
...
@@ -143,7 +145,6 @@ const drawColumnChartHighcharts = function (
},
},
yAxis
:
{
yAxis
:
{
min
:
0
,
title
:
{
title
:
{
text
:
`
${
phenomenonName
}
[
${
unitOfMeasurementSymbol
}
]`
,
text
:
`
${
phenomenonName
}
[
${
unitOfMeasurementSymbol
}
]`
,
},
},
...
@@ -155,10 +156,10 @@ const drawColumnChartHighcharts = function (
...
@@ -155,10 +156,10 @@ const drawColumnChartHighcharts = function (
// this.x -- common for all points
// this.x -- common for all points
// this.points -- an array containing properties for each series
// this.points -- an array containing properties for each series
// Note that our `reduce` method is in this format:
// Note that our `reduce` method is in this format:
// ((
accumulator
, currentValue, currentIndex) => {...}, initialValue)
// ((
previousValue
, currentValue, currentIndex) => {...}, initialValue)
return
this
.
points
.
reduce
(
return
this
.
points
.
reduce
(
(
accumulator
,
point
,
i
)
=>
(
previousValue
,
point
,
i
)
=>
`
${
accumulator
}
<br/> <span style="color:
${
point
.
color
}
">
${
`
${
previousValue
}
<br/> <span style="color:
${
point
.
color
}
">
${
point
.
series
.
name
point
.
series
.
name
}
</span>: <b>
${
point
.
y
.
toFixed
(
2
)}
${
}
</span>: <b>
${
point
.
y
.
toFixed
(
2
)}
${
unitOfMeasurementSymbolsArr
[
i
]
unitOfMeasurementSymbolsArr
[
i
]
...
...
public/js/src_modules/chartHeatmap.mjs
View file @
559e7982
...
@@ -48,7 +48,8 @@ const calculateMinMaxValuesForHeatmapColorAxis = function (
...
@@ -48,7 +48,8 @@ const calculateMinMaxValuesForHeatmapColorAxis = function (
const
maxValue
=
Math
.
trunc
(
Math
.
max
(...
obsValueArr
));
const
maxValue
=
Math
.
trunc
(
Math
.
max
(...
obsValueArr
));
// Calculate the closest multiple of 5
// Calculate the closest multiple of 5
const
minObsValue
=
minValue
-
(
minValue
%
5
);
const
minObsValue
=
minValue
>
0
?
minValue
-
(
minValue
%
5
)
:
minValue
+
(
minValue
%
5
);
const
maxObsValue
=
maxValue
+
(
5
-
(
maxValue
%
5
));
const
maxObsValue
=
maxValue
+
(
5
-
(
maxValue
%
5
));
return
{
minObsValue
,
maxObsValue
};
return
{
minObsValue
,
maxObsValue
};
...
@@ -98,13 +99,13 @@ const drawHeatMapHighcharts = function (
...
@@ -98,13 +99,13 @@ const drawHeatMapHighcharts = function (
title
:
{
title
:
{
text
:
TEXT_CHART_TITLE
,
text
:
TEXT_CHART_TITLE
,
align
:
"
left
"
,
align
:
"
center
"
,
x
:
40
,
x
:
40
,
},
},
subtitle
:
{
subtitle
:
{
text
:
TEXT_CHART_SUBTITLE
,
text
:
TEXT_CHART_SUBTITLE
,
align
:
"
left
"
,
align
:
"
center
"
,
x
:
40
,
x
:
40
,
},
},
...
...
public/js/src_modules/chartLine.mjs
View file @
559e7982
...
@@ -134,12 +134,12 @@ const drawLineChartHighcharts = function (
...
@@ -134,12 +134,12 @@ const drawLineChartHighcharts = function (
title
:
{
title
:
{
text
:
textChartTitle
,
text
:
textChartTitle
,
"
align
"
:
"
left
"
,
"
align
"
:
"
center
"
,
},
},
subtitle
:
{
subtitle
:
{
text
:
textChartSubtitle
,
text
:
textChartSubtitle
,
align
:
"
left
"
,
align
:
"
center
"
,
},
},
tooltip
:
{
tooltip
:
{
...
...
public/js/src_modules/chartScatterPlot.mjs
View file @
559e7982
...
@@ -231,12 +231,12 @@ const drawScatterPlotHighcharts = function (
...
@@ -231,12 +231,12 @@ const drawScatterPlotHighcharts = function (
title
:
{
title
:
{
text
:
CHART_TITLE
,
text
:
CHART_TITLE
,
"
align
"
:
"
left
"
,
"
align
"
:
"
center
"
,
},
},
subtitle
:
{
subtitle
:
{
text
:
CHART_SUBTITLE
,
text
:
CHART_SUBTITLE
,
"
align
"
:
"
left
"
,
"
align
"
:
"
center
"
,
},
},
xAxis
:
{
xAxis
:
{
...
...
public/js/src_modules/dropDownListHelpers.mjs
View file @
559e7982
"
use strict
"
;
/**
/**
* Get the selected option(s) from a dropdown list
* Get the selected option(s) from a dropdown list
*
*
...
...
public/js/src_modules/dropDownListProcessing.mjs
View file @
559e7982
"
use strict
"
;
import
{
drawLineChartHighcharts
}
from
"
./chartLine.mjs
"
;
import
{
drawLineChartHighcharts
}
from
"
./chartLine.mjs
"
;
import
{
import
{
...
...
public/js/src_modules/loadingIndicator.mjs
View file @
559e7982
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
/**
/**
* Show a loading indicator at the start of an async task. The indicator consists of a spinner and a transluscent mask placed on top of page elements
* Show a loading indicator at the start of an async task. The indicator consists of a spinner and a transluscent mask placed on top of page elements
* @returns {undefined}
* @returns {undefined}
undefined
*/
*/
const
showLoadingSpinner
=
function
()
{
const
showLoadingSpinner
=
function
()
{
const
loadingIndicatorMask
=
document
.
querySelector
(
"
#loadingIndicator
"
);
const
loadingIndicatorMask
=
document
.
querySelector
(
"
#loadingIndicator
"
);
...
@@ -14,7 +14,7 @@ const showLoadingSpinner = function () {
...
@@ -14,7 +14,7 @@ const showLoadingSpinner = function () {
/**
/**
* Hide the loading indicator after completion of the async tasks
* Hide the loading indicator after completion of the async tasks
* @returns {undefined}
* @returns {undefined}
undefined
*/
*/
const
hideLoadingSpinner
=
function
()
{
const
hideLoadingSpinner
=
function
()
{
const
loadingIndicatorMask
=
document
.
querySelector
(
"
#loadingIndicator
"
);
const
loadingIndicatorMask
=
document
.
querySelector
(
"
#loadingIndicator
"
);
...
@@ -24,4 +24,27 @@ const hideLoadingSpinner = function () {
...
@@ -24,4 +24,27 @@ const hideLoadingSpinner = function () {
loadingIconSpinner
.
style
.
display
=
"
none
"
;
loadingIconSpinner
.
style
.
display
=
"
none
"
;
};
};
export
{
showLoadingSpinner
,
hideLoadingSpinner
};
/**
* Disable the button used to trigger the drawing of charts
*
* @returns {undefined} undefined
*/
const
disableDrawChartButton
=
function
()
{
document
.
querySelector
(
"
#btn-draw-chart
"
).
disabled
=
true
;
};
/**
* Enable the button used to trigger the drawing of charts
*
* @returns {undefined} undefined
*/
const
enableDrawChartButton
=
function
()
{
document
.
querySelector
(
"
#btn-draw-chart
"
).
disabled
=
false
;
};
export
{
showLoadingSpinner
,
hideLoadingSpinner
,
disableDrawChartButton
,
enableDrawChartButton
,
};
public/js/thirdparty/scripts.js
View file @
559e7982
/*!
/*!
* Start Bootstrap - SB Admin v6.0.2 (https://startbootstrap.com/template/sb-admin)
* Start Bootstrap - SB Admin v7.0.3 (https://startbootstrap.com/template/sb-admin)
* Copyright 2013-2020 Start Bootstrap
* Copyright 2013-2021 Start Bootstrap
* Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-sb-admin/blob/master/LICENSE)
* Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-sb-admin/blob/master/LICENSE)
*/
*/
(
function
(
$
)
{
//
"
use strict
"
;
// Scripts
//
// Add active state to sidbar nav links
window
.
addEventListener
(
"
DOMContentLoaded
"
,
(
event
)
=>
{
var
path
=
window
.
location
.
href
;
// because the 'href' property of the DOM element is the absolute path
// Toggle the side navigation
$
(
"
#layoutSidenav_nav .sb-sidenav a.nav-link
"
).
each
(
function
()
{
const
sidebarToggle
=
document
.
body
.
querySelector
(
"
#sidebarToggle
"
);
if
(
this
.
href
===
path
)
{
if
(
sidebarToggle
)
{
$
(
this
).
addClass
(
"
active
"
);
// Uncomment Below to persist sidebar toggle between refreshes
}
// if (localStorage.getItem('sb|sidebar-toggle') === 'true') {
});
// document.body.classList.toggle('sb-sidenav-toggled');
// }
// Toggle the side navigation
sidebarToggle
.
addEventListener
(
"
click
"
,
(
event
)
=>
{
$
(
"
#sidebarToggle
"
).
on
(
"
click
"
,
function
(
e
)
{
event
.
preventDefault
();
e
.
preventDefault
();
document
.
body
.
classList
.
toggle
(
"
sb-sidenav-toggled
"
);
$
(
"
body
"
).
toggleClass
(
"
sb-sidenav-toggled
"
);
localStorage
.
setItem
(
"
sb|sidebar-toggle
"
,
document
.
body
.
classList
.
contains
(
"
sb-sidenav-toggled
"
)
);
});
});
})(
jQuery
);
}
});
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