-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
executable file
·77 lines (67 loc) · 2.76 KB
/
script.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fetch("Egå Engsø.json")
.then((r) => r.json())
.then((points) => {
const intersectionObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const id = entry.target.id;
console.log(id);
const [dates,counts] = points[id];
var selectorOptions = {
buttons: [ {
step: 'year',
stepmode: 'todate',
count: 1,
label: 'YTD'
}, {
step: 'year',
stepmode: 'backward',
count: 1,
label: '1y'
}, {
step: 'year',
stepmode: 'backward',
count: 2,
label: '2y'
}, {
step: 'year',
stepmode: 'backward',
count: 5,
label: '5y'
}, {
step: 'all',
}],
};
var data = [
{
x: dates,
y: counts,
type: "histogram",
histfunc: "max",
xbins: {
size: "M1",
},
},
];
var layout = {
title: id,
yaxis: {
//fixedrange: true,
//rangemode: "nonnegative",
},
xaxis: {
tickformat: "%b\n%Y",
//range: ["2020-01-01", "2024-01-01"],
rangeselector: selectorOptions,
//rangeslider: {}
},
};
Plotly.newPlot(id, data, layout, { staticPlot: false, responsive: true });
intersectionObserver.unobserve(entry.target);
}
});
});
document.querySelectorAll(".plot").forEach((plot) => {
intersectionObserver.observe(plot);
});
});