-
Notifications
You must be signed in to change notification settings - Fork 0
/
dorling.html
57 lines (54 loc) · 1.36 KB
/
dorling.html
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
<head>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Tangerine"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Pacifico"
/>
</head>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]"
charset="utf-8"
></script>
<script>
let geojson = "./world.json";
d3.json(geojson).then((data) => {
let svg = geoviz.create({
margin: [30, 100, -45, -100],
projection: "Equirectangular",
});
let centroids = geoviz.tool.centroid(data);
let dots = geoviz.tool.dodge(centroids, {
projection: svg.projection,
r: "pop",
k: 100,
iteration: 300,
});
svg.circle({ data: dots, coords: "svg", r: "pop", fill: "black", k: 100 });
let scale = d3.scaleSqrt(
[0, d3.max(data.features.map((d) => +d.properties.pop))],
[0, 100 * 0.6]
);
svg.text({
data: dots,
coords: "svg",
fill: "white",
text: "ISO3",
fontFamily: "Pacifico",
fontSize: (d) => scale(d.properties.pop),
});
svg.header({
fontSize: 60,
text: "A Dorling Cartogram World Map",
fill: "black",
fontWeight: "bold",
fontFamily: "Tangerine",
background_opacity: 0,
});
document.body.appendChild(svg.render());
});
</script>