-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·133 lines (117 loc) · 3.26 KB
/
index.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body { background: #000000}
#thesvg { width: 1440px; height: 900px}
@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {
}
</style>
</head>
<body>
<script src="data.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<svg id="thesvg"></svg>
<script>
var svg = d3.select("svg");
var colour = d3.scaleOrdinal(d3.schemeCategory10);
var data = window.data
.map(d => ({
...d,
radius: d.radius / 100 * 80 + 20
}))
.map(d => {
return { r: d.radius, url: d.url }
});
var simulation = d3.forceSimulation(data)
.force("x", d3.forceX(600).strength(0.05))
.force("y", d3.forceY(350).strength(0.05))
.force("collide", d3.forceCollide(function(d) {
return d.r + 8;
}));
var xmobile = window.matchMedia("(max-width: 370px)")
function mobile(x) {
if (xmobile.matches) {
var simulation = d3.forceSimulation(data)
.force("x", d3.forceX(0).strength(0.05))
.force("y", d3.forceY(20).strength(0.05))
.force("collide", d3.forceCollide(function(d) {
return d.r + 8;
}));
}
}
mobile(xmobile)
xmobile.addListener(mobile)
var defs = svg.append("defs");
defs.selectAll(".flag")
.data(data)
.enter()
.append("pattern")
.attr("id", function(d, i) { return i; })
.attr("class", "flag")
.attr("width", "100%")
.attr("height", "100%")
.attr("patternContentUnits", "objectBoundingBox")
.append("image")
.attr("width", 1)
.attr("height", 1)
// xMidYMid: center the image in the circle
// slice: scale the image to fill the circle
.attr("preserveAspectRatio", "xMidYMid slice")
.attr("xlink:href", function(d) {
return d.url;
});
var circles = svg.selectAll(".circles")
.data(data)
.enter()
.append("circle")
.attr("r", d => d.r)
.attr("fill", (d, i) => "url(#"+i+")");
var isOver = false
var timeout = null
circles.on('mouseover', function(){
isOver = true
clearTimeout(timeout)
timeout = setTimeout(function(){
if(isOver){
mouseOn()
}
}, 100)
})
.on('mouseout', function(){
isOver = false
clearTimeout(timeout)
timeout = setTimeout(function(){
if(!isOver){
mouseOff()
}
}, 100)
})
simulation.nodes(data)
.on("tick", d => {
circles.attr("cx", d => d.x ).attr("cy", d => d.y);
});
function mouseOn() {
simulation.force("collide", d3.forceCollide(function(d) {
return d.r * 1.5;
}));
simulation.alpha(0.8).restart();
}
function mouseOff() {
// d3.select(this).attr('r', d => d.r);
//circles.attr('opacity', 1);
simulation.force("collide", d3.forceCollide(function(d) {
return d.r + 8;
}));
simulation.alpha(0.8).restart();
}
</script>
</body>
</html>