-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfolio.html
300 lines (255 loc) · 9.87 KB
/
folio.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cornell DAS Lab NYC Tree Folio</title>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://d3js.org/d3.v4.js"></script>
<style>
td {
font: 12px/12px 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: 400;
padding: 2px 6px 2px 6px;
overflow: hidden;
}
table {
display: inline-block;
}
.title{
font: 64px/64px 'Helvetica Neue', Arial, Helvetica, sans-serif;
font-weight: 550;
float:left;
margin-top: 8px;
margin-bottom:0px;
padding-left: 8px;
padding-bottom:8px;
color: #b9bfb7;
}
</style>
</head>
<body>
<div id="my_dataviz"></div>
<script>
const queryString = window.location.href;
const url = new URL(queryString);
const zip = url.searchParams.get("zipcode");
const sp = url.searchParams.get("species");
console.log(zip);
console.log(sp);
// TREE LIST JSONS GO HERE ///////////////////////////////////////////////////////////
var csvpath = ' ./folio/folio/'.concat(zip,'/',zip,'/',sp,'/trees.json'); //original absolute path: https://tree-folio.s3.amazonaws.com
jQuery.when(jQuery.getJSON(csvpath)).done( function(trees) {
const body = document.body;
const tbl1 = document.createElement('table');
tbl1.setAttribute("style", "width:".concat("100%",";"));
var tr = tbl1.insertRow();
var td = tr.insertCell();
td.setAttribute("class" , "title");
var title = zip.concat(" - ",sp);
td.appendChild(document.createTextNode(title));
body.appendChild(tbl1);
//loop through csv
var treeArray = [];
for (const tree in trees) {
treeArray.push(trees[tree]);
};
for (const tree in treeArray.slice(0,50)) {
//console.log(treeArray[tree]);
const tree_data = treeArray[tree];
const tree_id = tree_data.tree_id;
const tree_dbh = tree_data.tree_dbh;
const curb_loc = tree_data.curb_loc;
const status = tree_data.status;
const health = tree_data.health;
const spc_latin = tree_data.spc_latin;
const spc_common = tree_data.spc_common;
const sidewalk = tree_data.sidewalk;
const address = tree_data.address;
const zipcode = tree_data.zipcode;
const boroname = tree_data.boroname;
const nta_name = tree_data.nta_name;
const latitude = tree_data.Latitude;
const longitude = tree_data.longitude;
//grab point cloud json and make D3 scatter plot
// POINT CLOUD FILE PATH GOES HERE ///////////////////////////////////////////////////////////////////////////////////////
var pointCloudFile = ' https://tree-folio.s3.amazonaws.com/folio/folio/';
var pointCloudFile = pointCloudFile.concat(zipcode);
var pointCloudFile = pointCloudFile.concat('/');
var pointCloudFile = pointCloudFile.concat(zipcode);
var pointCloudFile = pointCloudFile.concat('/');
var pointCloudFile = pointCloudFile.concat(spc_common);
var pointCloudFile = pointCloudFile.concat('/');
var pointCloudFile = pointCloudFile.concat(tree_id);
var pointCloudFile = pointCloudFile.concat('.json');
jQuery.when(jQuery.getJSON(pointCloudFile)).done( function(treeTable) {
var width = (window.innerWidth)/6;
var height = width;
var scalar = 25;
const tbl = document.createElement('table');
tbl.setAttribute("style", "width:".concat(width,";"));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right; padding: 2px 2px 2px ".concat(width/1.5,"px;"));
td.appendChild(document.createTextNode('Address: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(address));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Neighborhood: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(nta_name));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Boro: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(boroname));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Tree ID: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(tree_id));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Trunk Diameter (in): '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(tree_dbh));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Status: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(status));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Health: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(health));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Curb Location: '));
var td = tr.insertCell();
td.appendChild(document.createTextNode(curb_loc));
var tr = tbl.insertRow();
var td = tr.insertCell();
td.setAttribute("style" , "font-weight: 600; text-align: right;");
td.appendChild(document.createTextNode('Sidewalk Condition: '));
var td = tr.insertCell();
td.setAttribute("style" , "padding: 2px ".concat(width/1.5,"px 2px 6px;"));
td.appendChild(document.createTextNode(sidewalk));
body.appendChild(tbl);
const divid1 = "plotholder1_".concat(tree_id.toString());
var element = document.createElement('div');
element.setAttribute("id" , divid1);
element.setAttribute("width" , width);
element.setAttribute("height" , height);
element.setAttribute("style" , "display: inline-block;");
body.append(element);
d3.select( "#".concat(divid1))
.append('svg')
.attr("width", width)
.attr("height" , height)
.attr("style" , "background: white;")
.append("g")
.selectAll("circle")
.data(treeTable)
.enter()
.append("circle")
.attr("cx", function (d) { return (width/scalar)*d[0]/3.28+(width/2) } )
.attr("cy", function (d) { return -(width/scalar)*d[2]+(height/1) } )
.attr("r", function (d) { return (d[5]-d[4]+3)/2 } )
.attr("stoke","rgba(0,0,0,0)")
.attr("fill", function (d) {
var color = "rgba(".concat(
d[3]*75,
",",
(d[3]*75+(d[5]-d[4])*75),
",",
d[3]*75,
",",
(d[5]-d[4]+1)/10+0.1,
")");
//console.log(color);
return color;
} );
const divid2 = "plotholder2_".concat(tree_id.toString());
var element = document.createElement('div');
element.setAttribute("id" , divid2);
element.setAttribute("width" , width);
element.setAttribute("height" , height);
element.setAttribute("style" , "display: inline-block;");
body.append(element);
d3.select( "#".concat(divid1))
.append('svg')
.attr("width", width)
.attr("height" , height)
.attr("style" , "background: white;")
.append("g")
.selectAll("circle")
.data(treeTable)
.enter()
.append("circle")
.attr("cx", function (d) { return (width/scalar)*d[1]/3.28+(width/2) } )
.attr("cy", function (d) { return -(width/scalar)*d[2]+(height/1) } )
.attr("r", function (d) { return (d[5]-d[4]+3)/2 } )
.attr("stoke","rgba(0,0,0,0)")
.attr("fill", function (d) {
var color = "rgba(".concat(
d[3]*75,
",",
(d[3]*75+(d[5]-d[4])*75),
",",
d[3]*75,
",",
(d[5]-d[4]+1)/10+0.1,
")");
//console.log(color);
return color;
} );
const divid3 = "plotholder3_".concat(tree_id.toString());
var element = document.createElement('div');
element.setAttribute("id" , divid3);
element.setAttribute("width" , width);
element.setAttribute("height" , height);
element.setAttribute("style" , "display: inline-block;");
body.append(element);
d3.select( "#".concat(divid1))
.append('svg')
.attr("width", width)
.attr("height" , height)
.attr("style" , "background: white;")
.append("g")
.selectAll("circle")
.data(treeTable)
.enter()
.append("circle")
.attr("cx", function (d) { return (width/scalar)*d[0]/3.28+(width/2) } )
.attr("cy", function (d) { return (width/scalar)*d[1]/3.28+(width/2) } )
.attr("r", function (d) { return (d[5]-d[4]+3)/2 } )
.attr("stoke","rgba(0,0,0,0)")
.attr("fill", function (d) {
var color = "rgba(".concat(
d[3]*75,
",",
(d[3]*75+(d[5]-d[4])*75),
",",
d[3]*75,
",",
(d[5]-d[4]+1)/10+0.1,
")");
//console.log(color);
return color;
} );
body.append(document.createElement('br'));
});
}; //close for loop
});
</script>
</body>
</html>