forked from akshaypatel67/CurrEx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilterData.js
53 lines (42 loc) · 1.78 KB
/
filterData.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function filterData() {
chartX = [];
chartY = [];
currentCurrency = dropDown.value;
currentDate = new Date(sDate.value);
currentDate.setHours(0);
currentDate.setMinutes(0);
let mx = Number.MIN_SAFE_INTEGER;
let mn = Number.MAX_SAFE_INTEGER;
let mxDate = null;
let mnDate = null;
data.forEach((element) => {
let elementDate = new Date(element["1Date"]);
if(elementDate >= currentDate && elementDate <= addDays(currentDate, dayCount[currentRange])) {
if(element[currentCurrency] != null) {
chartX.push(element["1Date"]);
chartY.push(element[currentCurrency]);
if(element[currentCurrency] > mx) {
mx = element[currentCurrency];
mxDate = elementDate;
}
if(element[currentCurrency] < mn) {
mn = element[currentCurrency];
mnDate = elementDate;
}
}
}
});
let minMaxString = ""
let minMax = document.getElementById("minmaxinfo");
if(mxDate != null) {
let mxdate = ' (' + mxDate.getFullYear()+' - '+(mxDate.getMonth()+1)+' - '+mxDate.getDate() + ')';
minMaxString = "Max Currency Rate: " + (mx == Number.MIN_SAFE_INTEGER ? "-" : mx + mxdate) + "<br><br>";
let mndate = ' (' + mnDate.getFullYear()+' - '+(mnDate.getMonth()+1)+' - '+mnDate.getDate() + ')';
minMaxString += "Min Currency Rate: " + (mn == Number.MAX_SAFE_INTEGER ? "-" : mn + mndate) + "\n";
} else {
minMaxString = "Max Currency Rate: - <br><br>";
minMaxString += "Min Currency Rate: - <br><br>";
}
minMax.innerHTML = minMaxString;
displayChart();
}