-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
440 lines (384 loc) · 14.6 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
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"></script>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://rawgit.com/susielu/d3-annotation/master/d3-annotation.min.js"></script>
<link rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="styles/newspaper.css">
<title>My Title</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
<div class="head">
<div class="subhead">Friday July 29, 2022</div>
<div class="collumn">
<span class="headline hl1">
<br>
How many martinis have appeared in 007 history?
</span>
<p>
<span class="headline hl2">
Visualization of Statistics <br>
in the James Bond Movie Series
</span>
</p>
<figure class="figure">
<img class="media" src="giphy.gif" alt="">
<figcaption class="figcaption">
"Dry martini. Wait, 3 measures of gordons, 1 of vodka, half a measure
of kina lillet, shake it over ice. Then add a thin slice of lemon peel." <br>
- Recipe of the Vesper Martini in Casino Royale (2006)
</figcaption>
</figure>
<p>
Dry martini, or vodka martini has been symbolic drink of James Bond movies, also known as 007.
In lots of 007 movies, James Bond ordered the martini in his own way.
</p>
<span class="citation">
"Martini. <br>
Shaken, not stirred."
</span>
<p>
Will there be martinis in every movie of 007 series?
As 007 movie has long history, we need to check all of them to answer that question.
</p>
</div>
<div>
<text class="figtitle">[Fig. 1] The number of martinis in the 007 movie series</text>
<div class="martini_graph" style="text-align:center;"></div>
</div>
<div class="collumn">
<p>
Martini is most frequently appeared in Quantum of Solace (2008).
That is because the martini plays important role in its story line.
In Casino Royale (2006), James Bond named a recipe of martini as 'Vesper', which is also described in Ian Fleming’s original novel.
That becomes an item to represent Bond's feeling in the following movie.
What about other statistics? Let's drill down into others.
</p>
</div>
<div>
<text class="figtitle">[Fig. 2] Visualization of the 007 movie series with various statistics :</text>
<select id = "combo">
<option onclick="update('Kills_Bond')">Killed by Bond</button>
<option onclick="update('Kills_Others')">Killed by Others</button>
<option onclick="update('Budget')">Budget (Thousand USD)</button>
<option onclick="update('Film_Length')">Film Length (min)</button>
<option onclick="update('Avg_User_IMDB')">IMDB User Rating</button>
<option onclick="update('Avg_User_Rtn_Tom')">Rotten Tomato User Rating</button>
<option onclick="update('Martinis')">Martinis</button>
</select>
</div>
<div class="all_graphs" style="text-align:center;">
</div>
</div>
</body>
<script>
console.log("Hello!")
// set the dimensions and margins of the graph
var margin = { top: 30, right: 30, bottom: 200, left: 60 },
width = 700 - margin.left - margin.right,
height = 600 - margin.top - margin.bottom;
var original_color = "gray"
var highlight_color = "orange"
var bar_duration = 300
// append the svg object to the body of the page
var svg = d3.select(".martini_graph")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
function dataX(d) {
return d.Movie + " (" + d.Year + ")"
}
// Parse the Data
d3.csv("https://raw.githubusercontent.com/SewoongLee/SewoongLee.github.io/v0.0.4/jamesbond.csv", function (data) {
function dataY(d) {
return d.Martinis
}
// X axis
var xScale = d3.scaleBand()
.range([0, width])
.domain(data.map(function (d) { return dataX(d); }))
.padding(0.2);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.transition().duration(1000).call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
// Add Y axis
var yScale = d3.scaleLinear()
.domain([0, d3.max(data, function (d) { return dataY(d) })])
.range([height, 0]);
const yAxisTicks = yScale.ticks()
.filter(tick => Number.isInteger(tick));
svg.append("g")
.transition()
.duration(1000)
.call(d3.axisLeft(yScale).tickValues(yAxisTicks).tickFormat(d3.format('d')));
// Bars
svg.selectAll("mybar")
.data(data)
.enter()
.append("rect")
.on("mouseover", onMouseOver)
.on("mouseout", onMouseOut)
.transition()
.duration(bar_duration)
.attr("x", function (d) { return xScale(dataX(d)); })
.attr("y", function (d) { return yScale(dataY(d)); })
.attr("width", xScale.bandwidth())
.attr("height", function (d) { return height - yScale(dataY(d)); })
.attr("fill", original_color)
svg.append("g").attr("class", "val");
svg.select(".val")
.selectAll("text")
.data(data)
.enter()
.append("text")
.attr("x", function (d, i) {
return xScale(dataX(d)) + xScale.bandwidth() / 2;
})
.attr("y", (d) => yScale(dataY(d)) - 3)
.text(function (d) {
num = dataY(d)
if (num == 1)
return "Once";
else if (num == 2)
return "Twice";
else
return num + " times";
})
.attr("font-family", "sans-serif")
.attr("font-size", "10px")
.attr("fill", "black")
.attr("text-anchor", "middle")
.attr("display", "none");
})
function onMouseOut(d, i) {
d3.select(this)
// .transition()
// .duration(400)
.style("fill", original_color);
d3.select('.val')
.selectAll("text").filter((d, index) => index === i)
.attr("display", "none");
}
function onMouseOver(d, i) {
d3.select(this)
// .transition()
// .duration(400)
.style("fill", highlight_color);
d3.select('.val')
.selectAll("text").filter(function (d, index) {
return index === i;
})
.attr("display", "block");
}
// Features of the annotation
const qos_ann = [
{
note: {
label: "Martini is most frequently used to represent Bond's feeling",
title: "Recalling of the Vesper Martini"
},
x: 595,
y: 31,
dy: 20,
dx: -100,
connector: { end: "arrow" },
}
]
const cr_ann = [
{
note: {
label: "The Vesper Martini was named after Bond girl whose name is Vesper.",
title: "Invention of the Vesper Martini"
},
x: 570,
y: 216,
dy: -60,
dx: -250,
connector: { end: "arrow" },
}
]
// Add annotation to the chart
const makeQosAnn = d3.annotation()
.annotations(qos_ann)
d3.select(".martini_graph")
.select("svg")
.append("g")
.call(makeQosAnn)
const makeCrAnn = d3.annotation()
.annotations(cr_ann)
d3.select(".martini_graph")
.select("svg")
.append("g")
.call(makeCrAnn)
////////////////////////////////////////////////////////
// ALL GRAPHS //
////////////////////////////////////////////////////////
function dataSelect(d, selectedVar) {
if (selectedVar == "Budget")
return d.Budget;
if (selectedVar == "Film_Length")
return d.Film_Length;
if (selectedVar == "Avg_User_IMDB")
return d.Avg_User_IMDB;
if (selectedVar == "Avg_User_Rtn_Tom")
return d.Avg_User_Rtn_Tom;
if (selectedVar == "Martinis")
return d.Martinis;
if (selectedVar == "Kills_Bond")
return d.Kills_Bond;
if (selectedVar == "Kills_Others")
return d.Kills_Others;
if (selectedVar == "Video_Game")
return d.Video_Game;
}
// append the svg object to the body of the page
var svg_all = d3.select(".all_graphs")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Initialize the X axis
var xScaleAll = d3.scaleBand()
.range([0, width])
.padding(0.2);
var xAxisAll = svg_all.append("g")
.attr("transform", "translate(0," + height + ")")
// Initialize the Y axis
var yScaleAll = d3.scaleLinear()
.range([height, 0]);
var yAxisAll = svg_all.append("g")
.attr("class", "myYaxis")
var currSelect
// A function that create / update the plot for a given variable:
function update(selectedVar) {
currSelect = selectedVar
if(selectedVar == "Martinis")
{
d3.selectAll(".anno").attr("display", "block")
}
else
{
d3.selectAll(".anno").attr("display", "none")
}
// Parse the Data
d3.csv("https://raw.githubusercontent.com/SewoongLee/SewoongLee.github.io/v0.0.4/jamesbond.csv", function (data) {
// X axis
xScaleAll.domain(data.map(function (d) { return dataX(d); }))
xAxisAll.transition().duration(1000).call(d3.axisBottom(xScaleAll))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
// Add Y axis
var ymax = d3.max(data, function (d) {
var val = parseFloat(dataSelect(d, selectedVar));
return val;
})
var ymin = d3.min(data, function (d) {
var val = parseFloat(dataSelect(d, selectedVar));
return val;
})
yScaleAll.domain([0, ymax]);
yAxisAll.transition().duration(1000).call(d3.axisLeft(yScaleAll));
// variable u: map data to existing bars
var u = svg_all.selectAll("rect")
.data(data)
// update bars
u
.enter()
.append("rect")
.on("mouseover", onMouseOverAll)
.on("mouseout", onMouseOutAll)
.merge(u)
.transition()
.duration(bar_duration)
.attr("x", function (d) { return xScaleAll(dataX(d)); })
.attr("y", function (d) { return yScaleAll(dataSelect(d, selectedVar)); })
.attr("width", xScaleAll.bandwidth())
.attr("height", function (d) { return height - yScaleAll(dataSelect(d, selectedVar)); })
.attr("fill", original_color)
svg_all.append("g").attr("class", "valAll");
svg_all.select(".valAll")
.selectAll("text")
.data(data)
.enter()
.append("text")
.attr("x", function (d, i) {
var x = xScaleAll(dataX(d)) + xScaleAll.bandwidth() / 2
return x;
})
.attr("y", function (d) {
var y = yScaleAll(dataSelect(d, selectedVar)) - 3;
return y;
})
.text(function (d) {
var t = dataSelect(d, selectedVar)
return t;
})
.attr("font-family", "sans-serif")
.attr("font-size", "10px")
.attr("fill", "black")
.attr("text-anchor", "middle")
.attr("display", "none");
})
}
function onMouseOutAll(d, i) {
d3.select(this)
// .transition()
// .duration(100)
.style("fill", original_color);
d3.select('.valAll')
.selectAll("text").filter((d, index) => index === i)
.attr("display", "none");
}
function onMouseOverAll(d, i) {
d3.select(this)
// .transition()
// .duration(100)
.style("fill", highlight_color);
d3.select('.valAll')
.selectAll("text").filter(function (d, index) {
return index === i;
})
.attr("x", function (d, i) {
var x = xScaleAll(dataX(d)) + xScaleAll.bandwidth() / 2
return x;
})
.attr("y", function (d) {
var y = yScaleAll(dataSelect(d, currSelect)) - 3;
return y;
})
.text(function (d) {
var t = dataSelect(d, currSelect)
return t;
})
.attr("display", "block");
}
// Add annotation to the chart
const makeQosAnn2 = d3.annotation()
.annotations(qos_ann)
d3.select(".all_graphs")
.select("svg")
.append("g")
.attr("class", "anno")
.call(makeQosAnn2)
const makeCrAnn2 = d3.annotation()
.annotations(cr_ann)
d3.select(".all_graphs")
.select("svg")
.append("g")
.attr("class", "anno")
.call(makeCrAnn2)
// Initialize plot
update('Kills_Bond')
</script>
</html>