-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
161 lines (136 loc) · 6.63 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
body {
background-color: #F0ECEC !important;
}
#container {
width:100%;
}
#map {
height:400px;
width:900px;
}
#bounds {
height: 10px;
}
#bipartite {
height: 300px;
width:1000px;
}
#results {
align:right;
width:50%;
}
p#instructions {
width:900px;
}
svg text{
font-size:10px;
}
rect{
shape-rendering:crispEdges;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!--leaflet libraries and styles-->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"/>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<link rel="stylesheet" href="./leaflet-locationfilter/src/locationfilter.css"/>
<script src="./leaflet-locationfilter/src/locationfilter.js"></script>
<!-- Libraries needed for new bipartitie -->
<script src="lib/d3.min.js" type="text/javascript"></script>
<script src="lib/biPartite.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
window.onload = function () {
//map
var map = L.map('map').setView([51.505, -0.09], 5);
L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/{type}/{z}/{x}/{y}.{ext}', {
type: 'sat',
ext: 'jpg',
attribution: 'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> — Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency',
subdomains: '1234'
}).addTo(map);
//leaflet get bounds
var locationFilter = new L.LocationFilter().addTo(map);
locationFilter.enable(true);
var bounds = locationFilter.getBounds();
var isEnabled = locationFilter.isEnabled();
locationFilter.on("change", function (e) {
var sourceTaxaSelect = $('select[name=source-taxa]').val();
var targetTaxaSelect = $('select[name=target-taxa]').val();
var selectedarea = { nw_lat: e.bounds._northEast.lat, nw_lng: e.bounds._southWest.lng, se_lat: e.bounds._southWest.lat, se_lng: e.bounds._northEast.lng};
var options = { location: selectedarea, width: 1000, height: 500, sourceTaxa: [sourceTaxaSelect], targetTaxa: [targetTaxaSelect] };
$.ajax({
url: "http://api.globalbioticinteractions.org/interaction?type=json.v2&nw_lat="+e.bounds._northEast.lat+"&nw_lng="+e.bounds._southWest.lng+"&se_lat="+e.bounds._southWest.lat+"&se_lng="+e.bounds._northEast.lng+"&sourceTaxon="+sourceTaxaSelect+"&targetTaxon="+targetTaxaSelect+"&limit=100",
//force to handle it as text
dataType: "text",
success: function(data) {
var json = $.parseJSON(data);
var taxon_data = [];
$('#results').empty();
$('#results').append('Total interactions found: ' + json.length + '</br>');
for (var i = 0; i < json.length; i++) {
$('#results').append('Interactions: ' + json[i].source.name + ' ' + json[i].interaction_type + ' ' + json[i].target.name + '</br>');
//creating array of arrays for bipartite to consume
taxon_data.push([ json[i].source.name + "","" + json[i].target.name, 1, 1]);
}
JSON.stringify(taxon_data, null, 4);
//bipartite scales
$('svg').remove();
var width = 1100, height = 700, margin ={b:0, t:40, l:170, r:50};
var svg = d3.select("body")
.append("svg").attr('width',width).attr('height',(height+margin.b+margin.t))
.append("g").attr("transform","translate("+ margin.l+","+margin.t+")");
var data = [
{data:bP.partData(taxon_data,2), id:'TaxonInteractions', header:["Source","Target", "Taxon Interactions"]},
];
bP.draw(data, svg);
}
});
});
};
</script>
</head>
<body>
<p id="instructions">Please, select a geographic area in the map and source (e.g. predator) and target (e.g. prey)
taxas in order to generate a bipartite graph of interactions between the selected taxas within the bounding box. If too many interactions found, consider decreasing the size of the geographic bounding box.</p>
<form>
Select your source Taxa
<select name="source-taxa" id="source-taxa">
<option value="Arthropoda">Arthropoda</option>
<option value="Mammalia">Mammalia</option>
<option value="Actinopterygii">Actinopterygii</option>
<option value="Arachnida">Arachnida</option>
<option value="Mollusca">Mollusca</option>
<option value="Plantae">Plantae</option>
<option value="Amphibia" selected>Amphibia</option>
<option value="Reptilia">Reptilia</option>
<option value="Bacteria">Bacteria</option>
<option value="other">other</option>
</select>
Select Your Target Taxa
<select name="target-taxa" id="target-taxa">
<option value="Arthropoda">Arthropoda</option>
<option value="Mammalia">Mammalia</option>
<option value="Actinopterygii">Actinopterygii</option>
<option value="Arachnida">Arachnida</option>
<option value="Mollusca" selected>Mollusca</option>
<option value="Plantae">Plantae</option>
<option value="Amphibia">Amphibia</option>
<option value="Reptilia">Reptilia</option>
<option value="Bacteria">Bacteria</option>
<option value="other">other</option> </select>
</form>
</br>
<div id="container">
<div id="map"></div>
<div id="map-bounds"></div>
</br>
<span id="results"></span>
</div>
</body>
</html>