-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
136 lines (120 loc) · 3.63 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
134
135
136
<!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>Nuclear Firepower</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js"></script>
<style>
.box {
stroke: black;
fill: white;
}
.nuke {
fill: red;
}
svg {
display: block;
margin: auto;
}
#title {
text-align: center;
width: 600px;
margin: 0 auto;
}
.group {
stroke: black;
fill: none;
}
</style>
</head>
<body>
<div class="diagram"></div>
<div id='title'>
<h4>Fig.1.1 Nuclear firepower</h4>
<p>The dot in the centre represents all the firepower of World War II. The other dots <br> represent the firepower of existing nuclear weapons.</p>
<p><i>Source: Toronto Star,</i> 24 January 1982</p>
</div>
<script>
let data = [];
const width = 600;
for (let i = 0; i < 11; i++) {
for (let j = 0; j < 11; j++) {
data.push({
x: i,
y: j
});
}
}
function innerGrid(x, y) {
let grid = [];
let rowsCols = (boxSize / 7);
for (let i = 0; i < 7; i++) {
for (let j = 0; j < 7; j++) {
let jitter = 3;
if ((i < 6 && i > 0) && (j < 6 && j > 0)) {
jitter = 5;
}
let xJitter = Math.floor(Math.random() * jitter) - jitter;
let yJitter = Math.floor(Math.random() * jitter) - jitter;
grid.push({
x: (rowsCols * i) + 6 + xJitter + (x * boxSize),
y: (rowsCols * j) + 6 + yJitter + (y * boxSize)
})
}
}
return grid;
}
const svg = d3.select('.diagram')
.append('svg')
.attr('width', width)
.attr('height', width);
const boxSize = width / 11;
svg.selectAll('.box')
.data(data)
.enter()
.append('rect')
.attr('x', function(d) {
return d.x * boxSize;
})
.attr('y', function(d) {
return d.y * boxSize;
})
.attr('height', boxSize)
.attr('width', boxSize)
.attr('class', 'box');
let pointData = [];
let limitData = data;
limitData.splice(60, 1);
for (var i = 0; i < limitData.length; i++) {
let grid = innerGrid(limitData[i].x, limitData[i].y);
pointData = pointData.concat(grid);
}
pointData = pointData.concat([{
x: 5,
y: 5
}]);
svg.selectAll('.nuke')
.data(pointData)
.enter()
.append('circle')
.attr('r', 2)
.attr('cx', function(d, i) {
if (d.x == 5 && d.y == 5) {
return width / 2;
} else {
return d.x;
}
})
.attr('cy', (d, i) => {
if (d.x == 5 && d.y == 5) {
return width / 2;
} else {
return d.y;
}
})
.attr('class', 'nuke');
</script>
</body>
</html>