-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataview.html
More file actions
1230 lines (919 loc) · 35.6 KB
/
dataview.html
File metadata and controls
1230 lines (919 loc) · 35.6 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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<script src="scripts/d3.min.js" type="text/javascript"></script>
<script src="scripts/d3.tip.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script>
<script src="scripts/jquery.js" type="text/javascript"></script>
<script src="scripts/turf.min.js" type="text/javascript"></script>
<script src="scripts/simplestat.min.js" type="text/javascript"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/spin.min.js'></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<link rel="stylesheet" href="styles/map.css" />
<link rel="stylesheet" href="https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css" />
</head>
<style>
.context line, text {
fill: #000;
shape-rendering: crispEdges;
font-size: 10px;
}
div.tooltip {
position: absolute;
text-align: left;
width: 220px;
height: 35px;
padding: 3px;
font: 12px sans-serif;
background: white;
border: 0px;
border-radius: 8px;
/* pointer-events: none; This line needs to be removed */
}
#dropdown {
padding: 100px 100px 100px 100px;
display: block;
margin-left: auto;
margin-right: auto;
}
#edge:hover {
stroke-opacity: 1;
/*pointer-events: none;*/
}
.header {
padding: 0px 5px 10px 5px;
top: 5px;
/*font: 13px sans-serif;*/
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
display: block;
margin-left: auto;
margin-right: auto;
}
.header_text {
font: 6px sans-serif;
stroke: none;
}
input#toggle {
max-height: 0;
max-width: 0;
opacity: 0;
}
input#toggle + label {
display: block;
position: relative;
box-shadow: inset 0 0 0px 1px #d5d5d5;
text-indent: -5000px;
height: 20px;
width: 50px;
border-radius: 15px;
}
input#toggle + label:before {
content: "";
position: absolute;
display: block;
height: 20px;
width: 30px;
top: 0;
left: 0;
border-radius: 15px;
background: rgba(252, 76, 3, 1);
-moz-transition: .25s ease-in-out;
-webkit-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
input#toggle + label:after {
content: "";
position: absolute;
display: block;
height: 20px;
width: 30px;
top: 0;
left: 0px;
border-radius: 15px;
background: white;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2), 0 2px 4px rgba(0, 0, 0, .2);
-moz-transition: .25s ease-in-out;
-webkit-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
input#toggle:checked + label:before {
width: 50px;
background: rgba(252, 76, 3, 1);
}
input#toggle:checked + label:after {
left: 20px;
box-shadow: inset 0 0 0 1px rgba(252, 76, 3, 1), 0 2px 4px rgba(0, 0, 0, .2);
}
#intersection:hover {
opacity: 1;
stroke: white;
}
.intersection_legend circle {
fill: none;
stroke: black;
}
.intersection_legend text {
fill: #777;
font: 10px sans-serif;
text-anchor: middle;
}
.key path {
display: none;
}
.key fill, text {
fill: #000;
shape-rendering: crispEdges;
font-size: 10px;
}
.legend {
padding: 0px 10px;
top: 10px;
right: 15px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
#logo {
display: block;
margin-left: auto;
margin-right: auto;
}
#map {
width: 100%;
height: 100%;
}
#nodeToggle {
display: block;
margin-left: auto;
margin-right: auto;
}
svg {
fill: none;
position: relative;
}
</style>
<body>
<div id="loader_container"></div>
<div id="map">
<script>
// ensure Metro logo loads first
if(document.images){
image = new Image(144,127); // width, height
image.src = "data/Metro.png";
}
//// DEFINE FUNCTION VARIABLE FOR DATA VIEW ////
var dataView = (function() {
// config references for load spinner
var config = {
target: 'map'//,
//data_url: 'data/SF_weekday_total.json',
};
// loader settings
var opts = {
lines: 9, // Number of lines to draw
length: 9, // Length of each line
width: 6, // Line thickness
radius: 16, // Radius of inner circle
color: '#FC4C02', // #rgb or #rrggbb or array of colors
speed: 1.2, // Rounds per second
trail: 40, // Afterglow percentage
className: 'spinner', // CSS class to assign to the spinner
};
// loader target
var target = document.getElementById(config.target);
//// MAP COMPONENT ////
// get base map tiles
var mapboxTiles = L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
attribution: '<a href="http://www.mapbox.com/about/maps/" target="_blank">Terms & Feedback</a>'
});
// realize those tiles
var map = L.map('map', { zoomControl: false, minZoom: 9, maxZoom: 18})
.addLayer(mapboxTiles)
.setView([37.780536, -122.42], 13);
// position zoom control in top right
new L.Control.Zoom({ position: 'topright' }).addTo(map);
// Initialize the SVG layer //
map._initPathRoot()
// define svg, hide phantom artifacts on zoom, append svg to group with class "leaflet-zoom-hide"
var svg = d3.select(map.getPanes().overlayPane).append("svg"),
g = svg.append("g").attr("class", "leaflet-zoom-hide");
// define node svg layer
// var svgNodes = d3.select("#map").select("svg"),
// gNodes = svgNodes.append("g");
// // define node svg layer
// var svgEdges = d3.select("#map").select("svg"),
// gEdges = svgEdges.append("g");
// add bottom right layer panel for legend
var legend = L.control({position: 'bottomright'});
// add legend to map
legend.onAdd = function (map) {var div = L.DomUtil.create('div', 'legend'); return div};
legend.addTo(map);
// define svg for EDGE legend, append svg to a group with class "key"
var svg_Legend = d3.select(".legend.leaflet-control").append("svg")
.attr("id", "legend")
//.style("opacity", 0)
.attr("width", 550)
.attr("height", 80);
d3.select(".legend.leaflet-control").style("opacity", 0);
// define group for legend rectangle bars
var g_key = svg_Legend.append("g")
.attr("class", "key")
.attr("transform", "translate(25,25)");
// define group for legend supplementary text
var g_context = svg_Legend.append("g")
.attr("class", "context")
.attr("transform", "translate(25,25)");
// add top left layer panel for header
var header = L.control({position: 'topleft'});
// add header to the map
header.onAdd = function (map) {var header = L.DomUtil.create('div', 'header'); return header};
header.addTo(map);
//// ADD METRO LOGO
var LogoHeight = 27, LogoWidth = 144, // Image dimensions
width = 144, height = 35; // Dimensions of cropped region
// create svg area for Logo
var svg_header = d3.select(".header.leaflet-control").append("svg")
.attr("viewBox", "0 0 " + width + " " + height)
.attr("preserveAspectRatio", "xMidYMid meet");
// append Metro image to svg
svg_header.append("image")
.attr("id", "logo")
.attr("width", LogoWidth + "px")
.attr("height", LogoHeight + "px")
.attr("xlink:href","data/Metro.png");
svg_header.append("text")
.attr("class", "header_text")
.text("Currently Viewing: Weekday Rollup - Totals")
.attr("x", 9)
.attr("y", 30);
// Define div for tooltips
var tooltip = d3.select("#map")
.append("div") // declare the tooltip div
.attr("class", "tooltip") // apply the 'tooltip' class
.style("opacity", 0); // default to transparent
// project 100% GPS VERIFIED DATA POINTS, convert geojson to svg
var transform = d3.geo.transform({point: projectPoint}),
path = d3.geo.path().projection(transform);
// adapts Leaflet's latLngToLayerPoint and LatLng methods
// to project a single point; resulting coordinates are
// passed to an output geometry stream
function projectPoint(x,y) {
var point = map.latLngToLayerPoint(new L.LatLng(y,x));
this.stream.point(point.x, point.y);
}
// get current map zoom
var currentZoom = map.getZoom();
// Function for moving layers to the front
d3.selection.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
// Function for moving layers to the back -- NOT IN USE
d3.selection.prototype.moveToBack = function() {
return this.each(function() {
var firstChild = this.parentNode.firstChild;
if (firstChild) {
this.parentNode.insertBefore(this, firstChild);
}
});
};
// define labels and statistics for dropdown menu
var labels = ['Select Statistic', 'Weekday Total Activity Count', 'Weekday Commute Count', 'Weekday Total Athlete Count'];
var statistics = ['Select Statistic', 'weekday_TACTCNT', 'weekday_CMTCNT', 'weekday_TATHCNT']; // these names come straight from variables in geojson
// select dropdown div, append selectable options, apply labels
d3.select(".header.leaflet-control")
.append("select")
.attr("id", "dropdown")
.selectAll("option")
.data(statistics)
.enter()
.append("option")
.attr("value", function (d) {
return d;
})
.text(function (d, i) {
return labels[i];
});
// queue()
// .defer(d3.json, "data/sf_nodes_weekday_total.json")
// .defer(d3.json, "data/SF_weekday_total.json")
// .await(ready);
//function ready(error, nodes_collection) {
// GET 100% GPS VERIFIED INTERSECTION DATA
d3.json("data/sf_nodes_weekday_total.json", function(error, nodes_collection) {
// console.log("nodes_collection", nodes_collection);
var nodes = nodes_collection.features;
nodes.forEach(function(d) {
d.MEDMAXT = +d.properties.sf_osm_edges_nodes_ride_rollup_total_weekday_MEDMAXT;
d.ATHCNT = +d.properties.sf_osm_edges_nodes_ride_rollup_total_weekday_ATHCNT;
d.LatLng = new L.LatLng(d.geometry.coordinates[1],
d.geometry.coordinates[0])
})
console.log("nodes", nodes);
// create an athlete count > 0 filter variable
var ATHCNT_filter = nodes.filter(function(d) { return (d.ATHCNT > 0) });
// console.log("filter", ATHCNT_filter);
// var MEDMEDT_filter = nodes.filter(function(d) { return (d.MEDMAXT > 0) });
// console.log("filter", MEDMEDT_filter);
// var breaks = (ss.jenks(MEDMEDT_filter.map (function(d) { return d.MEDMAXT; }), 5));
// console.log("breaks", breaks);
// var breaks = (ss.jenks(ATHCNT_filter.map (function(d) { return d.ATHCNT; }), 5));
// console.log("breaks", breaks);
// get min/ max for athlete counts and median max times
var Min_ATHCNT = d3.min(ATHCNT_filter, function (d) {
return d.ATHCNT;
});
var Max_ATHCNT = d3.max(ATHCNT_filter, function (d) {
return d.ATHCNT;
});
var Min_MEDMAXT = d3.min(nodes, function (d) {
return d.MEDMAXT;
});
var Max_MEDMAXT = d3.max(nodes, function (d) {
return d.MEDMAXT;
});
// console.log("Min_ATHCNT", Min_ATHCNT);
// console.log("Max_ATHCNT", Max_ATHCNT);
// console.log("Min_MEDMAXT", Min_MEDMAXT);
// console.log("Max_MEDMAXT", Max_MEDMAXT);
// define custom proportional scale ranges based on zoom scale
var radius_9 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([0.15,0.75]);
var radius_10 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([0.2,1]);
var radius_11 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([0.4,2]);
var radius_12 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([0.75,4]);
var radius_Init = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([0.75,4]);
var radius_14 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([1.15,8]);
var radius_15 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([2.36,16.41]);
var radius_16 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([4.64,32.27]);
var radius_17 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([6.92,48.14]);
var radius_18 = d3.scale.sqrt()
.domain([Min_ATHCNT, Max_ATHCNT])
.range([9.2,64]);
var NoValueColor = '#238b45';
var MinColor = '#4d004b';//#0571b0';
var MinMidColor = '#88419d';//#92c5de';
var MidColor = '#8c96c6';//#f7f7f7';
var MidMaxColor = '#bfd3e6';//#f4a582';
var MaxColor = '#f7fcfd';//#ca0020';
// create quantile color function to map statistic values to colors
var color = d3.scale.threshold()
.domain([6.5, 18.5, 44, 129, 297]) // these values come from jenks classifier
.range([MinColor, MinMidColor, MidColor, MidMaxColor, MaxColor]);
// PROPORTIONAL SYMBOL LEGEND
intersectionLegend.append("circle")
.attr("class", "intersection_legend");
//// PROPORTIONAL SYMBOL LEGEND TEXT
intersectionLegend.append("text")
.attr("class", "intersection_legend")
.style("opacity", 0) // default set to 0
// .attr("transform", "translate(" + (width - 50) + "," + (height + 100) + ")")
.attr("dy", "1.3em")
.text(d3.format(".1s"));
// create intersection variable, node data, append circle, radius scale based on zoom level
var intersection = g.selectAll("circle")
.data(nodes.sort(function(a, b) { return b.ATHCNT - a.ATHCNT; }))
.enter().append("circle")
.attr("id", "intersection")
.style("opacity", 0) // default set to OFF
.attr("fill", function (d) {
return color(d.MEDMAXT);
});
//update function to translate points | Called in zoom end function
function update() {
intersection.attr("transform",
function(d) {
return "translate("+
map.latLngToLayerPoint(d.LatLng).x +","+
map.latLngToLayerPoint(d.LatLng).y +")";
}
)
}
// reset map view on zoom
map.on("viewreset", reset);
// call reset function to realize data paths
reset();
// define reset function
function reset() {
// compute projected bounding box
var bounds = path.bounds(nodes_collection),
topLeft = bounds[0],
bottomRight = bounds[1];
// set SVG dimensions w/ padding to display features
// above or to the left of the origin
svg.attr("width", bottomRight[0] - topLeft[0])
.attr("height", bottomRight[1] - topLeft[1])
.style("left", topLeft[0] + "px")
.style("top", topLeft[1] + "px");
g.attr("transform", "translate(" + -topLeft[0] + "," + -topLeft[1] + ")");
// initialize path data by setting d attribute
intersection.attr("d", "circle");
}
// on zoom end rescale proportional symbols
// also re-translate their coordinates update()
map.on('zoomend', ze);
ze();
function ze() {
var currentZoom = map.getZoom();
//var currentRadius = d3.selectAll('circle').attr("r");
intersectionLegend.selectAll("circle").transition().ease("linear").duration(750)
.style("opacity", 1)
.attr("cy", function (d) {
if (currentZoom == 13)
return "";
else if (currentZoom == 9)
return "";
else if (currentZoom == 10)
return "";
else if (currentZoom == 11)
return "";
else if (currentZoom == 12)
return "";
else if (currentZoom == 14)
return "";
else if (currentZoom == 15)
return "";
else if (currentZoom == 16)
return -radius_16(d);
else if (currentZoom == 17)
return -radius_17(d);
else if (currentZoom == 18)
return -radius_18(d);
})
.attr("r", function (d) {
if (currentZoom == 13)
return "";
else if (currentZoom == 9)
return "";
else if (currentZoom == 10)
return "";
else if (currentZoom == 11)
return "";
else if (currentZoom == 12)
return "";
else if (currentZoom == 14)
return "";
else if (currentZoom == 15)
return "";
else if (currentZoom == 16)
return radius_16(d);
else if (currentZoom == 17)
return radius_17(d);
else if (currentZoom == 18)
return radius_18(d);
});
intersectionLegend.selectAll("text").transition().ease("linear").duration(750)
.attr("y", function(d) {
if (currentZoom == 13)
return "";
else if (currentZoom == 9)
return "";
else if (currentZoom == 10)
return "";
else if (currentZoom == 11)
return "";
else if (currentZoom == 12)
return "";
else if (currentZoom == 14)
return "";
else if (currentZoom == 15)
return "";
else if (currentZoom == 16)
return -2 * radius_16(d);
else if (currentZoom == 17)
return -2 * radius_17(d);
else if (currentZoom == 18)
return -2 * radius_18(d);
})
.text(function(d) {
if (currentZoom == 13)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 9)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 10)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 11)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 12)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 13)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 14)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 15)
return "Circles too small to resolve dynamic legend";
else if (currentZoom == 16)
return d;
else if (currentZoom == 17)
return d;
else if (currentZoom == 18)
return d;
});
intersection.transition().attr("r", function (d) {
if (currentZoom == 13)
return radius_Init(d.ATHCNT);
else if (currentZoom == 9)
return radius_9(d.ATHCNT);
else if (currentZoom == 10)
return radius_10(d.ATHCNT);
else if (currentZoom == 11)
return radius_11(d.ATHCNT);
else if (currentZoom == 12)
return radius_12(d.ATHCNT);
else if (currentZoom == 14)
return radius_14(d.ATHCNT);
else if (currentZoom == 15)
return radius_15(d.ATHCNT);
else if (currentZoom == 16)
return radius_16(d.ATHCNT);
else if (currentZoom == 17)
return radius_17(d.ATHCNT);
else if (currentZoom == 18)
return radius_18(d.ATHCNT);
});
update();
console.log("zoomlevel", currentZoom);
};
});
// select header and left leaflet control
d3.select(".header.leaflet-control")
// append toggle
.append("foreignObject")
.html("<form><input type=checkbox name=toggle id=toggle />Toggle Intersections<label for=toggle></label></form>");
// select toggle, define click function to turn intersections on/off
d3.select("#toggle").on('click', function() {
var active = intersection.active ? false : true;
console.log("active", active);
var newOpacity = active ? 0.6 : 0;
// Hide or show intersections and legend
d3.selectAll("#intersection").style("opacity", newOpacity);
//d3.selectAll(".tooltip").style("opacity", newOpacity)
d3.selectAll(".intersection_legend").style("opacity", newOpacity);
// Update whether or not the elements are active
intersection.active = active;
d3.selectAll("#intersection").on("mouseover", function(d) {
if (active == false)
return
d3.select(this).style("opacity", 1);
tooltip.transition()
.duration(200)
.style("opacity", 1);
tooltip.html("Athlete Count: " + "<b>" + d.ATHCNT + "</b>" + "<br>" + "Median Max Wait Time: " + "<b>" + d.MEDMAXT + " seconds" + "</b>")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
d3.selectAll("#intersection").on("mouseout", function(d) {
if (active == false)
return
d3.select(this).style("opacity", 0.6);
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
});
// select head/ leaflet control, append svg, append
// data group element for proportional symbol legend
var intersectionLegend = d3.select(".header.leaflet-control").append("svg").append("g")
.attr("class", "intersection_legend")
.style("opacity", 0) // default set to 0
.attr("transform", "translate(" + (width - 30) + "," + (height + 100) + ")")
.selectAll("g")
//.data([1, 583, 1912, 3905, 6551, 11185])
.data([800, 6000, 12000])
.enter().append("g");
//// EDGE DATA ////
// bind statistics defined above to select and create an on change function
d3.select("select")
.on("change", function () {
var statistic = this.options[this.selectedIndex].__data__; // get statistics
//console.log("stat", statistic);
// callback function wrapped for loader in 'init' function
function init() {
// trigger loader
var spinner = new Spinner(opts).spin(target);
// slow the json load intentionally, so we can see it every load
//setTimeout(function() {
//// Load 100% GPS VERIFIED DATAS ////
d3.json("data/SF_weekday_total.json", function(error, edges_collection) {
//console.log("collection", collection);
var edge_data = edges_collection.features;
console.log("edges", edge_data);
edge_data.forEach(function(d) {
// unique ID variable not currently in use
d.ID = d.properties.ID;
// define a new stat variable to hold selected stat
d.stat = +d.properties[statistic];
});
var filter = edge_data.filter(function(d) { return (d.stat > 0) });
console.log("filter", filter);
// stop spin.js loader
spinner.stop();
//console.log("d", edge_data);
// create Min, Max, Median, Mean variables for statistics using FILTERED NON-0 Values
var Min = d3.min(filter, function(d) {return d.stat; });
var Max = d3.max(filter, function(d) { return d.stat; });
var Median = d3.median(filter, function(d) { return d.stat; });
var Mean = d3.mean(filter, function(d) { return d.stat; });
console.log("min", Min);
console.log("max", Max);
//console.log("median", Median);
//console.log("mean", Mean);
// CLASSIFY DATAS USING NATURAL BREAKS CLASSIFIER
//var breaks = (ss.jenks(filter.map (function(d) { return d.stat; }), 5));
//console.log("breaks", breaks);
//console.log("statistic", statistic);
// define colors for quantile breaks
var NoValueColor = '#238b45';
var MinColor = '#0571b0';
var MinMidColor = '#92c5de';
var MidColor = '#f7f7f7';
var MidMaxColor = '#f4a582';
var MaxColor = '#ca0020';
// programatic color-data classification mapping | Jenks takes too long to calculate
// var color = d3.scale.threshold()
// .domain([breaks[1], breaks[2], breaks[3], breaks[4]])
// .range([MinColor, MinMedColor, MedianColor, MedMaxColor, MaxColor]);
// create quantile color function to map statistic values to colors
var stat1_color = d3.scale.threshold()
.domain([Min, 2969, 10232, 23272, 43506]) // these values come jenks classifier
.range([NoValueColor, MinColor, MinMidColor, MidColor, MidMaxColor, MaxColor]);
var stat1_color_labels = [Min, 2969, 10232, 23272, 43506, Max];
var stat2_color = d3.scale.threshold()
.domain([Min, 1697, 6237, 14210, 27290]) // these values come jenks classifier
.range([NoValueColor, MinColor, MinMidColor, MidColor, MidMaxColor, MaxColor]);
var stat2_color_labels = [Min, 1697, 6237, 14210, 27290, Max];
var stat3_color = d3.scale.threshold()
.domain([Min, 520, 1798, 3708, 6187]) // these values come jenks classifier
.range([NoValueColor, MinColor, MinMidColor, MidColor, MidMaxColor, MaxColor]);
var stat3_color_labels = [Min, 520, 1798, 3708, 6187, Max];
// create linear function to weight stroke width of edges based on statistic and map zoom
var weightScale_9 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([0.05, 0.1]); // values irrelevant in context of the data
var weightScale_10 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([0.1, .2]); // values irrelevant in context of the data
var weightScale_11 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([0.2, .4]); // values irrelevant in context of the data
var weightScale_12 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([0.4, .8]); // values irrelevant in context of the data
var weightScale_Init = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([0.8, 1.6]); // values irrelevant in context of the data
var weightScale_14 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([1.6, 3.2]); // values irrelevant in context of the data
var weightScale_15 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([3.2, 6.4]); // values irrelevant in context of the data
var weightScale_16 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([6.4, 12.8]); // values irrelevant in context of the data
var weightScale_17 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([12.8, 25.6]); // values irrelevant in context of the data
var weightScale_18 = d3.scale.linear()
.domain(d3.extent(edge_data, function(d) { return d.stat; }))
.range([25.2, 51.2]); // values irrelevant in context of the data
var currentZoom = map.getZoom();
// select all edges, bind data
var appending_edges = g.selectAll("path")
.data(edge_data.sort(function(a, b) { return a.stat - b.stat}));
// enter data, append path, provide "edge" id
appending_edges.enter().append("path")
.attr("id", "edge")
.style("opacity", 0.7);
// make the streets' legend visible on load
d3.select(".legend.leaflet-control").transition().style("opacity", 1);
// make paths transitionable between data views
//appending_edges.transition()
map.on('zoomend', ze);
ze();
function ze() {
var currentZoom = map.getZoom();
appending_edges.transition()
.style("stroke-linecap", "round")
.style("stroke-linejoin", "round")
.style("stroke-width", function (d) {
if (currentZoom == 13)
return weightScale_Init(d.stat);
else if (currentZoom == 10)
return weightScale_10(d.stat);
else if (currentZoom == 11)
return weightScale_11(d.stat);
else if (currentZoom == 12)
return weightScale_12(d.stat);
else if (currentZoom == 14)
return weightScale_14(d.stat);
else if (currentZoom == 15)
return weightScale_15(d.stat);
else if (currentZoom == 16)
return weightScale_16(d.stat);
else if (currentZoom == 17)