dropDownListChartColumn.mjs 4.88 KB
Newer Older
1
2
"use strict";

3
4
5
6
7
import { drawColumnChartHighcharts } from "./chartColumn.mjs";

import {
  calculateAndFormatDailySumObservations,
  calculateAndFormatMonthlySumObservations,
8
9
10
} from "./dropDownListAggregationSum.mjs";

import {
11
12
  calculateAndFormatDailyMaximumObservations,
  calculateAndFormatMonthlyMaximumObservations,
13
14
15
} from "./dropDownListAggregationMaximum.mjs";

import {
16
17
  calculateAndFormatDailyMinimumObservations,
  calculateAndFormatMonthlyMinimumObservations,
18
19
20
} from "./dropDownListAggregationMinimum.mjs";

import {
21
22
  calculateAndFormatDailyAverageObservations,
  calculateAndFormatMonthlyAverageObservations,
23
} from "./dropDownListAggregationAverage.mjs";
24
25
26
27
28
29

/**
 * Draw a column chart based on the selected aggregation options from a drop-down list
 *
 * @param {String} selectedAggregationType A string representing the selected aggregation type. The currently supported strings include `Sum`, `Maximum`, `Minimum` and `Average`
 * @param {String} selectedAggregationDuration A string representing the selected aggregation duration. The currently supported strings include `Daily` and `Monthly`
30
 * @param {Array} observationsNestedArr An array made up of sub-array(s) of observations
31
32
33
34
35
36
 * @param {String} selectedSamplingRateAbbrev A string representing the abbreviated form of the selected sampling rate option
 * @param {Array} uniqueCalendarDatesNestedArr An array made up of sub-array(s) of unique calendar date(s) string(s)
 * @param {Array} formattedMetadataNestedArr An array of sub-arrays of formatted metadata properties
 * @returns {undefined} undefined
 */
export const drawColumnChartBasedOnSelectedAggregationOptions = function (
37
  selectedAggregationType,
38
  selectedAggregationDuration,
39
  observationsNestedArr,
40
41
42
43
  selectedSamplingRateAbbrev,
  uniqueCalendarDatesNestedArr,
  formattedMetadataNestedArr
) {
44
  // Daily / sum
45
  if (
46
    selectedAggregationType === "Sum" &&
47
48
    selectedAggregationDuration === "Daily"
  ) {
49
50
51
    // Note: The `drawColumnChart` function expects two arguments,
    // these are obtained by using the spread operator on the
    // result returned from the `calculateAndFormat...` functions
52
    drawColumnChartHighcharts(
53
54
55
56
57
58
      ...calculateAndFormatDailySumObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
59
    );
60
61
62
63
  }
  // Monthly / sum
  else if (
    selectedAggregationType === "Sum" &&
64
65
66
    selectedAggregationDuration === "Monthly"
  ) {
    drawColumnChartHighcharts(
67
68
69
70
71
72
      ...calculateAndFormatMonthlySumObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
73
    );
74
75
76
77
  }
  // Daily / maximum
  else if (
    selectedAggregationType === "Maximum" &&
78
79
80
    selectedAggregationDuration === "Daily"
  ) {
    drawColumnChartHighcharts(
81
82
83
84
85
86
      ...calculateAndFormatDailyMaximumObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
87
    );
88
89
90
91
  }
  // Monthly / maximum
  else if (
    selectedAggregationType === "Maximum" &&
92
93
94
    selectedAggregationDuration === "Monthly"
  ) {
    drawColumnChartHighcharts(
95
96
97
98
99
100
      ...calculateAndFormatMonthlyMaximumObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
101
    );
102
103
104
105
  }
  // Daily / minimum
  else if (
    selectedAggregationType === "Minimum" &&
106
107
108
    selectedAggregationDuration === "Daily"
  ) {
    drawColumnChartHighcharts(
109
110
111
112
113
114
      ...calculateAndFormatDailyMinimumObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
115
    );
116
117
118
119
  }
  // Monthly / minimum
  else if (
    selectedAggregationType === "Minimum" &&
120
121
122
    selectedAggregationDuration === "Monthly"
  ) {
    drawColumnChartHighcharts(
123
124
125
126
127
128
      ...calculateAndFormatMonthlyMinimumObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
129
    );
130
131
132
133
  }
  // Daily / average
  else if (
    selectedAggregationType === "Average" &&
134
135
136
    selectedAggregationDuration === "Daily"
  ) {
    drawColumnChartHighcharts(
137
138
139
140
141
142
      ...calculateAndFormatDailyAverageObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
143
    );
144
145
146
147
  }
  // Monthly / average
  else if (
    selectedAggregationType === "Average" &&
148
149
150
    selectedAggregationDuration === "Monthly"
  ) {
    drawColumnChartHighcharts(
151
152
153
154
155
156
      ...calculateAndFormatMonthlyAverageObservations(
        uniqueCalendarDatesNestedArr,
        observationsNestedArr,
        selectedSamplingRateAbbrev,
        formattedMetadataNestedArr
      )
157
158
159
    );
  }
};