-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathd3v5_example.html
88 lines (80 loc) · 2.81 KB
/
d3v5_example.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
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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: 0.5px;
}
.states {
stroke: #fff;
stroke-width: 0.5;
}
</style>
<!--
D3 v5 depeds on Fetch API that does not support local files fetching
To run locally:
- run python -m SimpleHTTPServer from the folder and then call http://localhost:8000/ in navigator
This might help in other cases of running js scripts locally, but should not be needed with this one:
- In Firefox: disable strict origin control in about:cofig
- Launch Chrome with /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --user-data-dir
-->
<svg width="1500" height="900"></svg>
<script src="lib/d3.v5.min.js"></script>
<script src="lib/d3-geo.v1.min.js"></script>
<script src="lib/d3-geo-projection.v2.min.js"></script>
<script src="lib/d3-geo-polygon.min.js"></script>
<script src="lib/d3-scale-chromatic.v3.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var projection =
// d3.geoPeirceQuincuncial() //
// d3.geoGringortenQuincuncial()
// d3.geoInterruptedMollweideHemispheres()
// d3.geoAzimuthalEquidistant()
// d3.geoInterruptedMollweideHemispheres()
// d3.geoWiechel()
// d3.geoPolyhedralWaterman()
d3.geoAirocean()
// d3.geoSinuMollweide() //
// d3.geoNaturalEarth1() //
// d3.geoLoximuthal() //
// d3.geoBonne() //
// d3.geoBertin()
.scale(90)
.translate([width / 2, height / 2])
.precision(0.1);
var path = d3.geoPath()
.projection(projection);
d3.json('geojson/world_1945.geojson').then(
function makeMyMap(data,error) {
console.log(data);
if (error) throw error;
let categories = [...new Set(data.features.map(d => d.properties.SUBJECTO || d.properties.NAME))];
categories = categories.sort((a, b) => 0.5 - Math.random());
// var colors = d3.scaleOrdinal(d3.schemePaired);
svg.append("g")
.attr("class", "states")
.selectAll("path")
.data(data.features)
.enter().append("path")
.attr("d", path)
.attr("fill", function(d){
let name = d.properties.SUBJECTO || d.properties.NAME;
if (name==="Antarctica") {return "white"}
else if (name==null | name=='unclaimed') {return "grey"}
else {
return d3.interpolateWarm(categories.indexOf(name)/categories.length);
// return colors(Math.floor(Math.random() * d3.schemePaired.length));
// return colors(d.properties.BORDER_COLOR_INDEX) // The problem with topological coloring is that it ignores the new variable SUBJECTO
}
})
;
}
);
</script>