-
Notifications
You must be signed in to change notification settings - Fork 6
/
world.html
257 lines (230 loc) · 11.8 KB
/
world.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!-- Copyright 2019 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Around the world</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="description" content="Exploring the Bach Doodle dataset">
<link href="style.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Work+Sans:400,700&display=swap" rel="stylesheet">
<style>
a.blob {
display: block !important;
position: absolute;
border-radius: 50%;
transition: transform 0.2s linear;
cursor: pointer;
overflow: hidden;
will-change: transform;
box-shadow: none;
}
.blob img, .blob .overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.blob .overlay {
color: black;
font-size: 20px;
line-height: 20px;
font-weight: bold;
padding-top: 50%;
background: rgba(255,255,255,0.8);
display: none;
}
a.blob:hover {
transform: scale(1.2);
z-index: 10;
}
.blob:hover .overlay {
display: block;
}
#container {
position: relative;
max-width: 960px;
width: 100%;
margin: 0 auto;
margin-top: -100px;
}
@media screen and (max-width: 600px) {
#container {
margin-top: -50px;
}
}
</style>
</head>
<body>
<header>
<div class="horizontal">
<button class="menu-btn" aria-label="nav drawer button" onclick="document.body.classList.toggle('drawer-opened')">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/></svg>
</button>
<a href="index.html">Bach Doodle Dataset</a>
</div>
<div class="menu">
<div class="hide-from-toolbar">
<a href="overall.html">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M12 7.13l.97 2.29.47 1.11 1.2.1 2.47.21-1.88 1.63-.91.79.27 1.18.56 2.41-2.12-1.28-1.03-.64-1.03.62-2.12 1.28.56-2.41.27-1.18-.91-.79-1.88-1.63 2.47-.21 1.2-.1.47-1.11.97-2.27M12 2L9.19 8.63 2 9.24l5.46 4.73L5.82 21 12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2z"/></svg>
Top overall melodies
</a>
<a href="world.html">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"/></svg>
Compositions around the world
</a>
<a href="unique.html">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M22 11h-4.17l3.24-3.24-1.41-1.42L15 11h-2V9l4.66-4.66-1.42-1.41L13 6.17V2h-2v4.17L7.76 2.93 6.34 4.34 11 9v2H9L4.34 6.34 2.93 7.76 6.17 11H2v2h4.17l-3.24 3.24 1.41 1.42L9 13h2v2l-4.66 4.66 1.42 1.41L11 17.83V22h2v-4.17l3.24 3.24 1.42-1.41L13 15v-2h2l4.66 4.66 1.41-1.42L17.83 13H22z"/><path fill="none" d="M0 0h24v24H0z"/></svg>
Most unique regional compositions
</a>
<a href="dataset.html">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V6h16v12zM6 10h2v2H6zm0 4h8v2H6zm10 0h2v2h-2zm-6-4h8v2h-8z"/></svg>
Random dataset samples
</a>
</div>
<a href="https://magenta.tensorflow.org/datasets/bach-doodle" target="_blank">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>
Get the data
</a>
<a href="https://www.google.com/doodles/celebrating-johann-sebastian-bach" target="_blank">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M15 6H3v2h12V6zm0 4H3v2h12v-2zM3 16h8v-2H3v2zM17 6v8.18c-.31-.11-.65-.18-1-.18-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3V8h3V6h-5z"/></svg>
Play the game
</a>
<a target="_blank" href="https://twitter.com/intent/tweet?hashtags=madewithmagenta&text=What%20do%2024%20million%20melodies%20composed%20with%20the%20Bach%20Doodle%20look%20like%3F%20https%3A%2F%2Fmagenta.github.io%2Fbach-doodle-visualization">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92 1.61 0 2.92-1.31 2.92-2.92s-1.31-2.92-2.92-2.92z"/></svg>
Share
</a>
</div>
</div>
</header>
<section>
<h1>Compositions around the <span class="accent primary">world</span></h1>
<p>
There were <b>21.6 million</b> total melodies entered in the dataset,
from <b>109</b> different countries, with the
<a class="accent" href="country.html?country=us" target="_blank">United States</a>,
<a class="accent" href="country.html?country=br" target="_blank">Brazil</a>,
<a class="accent" href="country.html?country=mx" target="_blank">Mexico</a>,
<a class="accent" href="country.html?country=it" target="_blank">Italy</a>, and
<a class="accent" href="country.html?country=es" target="_blank">Spain</a>, ranking in the <b>top 5</b>. Countries that had a small number of
compositions were all grouped together in a separate category, to minimize
the possibility of identifying users.
</p>
<p>Explore how the top
<b>2000</b> most repeated compositions change around the world (or in 80 countries, to
be more exact)-- the size of each
circle represents the size of the total number of melodies entered
in that country.
</p>
</section>
<div class="center" id="container">
<!-- I designed the circles sizes for a 900x900 svg centered on the page. -->
<svg id="svg" viewBox="-450 -450 900 900">
<g class="base" transform="translate(0,0)"></g>
</svg>
</div>
</body>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="common.js"></script>
<script>
let trivia;
const countriesBySize = Object.keys(totalPerCountry);
window.addEventListener('resize', showData);
d3.json('data/trivia_per_country.json').then((json) => {
trivia = json;
showData();
});
function showData() {
document.querySelector('.base').innerHTML = '';
const svg = d3.select('#svg');
if (window.innerWidth < 900) {
// Make the svg a bit tighter in small places.
svg.attr('viewBox', '-400 -400 800 800');
}
const circles = generateCircles();
// Add the country image to the circle.
svg
.select('g')
.selectAll('circle')
.data(circles)
.enter()
.append('circle')
.attr('cx', (d) => d.x)
.attr('cy', (d) => d.y)
.attr('fill', 'transparent')
.attr('r', (d) => d.r - 4) // add a 4px margin outside
const containerRekt = container.getBoundingClientRect();
const els = document.querySelectorAll('circle');
const links = document.querySelectorAll('#container a');
const overlays = document.querySelectorAll('#container a .overlay');
for (let i = 0; i < els.length; i++) {
// If we're resizing we've already created a bunch of images.
let a, overlay;
if (links.length === 0) {
a = document.createElement('a');
const img = document.createElement('img');
overlay = document.createElement('div');
a.classList.add('blob');
overlay.classList.add('overlay');
const country = countriesBySize[i];
img.src = `./blobs/${country}.jpg`;
img.alt = `image preview of the visualization for ${country}`;
a.href = `./country.html?country=${country}`;
a.setAttribute('aria-label', `click to explore ${availableCountriesNames[country]}`);
a.target = '_blank';
const t = trivia[country];
a.title = d3.format(".2s")(totalPerCountry[country]) +
' sequences were entered in total in ' + availableCountriesNames[country] + '.\n' +
`${(t.major/2000 * 100).toFixed(1)}% were in a major scale, ` +
`${(t.minor/2000 * 100).toFixed(1)}% in a minor, ` +
`${(t.neither/2000 * 100).toFixed(1)}% were neither. \n` +
t.unseen + ' of these compositions were not in the top 2000 in any other country.'
;
overlay.textContent = country.toUpperCase();
a.appendChild(img);
a.appendChild(overlay);
container.appendChild(a);
} else {
a = links[i];
overlay = overlays[i];
}
const rekt = els[i].getBoundingClientRect();
a.style.left = rekt.left - containerRekt.left + 'px';
a.style.top = rekt.top - containerRekt.top + 'px';
a.style.width = a.style.height = rekt.width + 'px';
const fontSize = Math.max(16, rekt.width - 40);
overlay.style.fontSize = Math.min(180, fontSize) + 'px';
overlay.style.lineHeight = 0;
}
}
function generateCircles() {
const sizeScale = d3.scaleSqrt()
.domain([totalPerCountry['ph'], totalPerCountry['us']])
.range([14, 120]); // Made up.
// Make a circle of the right size, and pack it.
return d3.packSiblings(
d3.range(countriesBySize.length)
.map((d,i) => {
const country = countriesBySize[i];
return {
r: sizeScale(totalPerCountry[country]),
country: country
}
})
);
}
</script>
</html>