-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_bobcatobs.php
2004 lines (1515 loc) · 61.6 KB
/
index_bobcatobs.php
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>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<title>Bobcatobs Demo Site</title>
<?php
include("include/site_keys.php");
?>
<?php
include("include/GA.php");
?>
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> -->
<script src="js/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<!-- Custom fonts for this template -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="vendor/simple-line-icons/css/simple-line-icons.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- Custom styles for this template -->
<link href="css/landing-page.css" rel="stylesheet">
<link rel="stylesheet" href="/leaflet/leaflet.css" />
<script src="/leaflet/leaflet.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/spin.min.js'></script>
<!-- bootstrap-select dropdownup=false -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap-select.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap-select.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<style>
.line {
fill: none;
clip-path: url(#clip);
}
.zoom {
cursor: move;
fill: none;
pointer-events: all;
}
.foo {
float: left;
width: 20px;
height: 20px;
margin: 5px;
border: 1px solid rgba(0, 0, 0, .2);
}
.blue {
background: #13b4ff;
}
.table_nopad table th{
padding:0px;
}
.table_nopad table td{
padding:0px;
}
/* Change Color for Active Tabs */
.nav-pills>li.active>a,
.nav-pills>li.active>a:focus,
.nav-pills>li.active>a:hover,
.nav-pills>li>a:hover,
.nav>li>a:hover {
//background-color: #F47321;
background-color: #135d7c;
border-color: #FFFFFF;
color: #FFFFFF;
}
/* Change Color for Inactive Tabs */
.nav-pills>li>a {
background-color: #777;
border-color: #FFFFFF;
color: #FFFFFF;
}
.nav-pills li {
margin-left: 5px;
margin-top: 3px;
margin-bottom: 3px;
}
.spacer {
margin-top: 10px;
}
.container{
max-width: none !important;
width: 960px;
}
.align-self-center .dropdown {
top: 50%;
transform: translateY(+30%);
}
}
</style>
</head>
<body>
<img style="display:none"/>
<canvas style="display:none" id="canvas" width="1110" height="560"></canvas>
<canvas style="display:none" style="background-color:white;" id="canvas3" width="1110" height="560"></canvas>
<iframe id="my_iframe" style="display:none;"></iframe>
<div class="container">
<div class="row bobcatobs-brand">
<div>
<a href="index_bobcatobs.php">
<img src="img/bobcat2c.png" height="120" width="130"></a>
</div>
<div class="align-self-center">
<a class="text-white" href="index_bobcatobs.php">
<h9>BOBCATOBS Organization<br/>
Office of ...<br/>
... Program</h9></a>
</div>
</div>
<!-- <div class="row" style="background-color:#135d7c;"> -->
<div class="row" style="background-color:#0075ac;">
<div class="col-md-auto align-self-center">
<a class="text-white" href="index_bobcatobs.php">Home </a>
</div>
<div class="col-md-auto align-self-center">
<a class="text-white" href="about_us.php">About Us</a>
</div>
<div class="col-md-auto align-self-center">
<!-- <div class="col-2 col-md-auto align-self-center" style="width: 15%"> -->
<ul class="dropdown">
<a class="dropdown-toggle text-white" data-toggle="dropdown" href="#">About Data</a>
<ul class="dropdown-menu">
<li><a href="about_data.php">Data Background</a></li>
<li><a href="about_data_qaqc.php">Data QAQC</a></li>
<li><a href="about_data_parameters.php">Collected Parameters</a></li>
<li><a href="about_data_metadata.php">Metadata</a></li>
</ul>
</div>
<div class="col-md-auto align-self-center">
<a class="text-white" href="training.php"> Training Resources</a>
</div>
<div class="col-3 align-self-center">
<ul class="dropdown">
<a class="dropdown-toggle text-white" data-toggle="dropdown" href="#">Additional Resources</a>
<ul class="dropdown-menu">
<li><a target="_blank" href="index_bobcatobs.php">Sample link 1</a></li>
<li><a target="_blank" href="index_bobcatobs.php">Sample link 2</a></li>
</ul>
</ul>
</div>
<div class="col-1 align-self-center">
<a class="text-white" href="https://docs.google.com/document/d/15n5OmHxGL3wjz2dYOBI8r2h9ZB5j7-GYeWlsVYhMKwo/edit?usp=sharing" target="_blank">Help</a>
</div>
</div>
<div class="row">
<img src="img/pcreek.jpg" height="160" width="960">
</div>
<div class="row">
<p style="max-height:3px;"></p>
</div>
<div class="row">
<!-- <div class="container choice-main"> -->
<!-- <div class="container col-12"> -->
<!--
<h2>Dynamic Pills</h2>
<p>To make the tabs toggleable, add the data-toggle="pill" attribute to each link. Then add a .tab-pane class with a unique ID for every tab and wrap them inside a div element with class .tab-content.</p>
-->
<ul id="myTab" class="nav nav-pills">
<!-- <li class="nav-item"><a class="nav-link" id="pill1" data-toggle="pill" href="#choose_preserve">Choose Preserve</a></li> -->
<li class="nav-item"><a class="nav-link" id="pill2" data-toggle="pill" href="#choose_station" onclick="clickNavStation();">Choose Station</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="pill" href="#choose_data">Graph Data</a></li>
<!-- <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#get_data" onclick="setupDownloadData();">Download Data</a></li> -->
</ul>
<div class="tab-content">
<div id="choose_preserve" class="tab-pane fade in active">
<div id="map" style="width: 960px; height: 500px"></div>
</div>
<div id="choose_station" class="tab-pane fade">
<?php
include("include/list_station_available_data.php");
?>
<p><i>* Denotes inactive stations</i></p> <!-- custom marker label convention -->
<div id="map_station" style="width: 960px; height: 500px"></div>
</div>
<div id="choose_data" class="tab-pane fade">
<div class="container">
<div class="row">
<p>Select a station, parameter and valid date range using the station parameter and dates available information below. Click 'Add to Graph' to add the chosen data to the graph display below. This process can be repeated to overlay several graphs with differing stations, parameters and date ranges. See the 'Help' link in the page menu above under 'Graph Data' details for additional info.</p>
</div>
<div class="row">
<div class="col-6">
<!-- event listener inputfile script listed later -->
<button onclick="document.getElementById('inputfile').click();">Load platform file</button>
<input id="inputfile" type="file" name="name" style="display: none;" />
<pre id="output"></pre>
</div>
</div> <!-- row -->
<div class="row">
<div id="option_preserve" class="col" style="display: none;">
<select id="preserve_choice">
</select>
</div>
<?php
//include("include/list_dropdown_choose_data.php");
?>
<!-- dynamic selection start, swap this section with php include of dropdowns for fixed application -->
<div class="col">
<p>Platform</p>
<select id="platform_choice"></select>
</div>
<div class="col">
<p>Parameter</p>
<select id="obs_choice"></select>
<!-- dynamic selection end -->
<!-- between currently performed on server-side, todo - add request types or filter results
<p>
<input type="checkbox" id="obs_range">
Between
<input type="text" id="obs_range_start" value="start" onfocus="if (this.value == 'start') { this.value=''; }" style="width: 50px;">and
<input type="text" id="obs_range_stop" value="stop" onfocus="if (this.value == 'stop') { this.value=''; }" style="width: 50px;">
</p>
-->
</div>
<div class="col">
<p><input type="text" id="datepicker_start" onfocus="if (this.value == 'Start Date') { this.value=''; }" width="150"></p>
<p><input type="text" id="datepicker_end" onfocus="if (this.value == 'End Date') { this.value=''; }" width="150"></p>
</div>
<div class="col">
<p><input name="AddToGraphButton"
type="button"
value="Add to Graph"
onclick="updateData();" /></p>
<p><input name="clearGraphButton"
type="button"
value="Clear Graph"
onclick="clearGraph();" /></p>
</div>
</div> <!-- row -->
<?php
include("include/list_param.php");
?>
<div class="row justify-content-start" >
<div id="option_units" class="col-2">
Units
<select id="units_convert">
<option value="metric" selected="selected">Metric</option>
<option value="english">English</option>
</select>
</div>
<div class="col-2">
<input type="checkbox" id="check_fixed_y" onclick="fixedY()" checked=true>
Fixed Y-index
</div>
<div class="col-2">
<input type="checkbox" id="check_fixed_time" onclick="fixedTime()">
Fixed Time-index
</div>
<!-- todo - commenting this out for now till can address better later across possible data sources
<div class="col-2">
<input type="checkbox" id="check_filter_suspect" onclick="filterSuspect()">
Include suspect data
</div>
-->
<div id="save_or_print" class="col-3">
<button onclick="makeGraphImage(1)">Save graph as PNG</button>
<button onclick="makeGraphImage(0)">Print graph</button>
<a hidden id="link_dl">Download</a>
</div>
</div> <!-- row -->
<div id="main_legend" class="graph-legend"> <!-- graph-legend -->
</div> <!-- graph-legend -->
<svg id="svg_display" style="display:none" width="960" height="500"></svg>
</div> <!-- choose_data container -->
</div> <!-- choose_data -->
<div id="get_data" class="tab-pane fade">
</div> <!-- tab-content -->
<!-- </div> <!-- container -->
<!-- </div> <!-- container choice-main -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/gijgo.min.js" type="text/javascript"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/gijgo.min.css" rel="stylesheet" type="text/css" />
<script>
//more compact - but overrides bottom orientation - uiLibrary: 'bootstrap4'
$('#datepicker_start').datepicker({
orientation: 'bottom'
});
document.getElementById("datepicker_start").value = "Start Date";
$('#datepicker_end').datepicker({
orientation: 'bottom'
});
document.getElementById("datepicker_end").value = "End Date";
</script>
<body>
<script>
function makeGraphImage(printOrSave) {
//get elements which will be used to write chart on canvas
var canvas = document.querySelector('canvas');
var svg = document.querySelector('svg');
var img = document.querySelector('img');
// get svg data
var xml = new XMLSerializer().serializeToString(svg);
// make it base64
var svg64 = btoa(xml);
var b64Start = 'data:image/svg+xml;base64,';
// prepend a "header"
var image64 = b64Start + svg64;
// set it as the source of the img element
img.src = image64;
//connect img to arm
var arm = img;
//each legend entry is 48 pixels(was 30px with one line) height so multiply these times obsGraphed to get offset in save/print canvas
//FIX?? the 560 pixel, subtraction is a kludge that seems to work to keep the bottom of the image from getting cropped off with additional graphs
var legendLineHeight = 48;
//wait for the image to be drawn and then draw it on canvas
arm.addEventListener('load', function(){
//draw on canvas
var ctx = canvas3.getContext('2d');
ctx.fillStyle = "#FFF";
ctx.fillRect(0, 0, 1110, 560+obsGraphed*legendLineHeight); //was 38px high at first with one line
//canvas3.getContext('2d').drawImage(img, 0, obsGraphed*30, 1110, 470+obsGraphed*30);
canvas3.getContext('2d').drawImage(img, 0, obsGraphed*legendLineHeight, 1110, 560-obsGraphed*legendLineHeight);
});
//draw the tables on canvas
html2canvas(document.querySelector("#main_legend")).then(canvas => {
//set id to canvas2
canvas.id = "canvas2";
//draw the tables on the canvas
canvas3.getContext('2d').drawImage(canvas, 0, 0, 960, obsGraphed*legendLineHeight);
var canvasFinal = document.getElementById("canvas3");
if (printOrSave == 1) { //save
var link = document.getElementById('link_dl');
var selPlatform = document.getElementById("platform_choice");
var optPlatform = selPlatform.options[selPlatform.selectedIndex];
var dateStart = document.getElementById('datepicker_start').value;
var dateEnd = document.getElementById('datepicker_end').value;
link.setAttribute('download', optPlatform.value+'_'+dateStart+'_'+dateEnd+'.png');
link.setAttribute('href', canvasFinal.toDataURL("image/png").replace("image/png", "image/octet-stream"));
link.click();
}
else if (printOrSave == 0) { //print
let mywindow = window.open('', 'to_print', 'height=600,width=800');
mywindow.document.write(`<html><head><title>bobcatobs Graph</title>`);
//mywindow.document.write('</head><body style="width: 100%; padding:0; margin:0; onload="window.focus(); window.print(); ">');
mywindow.document.write('</head><body style="width: 100%; padding:0; margin:0;">');
//mywindow.document.write(document.getElementById(divId).innerHTML);
mywindow.document.write('<img src="' + canvasFinal.toDataURL("image/png") + '" /></body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
//mywindow.close();
}
});
}
</script>
<script>
//custom setView
var myMap = L.map('map').setView([29.3387649,-83.0563767],6);
L.tileLayer(
//'http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
//attribution: '© ' + mapLink + ' Contributors',
maxZoom: 18,
accessToken: leaflet_key
}).addTo(myMap);
//custom setView
var myMapStation = L.map('map_station').setView([29.3387649,-83.0563767],5); //custom earlier version zoom = 6
//mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
//attribution: '© ' + mapLink + ' Contributors',
maxZoom: 18,
accessToken: leaflet_key
}).addTo(myMapStation);
function addMapMarker(myStringArray,mapType) {
var arrayLength = myStringArray.length;
var loopCtr = 0;
for (var i = 0; i < arrayLength; i = i +3) {
//alert(myStringArray[i]+":"+myStringArray[i+1]+":"+myStringArray[i+2]);
loopCtr++;
var strMarker =mapType+loopCtr+" = undefined";
//Declaring and Setting dynamic variable to undefined using eval
eval(strMarker);
if (mapType == 'station') {
strMarker = L.marker([myStringArray[i],myStringArray[i+1]]).addTo(myMapStation).on('click', onClickStation);
strMarker.bindTooltip(myStringArray[i+2],
{
permanent: false,
direction: 'right'
}
);
}
if (mapType == 'preserve') {
str = L.marker([myStringArray[i],myStringArray[i+1]]).addTo(myMap).on('click', onClickPreserve);
/*
var icon = str.options.icon;
icon.options.iconSize = [10, 10];
str.setIcon(icon);
*/
var labelDir = 'left';
//custom
if (myStringArray[i+2] == 'Indian River Lagoon' || myStringArray[i+2] == 'Northeast' || myStringArray[i+2] == 'Estero Bay') {labelDir = 'right';}
str.bindTooltip(myStringPreserveArray[i+2],
{
permanent: false,
direction: labelDir
}
);
}
}
}
var myStringPreserveArray = [
<?php
include("include/list_preserve.php");
?>
];
addMapMarker(myStringPreserveArray,'preserve');
var myStringStationArray = [
<?php
//include("include/list_station.php");
?>
];
addMapMarker(myStringStationArray,'station');
//var tabPreserveNum = 1;
//var tabStationNum = 2;
//var tabGraphNum = 3;
var tabStationNum = 1;
var tabGraphNum = 2;
$(document).ready(function(){
//$('#myTab li:nth-child('+tabPreserveNum+') a').tab('show');
$('#myTab li:nth-child('+tabStationNum+') a').tab('show');
setTimeout(function() {
myMapStation.invalidateSize(true);
}, 400);
});
//end default start/reload webpage
function onClickPreserve(e) {
//alert(e.target._tooltip._content);
//document.getElementById("platform_choice").value = e.target._tooltip._content;
$(document).ready(function(){
<?php
include("include/click_preserve.php");
?>
//document.getElementById("pill1").innerHTML = "Choose Preserve<br/>"+e.target._tooltip._content;
document.getElementById("pill2").innerHTML = "Choose Station";
$('#myTab li:nth-child('+tabStationNum+') a').tab('show');
setTimeout(function() {
myMapStation.invalidateSize(true);
}, 400);
}); //readyfunction
} //onClickPreserve
//handle click on station map placemark
function onClickStation(e) {
$(document).ready(function(){
var stationPick;
//alert(e.target._tooltip._content.substring(0,4));
//default
stationPick = e.target._tooltip._content;
<?php
include("include/click_station.php");
?>
//document.getElementById("platform_choice").value = stationPick;
changeStation(stationPick,0);
//document.getElementById("pill2").innerHTML = "Choose Station<br/>"+e.target._tooltip._content;
$('#myTab li:nth-child('+tabGraphNum+') a').tab('show');
});
}
//handle click on station map list
$(document).ready(function() {
$( "#stationtable tbody tr" ).on( "click", function( event ) {
var stationTableSel = $(this).find("th").eq(0).html();
//document.getElementById("platform_choice").value = stationTableSel;
changeStation(stationTableSel,0);
//document.getElementById("pill2").innerHTML = "Choose Station<br/>"+$(this).find("th").eq(0).html()+' '+$(this).find("td").eq(0).html();
$('#myTab li:nth-child('+tabGraphNum+') a').tab('show');
});
});
</script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
//==forward to station page/graph if station url param present - only useful where webpage station/params dropdowns are pre-populated
var strJSONConfig = '';
var objJSONConfig;
<?php
$params = $_REQUEST;
$json_link = isset($params['json_link']) && $params['json_link'] !='' ? $params['json_link'] : 'none';
$station = isset($params['station']) && $params['station'] !='' ? $params['station'] : 'none';
if ($json_link != 'none') {
//swap back in & symbol in our passed/formatted url to get
$json_link = str_replace("zzz","&",$json_link);
try {
$json_config = @file_get_contents($json_link);
if ($json_config === false) {
// Handle the error
echo 'swal("JSON file failed to load");';
}
} catch (Exception $e) {
// Handle exception
}
if ($json_config) {
echo 'strJSONConfig = '.$json_config.';';
}
}
?>
if (strJSONConfig != '') {
strJSONConfig = JSON.stringify(strJSONConfig); //have to stringify to later validate object with JSON.parse which returns object?
loadJSON(strJSONConfig);
}
var urlStation = '<?php echo $station ?>';
$(document).ready(function() {
if (urlStation != 'none') {
changeStation(urlStation,0);
$('#myTab li:nth-child('+tabGraphNum+') a').tab('show');
}
});
//===========================================================
var obsValue = 'none';
var obsTitle = 'none';
var platformTitle = 'none';
var timeValue = 'none';
var flagFixedY = 1;
var flagFilterSuspect = 0;
var flagFilterSuspectText = '';
var flagObsRangeText = '';
var flagFixedTime = 0;
var yMin;
var yMax;
listStations('none'); //clear station list on choose station page
listParams('none'); //clear param list on choose data page
document.getElementById("save_or_print").style.display = "none";
var svg = d3.select("svg"),
margin = {top: 10, right: 10, bottom: 110, left: 40},
margin2 = {top: 430, right: 10, bottom: 30, left: 40},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom,
height2 = +svg.attr("height") - margin2.top - margin2.bottom;
//custom
//var parseTime = d3.timeParse("%Y-%m-%d %H:%M:%S"); //RDB
//var parseTime = d3.timeParse("%Y-%m-%dT%H:%M:%S%Z"); //ERDDAP
var parseTime; //will be defined with each graph dataSourceType
//console.log("width", width);
//console.log("height", height);
var x = d3.scaleTime().range([0, width]),
x2 = d3.scaleTime().range([0, width]),
y = d3.scaleLinear().range([height, 0]),
y2 = d3.scaleLinear().range([height2, 0]),
z = d3.scaleOrdinal(d3.schemeCategory10);
var xAxis = d3.axisBottom(x)
.ticks(5)
.tickFormat(d3.timeFormat("%Y-%m-%d %I%p")),
xAxis2 = d3.axisBottom(x2)
.tickFormat(d3.timeFormat("%Y-%m-%d")),
yAxis = d3.axisLeft(y);
var brush = d3.brushX()
.extent([[0, 0], [width, height2]])
.on("brush end", brushed);
var zoom = d3.zoom()
.scaleExtent([1, Infinity])
.translateExtent([[0, 0], [width, height]])
.extent([[0, 0], [width, height]])
.on("zoom", zoomed);
var line = d3.line()
//.curve(d3.curveLinear)
//.defined(function(d) { return d; })
.defined(function(d) { return !isNaN(d.value); })
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.value); });
var line2 = d3.line()
.defined(function(d) { return !isNaN(d.value); })
.x(function(d) { return x2(d.date); })
.y(function(d) { return y2(d.value); });
svg.append("defs").append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width)
.attr("height", height);
var obs;
var focus = svg.append("g")
.attr("class", "focus")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); //this took forever to figure out - commenting out from original
//.attr("transform", "translate(" + margin.left + ",20)");
var context = svg.append("g")
.attr("class", "context")
.attr("transform", "translate(" + margin2.left + "," + margin2.top + ")");
//.attr("transform", "translate(0," + margin2.top + ")");
//interactive graph
var mouseG = svg.append("g")
.attr("class", "mouse-over-effects")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var obsData = [];
//var colorSet = ["#001c9c","#101b4d","#475003","#9c8305","#d3c47c"];
//custom
var colorSet = ["#00FF00","#0000FF","#FF0000","#B2912F","#DECF3F","#CC3300","#000000","#00FFFF","#FF00FF"]; //red,blue,green,purple,orange - colors here acting wonky, seem to be influencing each other
//var colorSet = ["#5899DA","#E8743B","#19A979","#ED4A7B","#945ECF","#13A4B4","#525DF4i","#BF399E","#6C8893","#EE6868","#2F6497"]; //red,blue,green,purple,orange - colors here acting wonky, seem to be influencing each other
//var colorSet = ["","","","","","","","","",]; //red,blue,green,purple,orange - colors here acting wonky, seem to be influencing each other
var colorChoice;
var yIndexNum;
var yIndexAdd;
var yIndexWidth;
var obsGraphed; //count of obsGraphed
var paramGraphed; //array used to keep track of what's been graphed already to know whether we need another y-index(with fixed y-index option)
var yMultiMin;
var yMultiMax;
var checkGraph;
var graphData; //array used to hold plot values for csv download later
var textLegendText;
var strLegendText;
//json lookups for processing data to common form
var dataSourceType;
var objPlatform;
var sourceRefObs;
var sourceUrl;
var sourceUrlPrev;
var strTimeParse;
var evalCode;
clearGraph();
//custom
//add graph line break 'NA' values when data gaps
var dGapBreak = 60000; //time in milliseconds to place break 'NA' value
//var dGapThresh = 1800000+dGapBreak; //time in milliseconds = 30 min+1 minute, over thresh creates line break
var dGapThresh = 10800000+dGapBreak; //time in milliseconds = 3 hours+1 minute, over thresh creates line break
function graphObs(data) {
//==trim array to remove elements outside of date selected range - mainly for static CSV files without dynamic query
var dataRangeTime = [];
//var t0 = performance.now();
data.forEach(function(d) {
if (d.m_date != null && d.m_date.getTime() >= startDateMilli && d.m_date.getTime() <= endDateMilli) { dataRangeTime.push(d); }
});
//var t1 = performance.now();
//console.log(t1-t0);
data = dataRangeTime.slice();
if (data.length === 0) { swal("No data available"); return; }
//==
colorChoice++;
if (colorChoice > 8) { colorChoice = 0; }
obsGraphed++;
//add another yIndex offset for different obs than last
//console.log(paramGraphed.indexOf(obsValue))
//add unitSuffix to differentiate between metric/english plot refs
unitSuffix = document.getElementById('units_convert').value;
//add new yIndex if new param
if (((paramGraphed.indexOf(obsValue+unitSuffix) == -1) && flagFixedY) || !flagFixedY) {
paramGraphed.push(obsValue+unitSuffix);
yIndexAdd = true;
yIndexNum++;
//width = width - yIndexWidth;
width = width + yIndexWidth;
if (obsGraphed <= 1) { //add right margin display for mouse-over, once only at beginning
width = width + 160;
}
d3.selectAll("svg")
.attr("width",width);
//reset yMin,yMax
//yMin = null; yMax = null;
}
//==map data - this section more to support CSV file with multiple parameters/keys in array at once - not really necessary where only querying one parameter at a time with other data sources
var useColumn = obsValue;
var varNames = d3.keys(data[0])
.filter(function (key) { return key == useColumn;}); //pull/process just what specified in useColumn to object key
obs = varNames.map(function (id) { //declared global for brush function
return {
id: id,
values: data.map(function (d) {
return {date: d.m_date, value: d[id]};
})
};
});
//console.log("Initial Data", obs);
//dont change x-axis if graphing suspect data overlay
if (flagFilterSuspect == 0) {
//if (flagFilterSuspect == 0 && obsGraphed == 1) {
x.domain(d3.extent(data, function(d) { return d.m_date; }));
x2.domain(x.domain());
}
//console.log("yMin", yMin);
//console.log("yMax", yMax);
if (!flagFixedY || yMin == null || yMax == null) {
yMin = d3.min(obs, function(c) { return d3.min(c.values, function(d) { return d.value; }); }),
yMax = d3.max(obs, function(c) { return d3.max(c.values, function(d) { return d.value; }); })
}
y.domain([unitsConvert(yMin),unitsConvert(yMax)]);
//support multi-y-axis
yMultiMin[obsGraphed] = unitsConvert(yMin);
yMultiMax[obsGraphed] = unitsConvert(yMax);
y2.domain(y.domain());
z.domain(obs.map(function(c) { return c.id; }));
//y-axis
if (yIndexAdd) {
focus.append("g")
.attr("class", "axis axis--y")
.attr("transform", "translate("+(yIndexNum-1)*-1*yIndexWidth+",0)")
//.attr("transform", "translate(-30,0)")
.call(d3.axisLeft(y))
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("fill", "#000")
.text(obsTitle);
yIndexAdd = false;
}
//create line
//https://stackoverflow.com/questions/24825145/black-area-when-exporting-graph-from-svg-d3-js-to-jpg
//have to include fill none directly for svg to export
focus.append("path")
.data(obs)
.attr("class", "line ymulti"+obsGraphed)
.attr("opacity", "1")
.attr("fill", "none")
.attr("d", function(d) {
var dTimePrev;
var dTimeBreak;
var dGap = [];
for (var i = 0; i < d.values.length; i++) {
if (i == 0) { dTimePrev = d.values[i].date; }
if (d.values[i].value == 0) { continue; } //remove null return values from erddap, FIX? depending on no actual param values at exactly 0
//below lines fixed by dataRangeTime array filter at start of graphObs
//if (d.values[i].date == null) { continue; } //FIX? problem with CSV testing
//cut out values from CSV that might be outside selected time range
//if (d.values[i].date.getTime() < startDateMilli) { dTimePrev = d.values[i].date; continue; }
//if (d.values[i].date.getTime() > endDateMilli) { continue; }
//console.log('i'+i+":time:"+d.values[i].date.getTime());
//console.log('i'+i+":time:",d.values[i]);
if (d.values[i].date.getTime() - dTimePrev > dGapThresh) {
//console.log('gap');
var dGapTemp = { date: dTimeBreak, value: 'NA'};
dGap.push(dGapTemp);
}
dTimePrev = d.values[i].date.getTime();
dTimeBreak = new Date(dTimePrev+dGapBreak); //create line break
//console.log("dvadate"+d.values[i].date.getTime());
//console.log("dva:"+d.values[i].value);
d.values[i].value = unitsConvert(d.values[i].value);
dGap.push(d.values[i]);
}
//create array x, pushed onto array graphData for later download if needed - FIX - merge/move into 1st processing loop when 1st entering graphObs - only loop through data once - currently loop 3 times - once for time range, once for gaps, once for download
//comma will render object in debug
//https://stackoverflow.com/questions/957537/how-can-i-display-a-javascript-object
//console.log("dGap:",dGap);
const objArrdGap = Object.entries(dGap); //Fix to use just regular js object notaction instead of indexing
//filter out the index keys(every other element) in array
//var x = objArrdGap.filter((value,index,arr) => {
//return index % 2 === 0;
//})
//var x = [['datetime(EST)','value']];
var x = [['datetime','value']];
for(i = 0 ; i < objArrdGap.length; i++) {
//https://stackoverflow.com/questions/8362952/javascript-output-current-datetime-in-yyyy-mm-dd-hhmsec-format
//const offsetMs = now.getTimezoneOffset() * 60 * 1000;
//const offsetMs = 5 * 60 * 60 * 1000; //FIX? check? database time values timezone?
const offsetMs = 0; //FIX? check? database time values timezone?
const dateLocal = new Date(Object.entries(objArrdGap[i][1])[0][1] - offsetMs);
const date_formatted = dateLocal.toISOString().slice(0, 19).replace(/-/g, "/").replace("T", " ");