-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtaxonomy.html
More file actions
444 lines (381 loc) · 13.9 KB
/
taxonomy.html
File metadata and controls
444 lines (381 loc) · 13.9 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
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Neotoma Taxonomy</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<link rel='stylesheet' href="bower_components/pace/themes/black/pace-theme-loading-bar.css" />
</head>
<style>
.node {
cursor: pointer;
}
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node text {
font: 10px sans-serif;
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
.tooltip {
position: absolute;
padding: 2px;
font: 12px sans-serif;
min-width: 150px;
background: lightsteelblue !important;
border: 0px;
border-radius: 8px;
pointer-events: none;
z-index: 99999999;
}
</style>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid nav-container">
<div class="navbar-header col-xs-8">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h3 class='iam-header' id='iam-header'>Ice Age <strong><i>Mapper</i></strong> <span class='text-muted'><small>v2.0</small></span></h3>
<label class="navbar-link" for="filterUnfulfilled">
<input type="checkbox" class="autosubmit" id="in-neotoma" value="true">
With Sites in NeotomaDB
</label>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" id='dropdown-menu' data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<h4>Menu <span class='caret'></span></h4>
</a>
<ul class="dropdown-menu">
<li href="index.html">
Home
</li>
<li><a href="gallery.html">Gallery</a></li>
<!-- <li><a href="#">Tutorial</a></li> -->
<li><a href="docs.html">Documentation</a></li>
<li><a href="taxonomy.html">Interactive Taxonomy</a></li>
</ul>
</li>
</ul>
</div><!--/.container-fluid -->
</nav>
<div class='container' id='main'>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<strong>Taxon ID: </strong><span class='text-muted' id='taxonIDModal'></span><br />
<strong>Exinct: </strong><span class='text-muted' id='exinctModal'></span><br />
<strong>Author: </strong><span class='text-muted' id='authorModal'></span><br />
<hr />
<!-- <strong>Occurrences in Neotoma: </strong><span class='text-muted' id='numOccurrencesModal'></span><br />
<strong>Youngest Age: </strong><span class='text-muted' id='ageYoungModal'></span><br />
<strong>Oldest Age: </strong><span class='text-muted' id='ageOldModal'></span><br /> -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success"><a id='openMap'>Show on Map</a></button>
</div>
</div>
</div>
</div>
<script src="bower_components/pace/pace.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="lib/burrow.js"></script>
<script src="https://d3js.org/d3-hierarchy.v1.min.js"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<script>
var getParameterByName = function(name, url) {
//get the query parameter values from the URI
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}; //end get parameter by name function
globals = {}
var margin = {top: 100, right: 120, bottom: 20, left: 120},
width = 2500 - margin.right - margin.left,
height = 1500 - margin.top - margin.bottom;
var i = 0,
duration = 750,
root;
var tree = d3.layout.tree()
.size([height, width]);
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
// Define the div for the tooltip
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var svg = d3.select("#main").append("svg")
.attr("width", width + margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
function loadAndDraw(){
d3.select("svg").empty()
onlyInNeotoma = getParameterByName("inNeotoma");
if (onlyInNeotoma == 'true'){
$("#in-neotoma").prop('checked', true)
}else{
$("#in-neotoma").prop('checked', false)
}
nonExtinctOnly = false;
d3.text("data/expanded_with_num_sites.csv", function(error, dump) {
//filter the data
if (error) throw error;
rows = d3.csv.parseRows(dump)
globals.rows = rows;
//decide how to filter
data = new Array()
rows.forEach(function(row) {
//construct a new row with a taxonomy property
newRow = {}
taxonomy = row.slice(4, row.length) // skips the extra info
taxonomy = taxonomy.clean("") // get rid of empty strings;
newRow.taxonomy = new Array()
//strip whitespace out of the taxonomy entries
for (var i=0; i< taxonomy.length; i++){
newRow.taxonomy[i] = taxonomy[i].replace(/\s+$/, '');
}
newRow.author = row[2]
newRow.extinct = row[1]
newRow.id = row[0]
newRow.numSites = parseInt(row[3])
newRow.nodeName = newRow.taxonomy[newRow.taxonomy.length - 1]
if ((onlyInNeotoma) && (nonExtinctOnly)){
if ((newRow.extinct == 'FALSE') && (newRow.numSites > 0)){
data.push(newRow)
}
}
else if (onlyInNeotoma){
if (newRow.numSites > 0){
data.push(newRow)
}else{
}
}else if (nonExtinctOnly){
if (newRow.extinct == 'FALSE'){
data.push(newRow)
}
}else{
data.push(newRow)
}
}); //end foreach
globals.dataset = data
drawTree(data);
});
}
function drawTree(data){
//takes in an array of rows
hierarchy = burrow(data)
root = d3.hierarchy(hierarchy);
root.x0 = height / 2;
root.y0 = 0;
function collapse(d) {
if (d.children) {
d._children = d.children;
d._children.forEach(collapse);
d.children = null;
}
}
root.children.forEach(collapse);
update(root);
}
function update(source) {
// Compute the new tree layout.
var nodes = tree.nodes(root).reverse(),
links = tree.links(nodes);
// Normalize for fixed-depth.
nodes.forEach(function(d) { d.y = d.depth * 180; });
// Update the nodes…
var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
// Enter any new nodes at the parent's previous position.
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
.on("click", click)
.on('dblclick', dblclick)
nodeEnter.append("circle")
.attr("r", 2)
.style('fill', function(d){
if ((d._children !== null) && (d._children != undefined)){
if(d._children.length == 0){
return 'lightsteelblue'
}else{
return 'steelblue'
}
}else{
return 'lightsteelblue'
}
})
nodeEnter.append("text")
.attr("x", function(d) { return d.children || d._children ? -10 : 10; })
.attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
.text(function(d) { return d.data.name; })
.style("fill-opacity", 1e-6)
.style('font-size', 12)
.on('mouseover', divShow)
.on('mouseout', divHide)
// Transition nodes to their new position.
var nodeUpdate = node.transition()
.duration(duration)
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
nodeUpdate.select("circle")
.attr("r", 4.5)
//.style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; });
.style('fill', function(d){
if ((d._children !== null) && (d._children != undefined)){
if(d._children.length == 0){
return 'lightsteelblue'
}else{
return 'steelblue'
}
}else{
return 'lightsteelblue'
}
})
// .on('mouseover', divShow)
// .on('mouseout', divHide)
nodeUpdate.select("text")
.style("fill-opacity", 1)
.style('font-size', 12)
// .on('mouseover', divShow)
// .on('mouseout', divHide)
// Transition exiting nodes to the parent's new position.
var nodeExit = node.exit().transition()
.duration(duration)
.attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
.remove();
nodeExit.select("circle")
.attr("r", 1e-6);
nodeExit.select("text")
.style("fill-opacity", 1e-6);
// Update the links…
var link = svg.selectAll("path.link")
.data(links, function(d) { return d.target.id; });
// Enter any new links at the parent's previous position.
link.enter().insert("path", "g")
.attr("class", "link")
.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});
});
// Transition links to their new position.
link.transition()
.duration(duration)
.attr("d", diagonal);
// Transition exiting nodes to the parent's new position.
link.exit().transition()
.duration(duration)
.attr("d", function(d) {
var o = {x: source.x, y: source.y};
return diagonal({source: o, target: o});
})
.remove();
// Stash the old positions for transition.
nodes.forEach(function(d) {
d.x0 = d.x;
d.y0 = d.y;
});
}
// Toggle children on click.
function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}
function divShow(d){
div.transition()
.duration(200)
.style("opacity", .9)
.style('background-color', 'lightsteelblue')
div.html("Loading...")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY + 15) + "px");
$.getJSON("https://api.neotomadb.org/v1/data/taxa?taxonname=" + d.data.name, function(data){
if (data['success']){
try{
html = "<h5 class='page-header'>" + data['data'][0]['TaxonName'] + "</h4>"
html += "<strong>Taxon ID: </strong>" + "<span class='text-muted'>" + data['data'][0]['TaxonID'] + "</span><br / />"
html += "<strong>Extinct: </strong>" + "<span class='text-muted'>" + data['data'][0]['Extinct'] + "</span><br / />"
html += "<strong>Author: </strong>" + "<span class='text-muted'>" + data['data'][0]['Author'] + "</span><br / />"
div.html(html)
}catch(err){
div.html("No Details Found")
}
}
})//end get json
}
function divHide(d){
div.transition().duration(500)
.style("opacity", 0);
}
function dblclick(d){
$("#myModal").modal('show');
$("#myModalLabel").text(d.data.name)
$.getJSON("https://api.neotomadb.org/v1/data/taxa?taxonname=" + d.data.name, function(data){
if (data['success']){
try{
$("#taxonIDModal").text(data['data'][0]['TaxonID'])
$("#exinctModal").text(data['data'][0]['Extinct'])
$("#authorModal").text(data['data'][0]['Author'])
uri = "iam.html?taxonid=" + data['data'][0]['TaxonID']
$("#openMap").attr('href', uri)
}catch(err){
console.log(err)
}
}
})
// $.getJSON("http://apidev.neotomadb.org/v1/data/occurrences?nametype=base&taxonname=" + d.data.name, function(data){
// if(data['success']){
// console.log("Got occurrences response")
// minAge = d3.min(data['data'], function(d){return d.AgeYounger})
// maxAge = d3.max(data['data'], function(d){return d.AgeOlder})
// console.log(minAge)
// console.log(maxAge)
// $("#numOccurrencesModal").text(data['data'].length)
// $("#ageYoungModal").text()
// $("#ageOldModal").text()
// }else{
// console.log(data)
// }
// })
}
loadAndDraw()
$("#in-neotoma").change(function(){
console.log("Changing.")
isChecked = $("#in-neotoma").prop('checked')
newURL = updateURLParameter(window.location.href, 'inNeotoma', isChecked)
window.location.href = newURL
})
</script>