-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvisualization.js
More file actions
64 lines (51 loc) · 2.13 KB
/
visualization.js
File metadata and controls
64 lines (51 loc) · 2.13 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
document.addEventListener("DOMContentLoaded", () => {
d3.json("/countries.json")
.then(countries => {
d3.csv("/europe-nato-members.csv")
.then(members => {
// Define the dimensions of your visualization
const width = 800
const height = 600
// Get the visualization container
const container = d3.select("#viz")
// Append and configure your svg node
const svg = container.append("svg")
.attr("width", width)
.attr("height", height)
// Configure a map projection for Europe
const projection = d3.geoAzimuthalEqualArea()
.rotate([-10.0, -52.0])
.translate([width / 2, height / 2])
.scale(700)
.precision(.1)
// Configure a pathGenerator based on your projection
const pathGenerator = d3.geoPath().projection(projection)
// Bind the `countries.features` to `paths`
const shapes = svg.selectAll("path")
.data(countries.features)
.enter()
.append("path")
.attr("d", pathGenerator)
.attr("fill", function(country) {
const natoMetaData = members.find(member => member.iso3 === country.properties.ADM0_A3)
if (natoMetaData) {
return +natoMetaData.year_of_accession <= 2019
? "#004990"
: "#DDDDDD"
}
else {
return "#DDDDDD"
}
})
// Button data
const buttonData = [
{ label: "1949", value: 1949 },
{ label: "Today", value: 2019 },
]
// Finde mit `d3.select` den Controls container `#controls`
// 1. Binde `buttonData` an zwei Knöpfe mit `d3.selectAll("button")`, `data()`, `enter()` und `append("button")`
// 2. Schliesse deine Buttons an click events um die Farben je nach Jahr zu wechseln
// 3. Wechsle die Farbe der Länder, die in 1949 keine Natomitgliedstaaten waren.
})
})
})