-
Notifications
You must be signed in to change notification settings - Fork 87
/
d3v5_roughjs_example.html
93 lines (83 loc) · 2.36 KB
/
d3v5_roughjs_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
89
90
91
92
93
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
display: block;
width: 1450px;
height: 900px;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: 0.5px;
}
.states {
stroke: #fff;
stroke-width: 0.5;
}
</style>
<svg id="svg"></svg>
<!-- <script src="https://rawgit.com/pshihn/workly/master/dist/workly.min.js"></script>-->
<script src="lib/rough.js"></script>
<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>
const svg = document.getElementById('svg');
const rc = rough.svg(svg, {
async: true,
options: {
simplification: 0.2,
roughness: 0.65
}
});
var width = 1500;
var height = 900;
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);
const randomColor = () => {
let r = `rgb(${Math.round(Math.random() * 255)}, ${Math.round(Math.random() * 255)}, ${Math.round(Math.random() * 255)})`;
return r;
}
const colors = d3.scaleOrdinal(d3.schemePaired);
const randomAngle = () => {
return (Math.random() > 0.5 ? -1 : 1) * (1 + Math.random() * 88);
}
d3.json('geojson/world_1945.geojson').then(function(data,error) {
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());
for (let feature of data.features) {
let name = feature.properties.SUBJECTO || feature.properties.NAME;
let fpath = rc.path(
path(feature),
{
// fill: randomColor(),
fill: d3.interpolateWarm(categories.indexOf(name)/categories.length),
fillStyle: '',
hachureAngle: randomAngle()
}
)
svg.appendChild(fpath);
}
}
);
</script>