prepRibbonData.js 1007 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function prepRibbonData(jsonData) {
  let resList = [];

  let resJson = {
    x: [],
    y: [],
    z: [],
  };

  const L = jsonData.length;

  var startVal = 2;
  var currentMonth = 0;

  for (var d = 0; d < L; d++) {
    let tmpDate = new Date(jsonData[d].x);
    // let datum = tmpDate.getDate(); // gets the day of the month 1...31
    let month = date.getMonth(); // gets the month as numeric value

    if (currentMonth === month) {
      resJson.x.push([startVal, startVal + 1]);
      resJson.y.push([tmpDate, tmpDate]);
      resJson.z.push([jsonData[d].y, jsonData[d].y]);
    } else {
      resList.push(resJson);
      resJson.x = [];
      resJson.y = [];
      resJson.z = [];
      currentMonth += 1;
      startVal += 2;
    }
  } // end of for loop

  // add results for last month as else statement will not be reached for the december
  // as the condition d < L will be true before the condition currentMonth === month can be evaluated
//   resList.push(resJson);

  return resList;
}