forked from Lyricsis/Lyricsis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnations.html
More file actions
386 lines (318 loc) · 10.5 KB
/
nations.html
File metadata and controls
386 lines (318 loc) · 10.5 KB
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>아이돌 멤버의 곡 제작 참여율</title>
<meta name="description" content="Drag & Drop World Countries (if you can)">
<link href="dragit.css" rel="stylesheet"/>
<script src="d3.v3.js"></script>
<script src="dragit.js"></script>
</head>
<title>아이돌 멤버의 곡 제작 참여율</title>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
margin-left:40px;
font-weight: 200;
font-size: 14px;
}
html,body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
text {
cursor: default;
}
h1 {
font-weight: 400;
}
#chart4 {
height: 506px;
}
text {
font-size: 12px;
}
.dot {
stroke: #000;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.label {
fill: #777;
}
.year.label {
font: 500 100px "NanumSquare";
fill: #ddd;
}
.country.label {
font: 500 96px "NanumSquare";
fill: #ddd;
}
.year.label.active {
fill: #aaa;
}
circle.pointTrajectory {
pointer-events: none;
stroke: lightgray;
fill: black;
opacity: 0;
}
path.lineTrajectory {
stroke-width: 2;
stroke-opacity: .5;
stroke: black;
fill: none;
pointer-events: none;
}
.selected {
stroke-width: 4;
}
</style>
<h1>아이돌 멤버의 곡 제작 참여율</h1>
<i>해당 년도로 이동하여 여남 아이돌의 참여율 차이를 확인해보세요.</i></p>
<div id="chart4" style="margin:0px"></div>
<span id="min-time">1992</span>
<input type="range" name="points" min="0" max="26" step="1" value="0" id="slider-time" style="width:900px">
<span id="max-time">2018</span>
<br>
<p>
<!-- Original creation by <a href="http://www.gapminder.org/world/">Gapminder</a> using <a href="https://github.com/RandomEtc/mind-gapper-js">Tom Carden</a> JavaScript version.<br>
Recreation by <a href="http://bost.ocks.org/mike/nations/">Mike Bostock</a> with <a href="http://d3js.org/">D3.js</a>.<br>
Re-Recreation using <a href="http://romsson.github.io/dragit/">dragit.js</a> by <a href="http://romain.vuillemot.net/">Romain Vuillemot</a> (view <a href="https://github.com/romsson/dragit/blob/master/example/nations.html">source</a> on GitHub). -->
동그라미의 크기는 그 해 활동한 아이돌 그룹 수를 의미합니다.
<!-- Place this tag in your head or just before your close body tag. -->
<!-- <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> -->
<br>
<script>
// Various accessors that specify the four dimensions of data to visualize.
function x(d) { return d.lyricist; }
function y(d) { return d.composer; }
function radius(d) { return d.group_number; }
function colors(d) { return d.region; }
function key(d) { return d.name; }
// Chart dimensions.
var margin = {top: 19.5, right: 19.5, bottom: 19.5, left: 39.5},
c4_width = 960 - margin.right,
c4_height = 500 - margin.top - margin.bottom;
// Various scales. These domains make assumptions of data, naturally.
var xScale = d3.scale.linear().domain([0, 350]).range([0, c4_width]),
yScale = d3.scale.linear().domain([0, 200]).range([c4_height, 0]),
radiusScale = d3.scale.sqrt().domain([0, 70]).range([0, 30]),
// colorScale = d3.scale.category10()
colorScale = d3.scale.linear()
.domain([1, 2])
.range(['#7A37F5', '#20C2AA']);
/// The x & y axes.
var xAxis = d3.svg.axis().orient("bottom").scale(xScale),
yAxis = d3.svg.axis().scale(yScale).orient("left");
// Create the SVG container and set the origin.
var svgs = d3.select("#chart4").append("svg")
.attr("width", c4_width + margin.left + margin.right)
.attr("height", c4_height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.attr("class", "gRoot")
// Add the x-axis.
svgs.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + c4_height + ")")
.call(xAxis);
// Add the y-axis.
svgs.append("g")
.attr("class", "y axis")
.call(yAxis);
// Add an x-axis label.
svgs.append("text")
.attr("class", "x label")
.attr("text-anchor", "end")
.attr("x", c4_width)
.attr("y", c4_height - 6)
.text("멤버가 작사한 곡 수");
// Add a y-axis label.
svgs.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("y", 6)
.attr("dy", ".75em")
.attr("transform", "rotate(-90)")
.text("멤버가 작곡한 곡 수");
// Add the year label; the value is set on transition.
var label = svgs.append("text")
.attr("class", "year label")
.attr("text-anchor", "end")
.attr("y", c4_height - 24)
.attr("x", c4_width)
.text(1992);
// Add the country label; the value is set on transition.
var countrylabel = svgs.append("text")
.attr("class", "country label")
.attr("text-anchor", "start")
.attr("y", 80)
.attr("x", 20)
.text(" ");
var first_time = true;
// Load the data.
d3.json("data/nations.json", function(nations) {
// A bisector since many nation's data is sparsely-defined.
var bisect = d3.bisector(function(d) { return d[0]; });
// Add a dot per nation. Initialize the data at 1993, and set the colors.
var dot = svgs.append("g")
.attr("class", "dots")
.selectAll(".dot")
.data(interpolateData(1992))
.enter().append("circle")
.attr("class", "dot")
// .style("fill", function(d) { return colorScale(color(d)); })
.style("fill", function(d) { return colorScale(colors(d)); })
.style("stroke-opacity", "0")
.call(position)
.on("mousedow", function(d, i) {
})
.on("mouseup", function(d, i) {
dot.classed("selected", false);
d3.select(this).classed("selected", !d3.select(this).classed("selected"));
dragit.trajectory.display(d, i, "selected");
//TODO: test if has been dragged
// Look at the state machine history and find a drag event in it?
})
.on("mouseenter", function(d, i) {
clear_demo();
if(dragit.statemachine.current_state == "idle") {
dragit.trajectory.display(d, i)
dragit.utils.animateTrajectory(dragit.trajectory.display(d, i), dragit.time.current, 1000)
countrylabel.text(d.name);
dot.style("opacity", .4)
d3.select(this).style("opacity", 1)
d3.selectAll(".selected").style("opacity", 1)
}
})
.on("mouseleave", function(d, i) {
if(dragit.statemachine.current_state == "idle") {
countrylabel.text("");
dot.style("opacity", 1);
}
dragit.trajectory.remove(d, i);
})
.call(dragit.object.activate)
// Add a title.
dot.append("title")
.text(function(d) { return d.name; });
// Start a transition that interpolates the data based on year.
svgs.transition()
.duration(30000)
.ease("linear")
// Positions the dots based on data.
function position(dot) {
dot.attr("cx", function(d) { return xScale(x(d)); })
.attr("cy", function(d) { return yScale(y(d)); })
.attr("r", function(d) { return radiusScale(radius(d)); });
}
// Defines a sort order so that the smallest dots are drawn on top.
function order(a, b) {
return radius(b) - radius(a);
}
// Updates the display to show the specified year.
function displayYear(year) {
dot.data(interpolateData(year+dragit.time.min), key).call(position).sort(order);
label.text(dragit.time.min + Math.round(year));
}
// Interpolates the dataset for the given (fractional) year.
function interpolateData(year) {
return nations.map(function(d) {
return {
name: d.name,
region: d.region,
lyricist: interpolateValues(d.lyricist, year),
group_number: interpolateValues(d.group_number, year),
composer: interpolateValues(d.composer, year)
};
});
}
// Finds (and possibly interpolates) the value for the specified year.
function interpolateValues(values, year) {
var i = bisect.left(values, year, 0, values.length - 1),
a = values[i];
if (i > 0) {
var b = values[i - 1],
t = (year - a[0]) / (b[0] - a[0]);
return a[1] * (1 - t) + b[1] * t;
}
return a[1];
}
init();
function update(v, duration) {
dragit.time.current = v || dragit.time.current;
displayYear(dragit.time.current)
d3.select("#slider-time").property("value", dragit.time.current);
}
function init() {
dragit.init(".gRoot");
dragit.time = {min:1992, max:2019, step:1, current:1992}
dragit.data = d3.range(nations.length).map(function() { return Array(); })
for(var yy = 1992; yy<2019; yy++) {
interpolateData(yy).filter(function(d, i) {
dragit.data[i][yy-dragit.time.min] = [xScale(x(d)), yScale(y(d))];
})
}
dragit.evt.register("update", update);
//d3.select("#slider-time").property("value", dragit.time.current);
d3.select("#slider-time")
.on("mousemove", function() {
update(parseInt(this.value), 500);
clear_demo();
})
var end_effect = function() {
countrylabel.text("");
dot.style("opacity", 1)
}
dragit.evt.register("dragend", end_effect)
}
function clear_demo() {
if(first_time) {
svgs.transition().duration(0);
first_time = false;
window.clearInterval(demo_interval);
countrylabel.text("");
dragit.trajectory.removeAll();
d3.selectAll(".dot").style("opacity", 1)
}
}
function play_demo() {
var ex_nations = ["China", "India", "Indonesia", "Italy", "France", "Spain", "Germany", "United States"]
var index_random_nation = null;
var random_index = Math.floor(Math.random() * ex_nations.length);
var random_nation = nations.filter(function(d, i) {
if(d.name == ex_nations[random_index]) {
index_random_nation = i;
return true;
}
})[0];
var random_nation = nations[index_random_nation];
dragit.trajectory.removeAll();
dragit.trajectory.display(random_nation, index_random_nation);
countrylabel.text(random_nation.name);
dragit.utils.animateTrajectory(dragit.lineTrajectory, dragit.time.min, 2000)
d3.selectAll(".dot").style("opacity", .4)
d3.selectAll(".dot").filter(function(d) {
return d.name == random_nation.name;
}).style("opacity", 1)
}
var demo_interval = null;
setTimeout(function() {
if(first_time) {
play_demo()
demo_interval = setInterval(play_demo, 3000)
}
}, 1000);
});
</script>
<script type="text/javascript" src="https://apis.google.com/js/platform.js"></script>
</body>
</html>