-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
102 lines (76 loc) · 2.13 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* HOW TO USE A FUNCTION
function myFunction (){
alert("hello world!");
}
myFunction();
*/
/***********************************************************************************/
// Choropleth Chart zur Zahl der Covid-19-Fälle in den einzelnen Kreisen
/***********************************************************************************/
function vis_choropleth() {
// The svg
var svg = d3.select("#vis_map"),
width = 800,
height = 700;
// Map and projection
var projection = d3.geoMercator()
.translate([width / 2, height / 2])
.scale(8000)
.center([9.24,52.45]);
var path = d3.geoPath()
.projection(projection);
// Data and color scale
var data = d3.map();
var colorScale = d3.scaleOrdinal().range(d3.schemeBlues[3]);
// Load external data and boot
var promises = [
d3.json("viz/nds_kreise.geojson"),
d3.csv("time_series/time_series_covid-19_nds_confirmed.csv", function(d) { data.set(d.code, +d.pop);})
];
Promise.all(promises).then(ready);
function ready(fulfillmentvalue) {
let mouseover = function(d) {
d3.selectAll(".Country")
.transition()
.duration(100)
.style("opacity", 1);
d3.select(this)
.transition()
.duration(100)
.style("opacity", 1)
.style("stroke", "white");
console.log(this);
tooltip.style("display", null);
};
let mouseleave = function(d) {
d3.selectAll(".Country")
.transition()
.duration(200)
.style("opacity", 0.8);
d3.select(this)
.transition()
.duration(200)
.style("stroke", "transparent");
tooltip.style("display", "none");
};
// Draw the map
svg.append("g")
.selectAll("path")
.data(fulfillmentvalue[0].features)
.enter()
.append("path")
// draw each country
.attr("d", d3.geoPath()
.projection(projection)
)
// set the color of each country
.attr("fill", function (d) {
d.total = data.get(d.id) || 0;
return colorScale(d.total);
})
.style("stroke", "black")
.attr("class", function(d){ return "Country"; } )
.style("opacity", 0.5);
}
} // end vis_choropleth
vis_choropleth();