-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
70 lines (65 loc) · 1.57 KB
/
Copy pathmain.js
File metadata and controls
70 lines (65 loc) · 1.57 KB
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
let climate_daly_data = [{
region: "Low-and-middle-income countries of the African Region",
deaths: 57
},
{
region: "Low-and-middle-income countries of the Americas",
deaths: 2
},
{
region: "Low-and-middle-income countries of the Eastern Mediterranean Region",
deaths: 20
},
{
region: "Low-and-middle-income countries of the European Region",
deaths: 0.67
},
{
region: "Low-and-middle-income countries of the South-East Asia Region",
deaths: 58
},
{
region: "Low-and-middle-income countries of the Western Pacific Region",
deaths: 4
},
{
region: "High income countries",
deaths: 0.23
}
];
let toggleClass = (i, toggle) => {
d3.select("#viz div:nth-child(" + i + ")").classed("highlightBar", toggle);
d3.select("#legend li:nth-child(" + i + ")").classed("highlightText", toggle);
};
let divSelection = d3.select('#viz')
.selectAll('div');
divSelection
.data(climate_daly_data)
.enter()
.append("div")
.attr("class", "bar")
.style("width", function (d) {
return d.deaths * 8 + 'px';
})
.on("mouseover", function (d, i) {
i = i + 1;
toggleClass(i, true);
})
.on("mouseout", function (d, i) {
i = i + 1;
toggleClass(i, false);
});
let listSelection = d3.select('#legend')
.selectAll('li');
listSelection.data(climate_daly_data)
.enter()
.append('li')
.text((d) => {
return d.region + ': ' + d.deaths + ' deaths'
})
.on('mouseover', (d, i) => {
toggleClass(i + 1, true);
})
.on('mouseout', (d, i) => {
toggleClass(i + 1, false);
});