-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
74 lines (59 loc) · 2.26 KB
/
app.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
import { download } from "./core/export";
import { render } from "./core/plot";
document.querySelector("#loader").classList.add("hide");
let radiusInput = document.querySelector("input#radius");
let radiusButton = document.querySelector("input#select-radius");
let cellScaleInput = document.querySelector("#cell-scale");
let cellScaleButton = document.querySelector("input#select-cell-scale");
let downloadButton = document.querySelector("#select-download");
let cellShapeInput = document.querySelector("#cell-shape");
let cellShapeButton = document.querySelector("#select-cell-shape");
let yearInput = document.querySelector("input#year");
let yearButton = document.querySelector("input#select-year");
radiusButton.addEventListener("click", () => {
radiusInput = document.querySelector("input#radius");
document.querySelector("#loader").classList.remove("hide");
load();
});
yearButton.addEventListener("click", () => {
yearInput = document.querySelector("input#year");
document.querySelector("#loader").classList.remove("hide");
load();
});
downloadButton.addEventListener("click", () => {
let fileType = document.querySelector("#download").value;
download(fileType, yearInput.value);
});
cellShapeButton.addEventListener("click", () => {
cellShapeInput = document.querySelector("#cell-shape");
document.querySelector("#loader").classList.remove("hide");
load();
});
cellScaleButton.addEventListener("click", () => {
cellScaleInput = document.querySelector("#cell-scale");
document.querySelector("#loader").classList.remove("hide");
load();
});
function load() {
let cellRadius = radiusInput.value;
let cellShape = cellShapeInput.value;
let cellScale = cellScaleInput.value;
let year = yearInput.value;
const topoData = d3.json(
"https://raw.githubusercontent.com/owid/cartograms/main/data/base/2018/v2/topo.json"
);
const popData = d3.csv(
"https://raw.githubusercontent.com/owid/cartograms/main/data/population/unpd-flat.csv"
);
Promise.all([topoData, popData]).then((res) => {
let [topoData, popData] = res;
let cellDetails = {
radius: cellRadius,
shape: cellShape,
scale: cellScale,
};
render(topoData, popData, cellDetails, year);
document.querySelector("#loader").classList.add("hide");
});
}
load();