-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
535 lines (431 loc) · 19.4 KB
/
index.html
File metadata and controls
535 lines (431 loc) · 19.4 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
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="style.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div class="container">
<h1 >Hollywood Movie Budgets</h1>
<h4> <i>A visualization of data for every Hollywood and major US film from 2007-2011 <br>by Lisa Nuccitelli, Alisha Sojar, and Ryan Dong</i></h4>
<p class="description"> <i> Use the filters below to explore relationships between movie budget, genre, Rotten Tomatoes rating, and profitabilty, or % of budget recovered (profitability is represented by circle size). Click on a movie to see the gross profit breakdown in the pie charts below.</i></p>
<div>
<!-- <p class="subtitle">Dollars spent, Rating, Profitibility, </p> -->
<div id="scatterplot"><div class="error">There are no movies that fit these ranges.</div></div>
<div id="piecharts">
<h4 id="pieheader">Select a movie to see profit details</h4>
<div id = "piechart1"></div>
<div id = "piechart2"></div>
</div>
</div>
<div class="filter">
<div class="choose">
<p>
<label for="budget">Budget range:</label>
<input class="text-label" type="text" id="budget" readonly>
</p>
<div class="slider" id="budget-range"></div>
<p>
<label for="profit">Profitability:</label>
<input class="text-label" type="text" id="profit" readonly >
</p>
<div class="slider" id="profit-range"></div>
<p>
<label for="rating">Rating range:</label>
<input class="text-label" type="text" id="rating" readonly >
</p>
<div class="slider" id="rating-range"></div>
</div>
<div class="choose">
<p class="checkbox-list">
<label for="rating">Genre</label><br>
<input checked type="checkbox" name="genre" value="Action" ><span class="circle">● </span>Action <br>
<input checked type="checkbox" name="genre" value="Animation" ><span class="circle">● </span>Animation <br>
<input checked type="checkbox" name="genre" value="Comedy" ><span class="circle">● </span>Comedy <br>
<input checked type="checkbox" name="genre" value="Drama" ><span class="circle">● </span>Drama <br>
</p>
<p class="checkbox-list">
<label style="display:none" for="rating">Year</label><br>
<input checked type="checkbox" name="genre" value="Fantasy" ><span class="circle">● </span>Fantasy <br>
<input checked type="checkbox" name="genre" value="Horror" ><span class="circle">● </span>Horror <br>
<input checked type="checkbox" name="genre" value="Romance" ><span class="circle">● </span>Romance <br>
<input checked type="checkbox" name="genre" value="Thriller" ><span class="circle">● </span>Thriller<br>
</p>
<p class="checkbox-list years">
<label for="year">Year</label><br>
<input type="checkbox" name="year" value="2007" >2007<br>
<input type="checkbox" name="year" value="2008" >2008<br>
<input type="checkbox" name="year" value="2009" >2009<br>
<input type="checkbox" name="year" value="2010" >2010<br>
<input checked type="checkbox" name="year" value="2011" >2011<br>
</p>
</div>
</div>
</div>
</body>
</html>
<!-- SLIDERS -->
<script>
var budget_vals=[0,300];
var profit_vals=[0,6700];
var rating_vals=[0,100];
var years=[2011];
var genres = ["Action", "Animation", "Comedy", "Drama", "Fantasy", "Horror", "Romance", "Thriller"];
function makeSlider(slider_div, text_div, values, max, unit){
$(slider_div).slider({
range: true,
min: 0,
max: max,
values: values,
slide: function( event, ui ) {
$( text_div ).val( "" + ui.values[ 0 ] + unit+ " - " + ui.values[ 1 ] + unit);
budget_vals=[ui.values[0], ui.values[1]]
},
stop: function( event, ui){
updateGraph();
}
});
$( text_div).val( "" + $( slider_div ).slider( "values", 0 ) + unit+
" - " + $( slider_div ).slider( "values", 1 )+ unit );
}
makeSlider("#budget-range", "#budget",budget_vals, 305, 'M');
makeSlider("#profit-range", "#profit",profit_vals, 6700, '%');
makeSlider("#rating-range", "#rating",rating_vals, 100, '%');
//set up margins
var margin = {top: 20, right: 20, bottom: 50, left: 60},
width = 750 - margin.left - margin.right,
height = 550 - margin.top - margin.bottom;
var margin2 = {top: 20, right: 250, bottom: 20, left: 20},
width2 = 200 - margin2.left - margin2.right/4,
height2 = 200 - margin2.top - margin2.bottom;
var radius = Math.min(width2, height2) / 2;
// setup svgs
var svg = d3.select("#scatterplot").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 + ")");
var svg2 = d3.select("#piechart1").append("svg")
.attr("width", width2 + margin2.left + margin2.right)
.attr("height", height2 + margin2.top + margin2.bottom)
.append("g")
.attr('transform', 'translate(' + ((width2 + margin2.right/2 + margin2.left) / 2) +
',' + ((height2 + margin2.top + margin2.bottom) / 2) + ')');
var svg3 = d3.select("#piechart2").append("svg")
.attr("width", width2 + margin2.left + margin2.right)
.attr("height", height2 + margin2.top + margin2.bottom)
.append("g")
.attr('transform', 'translate(' + ((width2 + margin2.right/2 + margin2.left) / 2) +
',' + ((height2 + margin2.top + margin2.bottom) / 2) + ')');
var arc = d3.svg.arc().outerRadius(radius);
function arcTween(a) {
var i = d3.interpolate(this._current, a);
this._current = i(0);
return function(t) {
return arc(i(t));
};
}
// setup x scale and axis
var xScale = d3.scale.linear().range([0, width]),
xAxis = d3.svg.axis().scale(xScale).orient("bottom");
// setup y scale and axis
var yScale = d3.scale.linear().range([height, 0]),
yAxis = d3.svg.axis().scale(yScale).orient("left");
// setup fill color
//var color = d3.scale.category20();
var color = d3.scale.ordinal()
.range(["#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e",
"#e6ab02", "#a6761d", "#666666"]);
//set legend colors
var i=0;
$( ".circle" ).each(function() {
$( this ).css( 'color',color(genres[i]));
i++
});
// add the tooltip area to the webpage
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0)
// x-axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", (width)/2)
.attr("y", 40)
.style("text-anchor", "middle")
.text("Budget (Millions)");
// y-axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("x",-40)
.attr("y", (height)/2)
.attr("transform", "rotate(-90, -40," + (height/2) +" )")
.style("text-anchor", "middle")
.text("Rotten Tomatoes Rating (%)");
// Gross Profit label
svg2.append("g")
.append("text")
.attr("class", "label")
.attr("y", -(height2/2) - 5)
.style("text-anchor", "middle")
.text("Gross Profit");
var piechart1 = ["Foreign", "Domestic"]
var legend1 = svg2.selectAll(".legend")
.data(piechart1)
.enter().append("g")
.attr("transform", function(d, i) { return "translate(100," + (i * -30) + ")"; });
legend1.append("rect")
.attr("width", 18)
.attr("height", 18)
.style("fill", function(d) {return color(d);});
legend1.append("text")
.attr("x", 24)
.attr("y", 9)
.attr("font-size", "10")
.style("text-anchor", "beginning")
.style("word-wrap", "break-word")
.text(function(d) { return d; });
// Opening Weekend label
svg3.append("g")
.append("text")
.attr("class", "label")
.attr("y", -(height2/2) - 5)
.style("text-anchor", "middle")
.text("Opening Weekend Profit");
var piechart2 = ["Post Opening Weekend", "Opening Weekend"]
var legend2 = svg3.selectAll(".legend")
.data(piechart2)
.enter().append("g")
.attr("transform", function(d, i) { return "translate(100," + (i * -30) + ")"; });
legend2.append("rect")
.attr("width", 18)
.attr("height", 18)
.style("fill", function(d) {return color(d);});
legend2.append("text")
.attr("x", 24)
.attr("y", 9)
.attr("font-size", "10")
.style("text-anchor", "beginning")
.text(function(d) { return d; });
//initialized pie charts
var dataset1 = [
{ label: 'Domestic', num: 100 },
{ label: 'Foreign', num: 0 },
];
var dataset2 = [
{ label: 'Opening Weekend', num: 100 },
{ label: 'Post Opening Weekend', num: 0 },
];
var pie = d3.layout.pie()
.value(function(k) {
return k.num;
})
.sort(null);
var path1 = svg2.selectAll('path')
.data(pie(dataset1));
path1.enter()
.append('path')
.attr('d', arc)
.each(function(d) { this._current = d; })
.attr('fill', function(d, i) {
return color(d.data.label);
})
.attr('opacity', function(d, i) {
return .7;
});
var path2 = svg3.selectAll('path')
.data(pie(dataset2));
path2.enter()
.append('path')
.attr('d', arc)
.each(function(d) { this._current = d; })
.attr('fill', function(d, i) {
return color(d.data.label);
}).attr('opacity', function(d, i) {
return .7;
});
updateGraph();
$("input:checkbox").change(function() {
console.log("checkbox called")
updateGraph();
});
//filter data based on inputs and update graph
function updateGraph(){
$('.error').hide(0);
//get updated values from sliders and checkboxes
var budget_vals = $( "#budget-range" ).slider( "values" );
var profit_vals = $( "#profit-range" ).slider( "values" );
var rating_vals = $( "#rating-range" ).slider( "values" );
var genres = $('input[name="genre"]:checkbox:checked').map(function() {
return this.value;
}).get();
var years = $('input[name="year"]:checkbox:checked').map(function() {
return this.value;
}).get();
//update graph
d3.csv("movieData.csv",
function(d) {
//define data fields
return {
title: d.Film,
year: d.Year,
rating: +d.Rotten_Tomatoes,
genre: d.Genre,
budget: +d.Budget,
profitability: +d.Profitability,
domestic: +(d.Domestic_Gross.replace(',', '')),
foreign: +(d.Foreign_Gross.replace(',', '')),
world: +(d.Worldwide_Gross.replace(',', '')),
opening: +d.Opening_Weekend
};
},
function(error, data) {
//filter data
var newdata = data.filter(function(d){
if (d.budget > budget_vals[0] && d.budget < budget_vals[1]
&& d.rating > rating_vals[0] && d.rating < rating_vals[1]
&& d.profitability > profit_vals[0] && d.profitability < profit_vals[1] && genres.indexOf(d.genre)!=-1 && years.indexOf(d.year)!=-1 ) {
return d;
}
})
if (newdata.length==0){$('.error').fadeIn(1000);}
// don't want dots overlapping axis, so add in buffer to data domain
xScale.domain([d3.min(newdata, function(d) {return d.budget}), d3.max(newdata, function(d) { return d.budget})]);
yScale.domain([d3.min(newdata, function(d) {return d.rating}), d3.max(newdata, function(d) {return d.rating})]);
// Update X Axis
svg.select(".x.axis")
.transition()
.duration(1000)
.call(xAxis);
// Update X Axis
svg.select(".y.axis")
.transition()
.duration(1000)
.call(yAxis);
//sort data so small bubbles on top
newdata.sort(function (a, b) {
if (a.profitability < b.profitability) {
return 1;
}
if (a.profitability > b.profitability) {
return -1;
}
// a must be equal to b
return 0;
});
//Update all circles
var circles = svg.selectAll("circle")
.data(newdata);
circles.transition()
.duration(1000)
.attr("r", function(d) {return Math.pow(d.profitability,0.5)/2;})
.attr("cx", function(d) {
return xScale(d.budget);
})
.attr("cy", function(d) {
return yScale(d.rating);
});
circles.style("fill", function(d) { return color(d.genre);})
.style("stroke", function(d) { return color(d.genre);})
.on("mouseover", function(d) {
d3.select(this).style("fill-opacity" ,1);
tooltip.transition()
.duration(500)
.style("opacity", .9);
tooltip.html("<div><div class='title'><strong>"+d.title+"</strong></div><div class='genre'>Genre:<span class='label'> "+d.genre+"</span></div><div class='year'>Year:<span class='label'> "+d.year+"</span></div><div class='rating'>Rating: <span class='label'>"+d.rating+"% </span></div><div class='budget'>Budget: <span class='label'>$"+d.budget+"M</div><div class='profit'>Profitibility: <span class='label'> "+d.profitability+"%</span></div></div>")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
d3.select(this).style("fill-opacity" ,0.7);
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
//Enter new circles
circles.enter().append("circle")
.attr("class", "dot")
.attr("r", function(d) {return Math.pow(d.profitability,.5)/2;})
.attr("cx", function(d) {return xScale(d.budget)})
.attr("cy", function(d) {return yScale(d.rating)})
.style("fill", function(d) { return color(d.genre);})
.style("stroke", function(d) { return color(d.genre);})
.on("mouseover", function(d) {
d3.select(this).style("fill-opacity" ,1);
tooltip.transition()
.duration(500)
.style("opacity", .9);
tooltip.html("<div><div class='title'><strong>"+d.title+"</strong></div><div class='genre'>Genre:<span class='label'> "+d.genre+"</span></div><div class='year'>Year:<span class='label'> "+d.year+"</span></div><div class='rating'>Rating: <span class='label'>"+d.rating+"% </span></div><div class='budget'>Budget: <span class='label'>$"+d.budget+"M</div><div class='profit'>Profitibility: <span class='label'> "+d.profitability+"%</span></div></div>")
.style("left", (d3.event.pageX + 5) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
d3.select(this).style("fill-opacity" ,0.7);
tooltip.transition()
.duration(500)
.style("opacity", 0);
})
.on("click", function(d) {
//update pie charts
document.getElementById("pieheader").innerHTML = d.title;
var dataset1 = [
{ label: 'Domestic', num: d.domestic },
{ label: 'Foreign', num: d.foreign },
];
var dataset2 = [
{ label: 'Opening Weekend', num: d.opening },
{ label: 'Post Opening Weekend', num: (d.world - d.opening) },
];
var pie = d3.layout.pie()
.value(function(k) {
return k.num;
})
.sort(null);
var path1 = svg2.selectAll('path')
.data(pie(dataset1));
path1.transition().duration(1000).attrTween("d", arcTween);
path1.enter()
.append('path')
.attr('d', arc)
.each(function(d) { this._current = d; })
.attr('fill', function(d, i) {
return color(d.data.label);
});
// .append("g")
// .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
// .append("text")
// .style("fill", "Black")
// .attr("text-anchor", "middle")
// .text("Hi");
// path1.append("g")
// .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
// .append("svg:text")
// //.style("fill", "White")
// //.attr("text-anchor", "middle")
// .text(function(d) { return "Hi"; });
var path2 = svg3.selectAll('path')
.data(pie(dataset2));
path2.transition().duration(1000).attrTween("d", arcTween);
path2.enter()
.append('path')
.attr('d', arc)
.each(function(d) { this._current = d; })
.attr('fill', function(d, i) {
return color(d.data.label);
});
});
// Remove old
circles.exit().remove();
});
}
</script>