forked from cs4804-24c/final
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
560 lines (479 loc) · 23 KB
/
index.html
File metadata and controls
560 lines (479 loc) · 23 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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<html>
<head>
<script src="https://d3js.org/d3.v6.min.js"></script>
<style>
div.tooltip {
position: absolute;
text-align: center;
width: 80px;
height: 33px;
padding: 2px;
font: 12px sans-serif;
background: white;
border: 0px;
border-radius: 8px;
pointer-events: none;
font-family:'Segoe UI', Geneva;
}
.flex-container {
display: flex;
}
.flex-child {
flex: 1;
}
.flex-child:first-child {
margin-right: 2px;
}
p {
font-family:'Segoe UI', Geneva;
}
h1 {
font-family:'Segoe UI', Geneva;
}
h3 {
font-family:'Segoe UI', Geneva;
}
p:first-child {
margin-top: 50px;
}
button {
margin-top: 1px;
font-family:'Segoe UI', Geneva;
font-size: 13px;
}
select {
font-size: 14px;
font-family:'Segoe UI', Geneva;
}
/* Add a black background color to the top navigation */
.topnav {
background-color:#E3AD63;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color:#724820;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 14px;
font-family:'Segoe UI', Geneva;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color:#724820;
color:#E3AD63 ;
}
/* Add an active class to highlight the current page */
.topnav a.active {
background-color:#724820;
color:#E3AD63;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
</style>
</head>
<body>
<div id="visScreen">
<div id="menu" class="topnav">
<a href="#vis" class="active" onClick="return showVis();">visualization</a>
<a href="#details" onClick="return showDetails();">details</a>
</div>
<div class="flex-container">
<div id="visualization" class="flex-child">
</div>
<div id="options" class="flex-child">
<p>sort data in descending order</p>
<button id="sort">sort</button>
<p>unsort data to original order</p>
<button id="unsort">unsort</button>
<br>
<br>
<p>select year</p>
<select id="selectYear">
<option>all</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
</select>
<br>
<br>
<p>select incident type</p>
<select id="selectType">
<option>all</option>
<option>possession/trade</option>
<option>possession/transfer</option>
<option>seizure</option>
</select>
</div>
</div>
</div>
<div id="detailsScreen" style="display:none">
<div id="menu" class="topnav">
<a href="#vis" onClick="return showVis();">visualization</a>
<a href="#details" class="active" onClick="return showDetails();">details</a>
</div>
<h1 class="padded">Visualizing Illegal Cheetah Trade and Seizure</h1>
<p class="padded">
Utilizing a global dataset created to document the illegal trade and seizure of cheetahs between the years 2010 and 2019,
this visualization aims to summarize the data from these incidents in an interactive way. Our group implemented a
filterable and sortable horizontal bar chart with the goal of showing the number of cheetahs involved in incidents, organized by location (specifically the country).
<br>
<br>
Since the dataset contained information on individual and contained incidents, this summarative visualization allows the user to see
where, when, and what type of incidents that the greatest number of cheetahs were involved in.
<br>
<br>
- Saudi Arabia, by far, saw the most number of cheetahs involved in incidents over the total timeframe (1559), of which 1504 were possession/trade incidents.
<br>
- However, until 2013, countries like Kenya, the UAE, and Somaliland outranked Saudi Arabia in number of cheetahs involved in incidents.
<br>
- Only two countries (UAE and Egypt) had occurrences of possession/transfer incidents.
<br>
- Kenya had the highest number of cheetahs involved in seizure incidents (284), as well as the highest overall numbers
in 2010 and 2011.
<br>
<br>
By the use of this visualization, it is our hope that the issue of poaching and illegal seizure of cheetahs in different locations
can be examined more in depth over the selected timeframe of the dataset.
</p>
<h3 class="padded">dataset information:</h3>
<p class="padded"><a href="https://www.sciencedirect.com/science/article/pii/S2352340921001323">article</a></p>
<p class="padded"><a href="https://data.mendeley.com/datasets/84k92j4n3y/2">dataset source</a></p>
<h3 class="padded">process book & narrative video:</h3>
<p class="padded"><a href="https://github.com/ryjdillon/final/blob/9afcfb07a2740c55aa6271d8b80a3a425bbcdcef/process_book.pdf">book</a></p>
<p class="padded"><a href="https://www.youtube.com/watch?v=2bgdcwqqcZY">video</a></p>
</div>
<script>
console.log(d3); // test if d3 is loaded
// change screen from vis screen to details screen
function showDetails() {
document.getElementById('visScreen').style.display='none';
document.getElementById('detailsScreen').style.display='block';
}
// change screen from details screen to vis screen
function showVis() {
document.getElementById('detailsScreen').style.display='none';
document.getElementById('visScreen').style.display='block';
}
var margin = {top: 50, left: 100, bottom: 80, right: 50};
var width = 1325 - margin.left - margin.right;
var height = 1200 - margin.top - margin.bottom;
const svg = d3.select("div#visualization")
.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 + ")");
svg.append("rect")
.attr("x",0)
.attr("y",0)
.attr("height", height)
.attr("width", width)
.style("fill", "#E3AD63")
var div = d3.select("div#visualization").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
let data = d3.csv("data/Tricorache et al_Global trade dataset for cheetah.csv", d3.autoType).then(function(data) {
const grouped_data = d3.rollups(data, v => d3.sum(v, d => d.Cheetahs), d => d.Country);
const grouped_data_year = d3.rollups(data, v => d3.sum(v, d => d.Cheetahs), d => d.Country, d => d.Year);
const grouped_data_type = d3.rollups(data, v => d3.sum(v, d => d.Cheetahs), d=> d.Country, d => d.Incident_Type);
//console.log(grouped_data_type);
const filtered_grouped_data = grouped_data.filter(function (d) {
return d[1] > 0;
})
var current_data = [...filtered_grouped_data];
// x axis
var xScale = d3.scaleLinear()
.domain([0, (d3.max(current_data, d => d[1])*1.05)])
.range([0, width]);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(xScale))
.attr("class", "x-axis1")
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
svg.append("g")
.attr("transform", "translate(0," + 0 + ")")
.call(d3.axisTop(xScale))
.attr("class", "x-axis2")
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
// y axis
var yScale = d3.scaleBand()
.range([ 0, height ])
.domain(current_data.map(function(d) {return d[0];}))
.padding(.1);
svg.append("g")
.call(d3.axisLeft(yScale))
.attr('class', 'y-axis')
.attr("font-family", 'Segoe UI')
var axisLeft = d3.axisLeft(yScale).tickFormat(function(d) {return d; });
// bars
// bars
var defs = svg.append('svg:defs');
defs.append('svg:pattern')
.attr('id', 'cheetahprint')
.attr("width", 612)
.attr("height", 612)
.attr("patternUnits", "userSpaceOnUse")
.append('svg:image')
.attr("xlink:href", "https://media.istockphoto.com/id/1313630388/vector/vector-seamless-pattern-of-leopard-or-ounce-predatory-print.jpg?s=612x612&w=0&k=20&c=-lSnZFVY2ccPzyMyO0KzGO483fTotNMtlnbxPTvwx3o=")
.attr("width", 612)
.attr("height", 612)
.attr("x", 0)
.attr("y", 0);
svg.selectAll(".bar")
.data(filtered_grouped_data)
.enter()
.append("rect")
.attr("class","bar")
.attr("x", xScale(0) )
.attr("y", function(d) { return yScale(d[0]); })
.attr("width", function(d) { return xScale(d[1]); })
.attr("height", yScale.bandwidth() )
.style("fill", "url(#cheetahprint)")
.style("stroke", "#724820")
.style("stroke-width", 1)
.on("mouseover", function(event,d) {
//console.log(d);
div.transition()
.duration(200)
.style("opacity", 1);
div.html("# of cheetahs: " + d[1] + "<br/>")
.style("left", (event.pageX) + "px")
.style("top", (event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
// x axis label:
svg.append("text")
.attr("text-anchor", "end")
.attr("x", width/2 + margin.left)
.attr("y", height + margin.top + 10)
.attr("font-family", 'Segoe UI')
.text("number of cheetahs involved in incidents");
// y axis label:
svg.append("text")
.attr("text-anchor", "end")
.attr("transform", "rotate(-90)")
.attr("y", -margin.left + 20)
.attr("x", -margin.top - height/2 + 20)
.attr("font-family", 'Segoe UI')
.text("country")
d3.selectAll(".y-axis text")
.attr("class", "bar-label");
d3.select("#sort").on("click", function() {
copied_current_data = [...current_data];
sorted_data = copied_current_data.sort(function(a, b) {
return a[1] - b[1];
}).reverse();
yScale.domain(sorted_data.map(function(d) {
//console.log(d);
return d[0];
}));
// move bars
svg.selectAll(".bar")
.transition()
.duration(1000)
.attr("y", function(d, i) {
return yScale(d[0]);
});
// move labels
svg.select('g.y-axis')
.transition()
.duration(1000)
.call(axisLeft);
});
d3.select("#unsort").on("click", function() {
yScale.domain(current_data.map(function(d) {
return d[0];
}));
// move bars
svg.selectAll(".bar")
.transition()
.duration(1000)
.attr("y", function(d, i) {
return yScale(d[0]);
});
// move labels
svg.select('g.y-axis')
.transition()
.duration(1000)
.call(axisLeft);
});
d3.select("#selectYear").on("change", changeYear);
d3.select("#selectType").on("change", changeType)
function changeYear() {
var selectedYear = this.options[this.selectedIndex].value;
//console.log(selectedYear);
if (selectedYear == "all") {
current_data = [...filtered_grouped_data];
document.getElementById("selectType").disabled = false;
xScale.domain([0, (d3.max(current_data, d => d[1])*1.05)]);
svg.select('g.x-axis1')
.transition()
.duration(500)
.call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
svg.select('g.x-axis2')
.transition()
.duration(500)
.call(d3.axisTop(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
// move bars
svg.selectAll(".bar")
.data(current_data)
.transition()
.duration(500)
.attr("width", function(d) { return xScale(d[1]);});
}
else {
const copied_year_data = [...grouped_data_year];
//console.log(copied_year_data);
var new_data = copied_year_data.map(function(d) {
var num = 0;
for(var i=0; i<d[1].length; i++) {
if (d[1][i][0] == selectedYear) {
num = d[1][i][1];
}
}
return [d[0], num];
});
current_data = [...new_data];
document.getElementById("selectType").disabled = true;
xScale.domain([0, (d3.max(current_data, d => d[1])*1.05)]);
svg.select('g.x-axis1')
.transition()
.duration(500)
.call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
svg.select('g.x-axis2')
.transition()
.duration(500)
.call(d3.axisTop(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
// move bars
svg.selectAll(".bar")
.data(current_data)
.transition()
.duration(500)
.attr("width", function(d) { return xScale(d[1]);});
}
}
function changeType() {
var selectedType = this.options[this.selectedIndex].value;
//console.log(selectedYear);
if (selectedType == "all") {
current_data = [...filtered_grouped_data];
document.getElementById("selectYear").disabled = false;
xScale.domain([0, (d3.max(current_data, d => d[1])*1.05)]);
svg.select('g.x-axis1')
.transition()
.duration(500)
.call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
svg.select('g.x-axis2')
.transition()
.duration(500)
.call(d3.axisTop(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
// move bars
svg.selectAll(".bar")
.data(current_data)
.transition()
.duration(500)
.attr("width", function(d) { return xScale(d[1]);});
}
else {
var type = "";
if (selectedType == "possession/trade") {
type = "Possession/trade";
}
else if (selectedType == "possession/transfer") {
type = "Possession/transfer";
}
else if (selectedType == "seizure") {
type = "Seizure";
}
const copied_type_data = [...grouped_data_type];
console.log(copied_type_data);
var new_data = copied_type_data.map(function(d) {
var num = 0;
for(var i=0; i<d[1].length; i++) {
//console.log(d[1][i]);
if (d[1][i][0] == type) {
//console.log(d[1][i][1]);
num = d[1][i][1];
}
}
return [d[0], num];
});
current_data = [...new_data];
console.log(current_data);
document.getElementById("selectYear").disabled = true;
xScale.domain([0, (d3.max(current_data, d => d[1])*1.05)]);
svg.select('g.x-axis1')
.transition()
.duration(500)
.call(d3.axisBottom(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
svg.select('g.x-axis2')
.transition()
.duration(500)
.call(d3.axisTop(xScale))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(45)")
.attr("font-family", 'Segoe UI')
.style("text-anchor", "end");
// move bars
svg.selectAll(".bar")
.data(current_data)
.transition()
.duration(500)
.attr("width", function(d) { return xScale(d[1]);});
}
}
});
</script>
</body>
</html>