-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcali_2loadcell_2sucmoist_2moist_2saltrh_2sucheat.html
818 lines (670 loc) · 31.5 KB
/
cali_2loadcell_2sucmoist_2moist_2saltrh_2sucheat.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
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
<!DOCTYPE html>
<!--
https://bl.ocks.org/d3noob/4db972df5d7efc7d611255d1cc6f3c4f
-->
<meta charset="utf-8">
<style> /* set the CSS */
body { font: 12px Arial;}
/* global properties for the plot line properties */
path {
stroke: steelblue;
stroke-width: 3;
fill: none;
}
.axis { font: 18px sans-serif; }
.axis path,
/*<-- global properties for the axes properties--> */
/* be careful about the new comment styles */
.axis line {
fill: none;
stroke: black;
stroke-width: 3;
shape-rendering: crispEdges;
}
.legend {
font-size: 16px;
font-weight: bold;
text-anchor: middle;
}
/*below is function to make grid */
.grid .tick {
stroke: lightgrey;
opacity: 0.7;
}
.grid path {
stroke-width: 0;
}
/*above is function to make grid */
</style>
<body>
<!-- load the d3.js library -->
<!-- EXTERNAL LIBS-->
<script src="https://d3js.org/d3.v4.min.js"></script>
<!--
<script>
// -----------------------below is to draw current setup of the experiment -------------------
var width_uq = 1350,
height_uq = 100;
var svg_uq = d3.select("body").append("svg")
.attr("width", width_uq)
.attr("height", height_uq)
.style("border", "0px solid black");
var g_uq = svg_uq.append("g");
var text_2 = svg_uq.selectAll("text")
.data([0])
.enter()
.append("text")
.text("Calibration of soil sensors undertaking at the 1st floor geotechnical laboratory")
.style("font-size", "30px")
.attr("x", "0")
.attr("y", "65");
var img = g_uq.append("svg:image")
.attr("xlink:href", "https://outbox.eait.uq.edu.au/uqczhan2/photo_geo_1st/UQ.jpg")
.attr("width", 200)
.attr("height", 200)
.attr("x", 1100)
.attr("y",-50);
// -----------------------above is to draw current setup of the experiment -------------------
</script>
-->
<!-- a container with the headlines and descreptions
http://bl.ocks.org/Matthew-Weber/5645518
-->
<div id="container">
<p id="headline" class="hed" style="font-size:30px">Calibration of soil sensors undertaking at the 1st floor geotechnical laboratory
<img src="https://outbox.eait.uq.edu.au/uqczhan2/photo_geo_1st/UQ.jpg" align="right" style="width:400px;height:122px;"> </p>
<p class="dek" style="font-size:25px">Description</p>
<p class="dek" style="font-size:17px"> The experiment involves calibrating four soil sensors: (1) soil moisture sensors based on dielectrical resistivity principle
(2) soil suction sensor based on dielectrical resistivity, (3) soil suction sensor based on heat dissipation, and (4) soil salinity sensor based on relative humidity. </p>
<p class="dek" style="font-size:17px">The calibration of moisture sensor is conducted by the volumetric moisture content derived from scale weight reading, with the moisture cotent obtain by sensor reading.
the suction sensor can be calibrated using similar principle with soil water retention curve obtained from Fredlund Pressure Cell. </p>
</div>
<script>
// -------------------------- below is the function to creat grid lines ---------------
// gridlines in x axis function
function make_x_gridlines(x_ax) {
return d3.axisBottom(x_ax)
.ticks(5)
}
// gridlines in y axis function
function make_y_gridlines(y_ax) {
return d3.axisLeft(y_ax)
.ticks(5)
}
// -------------------------- above is the function to creat grid lines ---------------
// below is needed to initializating the picture
// Set the dimensions of the canvas / graph
// right determins the space for writting things
var margin = {top: 40, right: 100, bottom: 100, left: 110},
width = 1300 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var key_mo=["mo_7","mo_8","mo_9","mo_10"];
var key_temp=["suht_28e5_begin","suht_28e5_peak","suht_28e5_end","suht_2847_begin","suht_2847_peak","suht_2847_end","saltrh_2_tp","saltrh_3_tp"];
var act_mo=[];
var act_temp=[];
var legendSpace_mo = width/ key_mo.length
var legendSpace_temp = width/ key_temp.length
var format = d3.timeParse('%Y-%m-%dT%H:%M:%S.%LZ')
//tenHourslater = d3.time.hour.offset(d, 10)
// Set the ranges
var x_mo = d3.scaleTime().range([0, width]);
var y_mo = d3.scaleLinear().range([height, 0]);
var x_temp = d3.scaleTime().range([0, width]);
var y_temp = d3.scaleLinear().range([height, 0]);
// ---------Define the line for moisture
var valueline_mo=[];
key_mo.forEach(function(d,i) {
valueline_mo[i]=d3.line()
.x(function(d) { return x_mo(d.timestamp); })
.y(function(d) { return y_mo(d[key_mo[i]]); });
})
//// Define the line for moisture
var valueline_temp=[];
key_temp.forEach(function(d,i) {
valueline_temp[i]=d3.line()
.x(function(d) { return x_temp(d.timestamp); })
.y(function(d) { return y_temp(d[key_temp[i]]); });
})
// ----------------------draw picture for the entire setup ---------------------
var svg_pic = d3.select("body")
.append("svg")
.attr("width", 1280)
.attr("height", 1124)
.style("border", "0px solid black");
var text = svg_pic.selectAll("text")
.data([0])
.enter()
.append("text")
.text("Experimental Setup")
.style("font-size", "25px")
.attr("x", "0")
.attr("y", "20");
var imgs = svg_pic.selectAll("image").data([0]);
imgs.enter()
.append("svg:image")
.attr("xlink:href", "https://outbox.eait.uq.edu.au/uqczhan2/photo_geo_1st/setup.PNG")
.attr("x", "00")
.attr("y", "30")
.attr("width", "1280")
.attr("height", "1024");
// ----------------------draw picture for the entire setup ---------------------
var svg_pic_realtime = d3.select("body")
.append("svg")
.attr("width", 1280)
.attr("height", 1124)
.style("border", "0px solid black");
var text = svg_pic_realtime.selectAll("text")
.data([0])
.enter()
.append("text")
.text("Real-time snapshot of tailings surface")
.style("font-size", "25px")
.attr("x", "0")
.attr("y", "20");
var imgs = svg_pic_realtime.selectAll("image").data([0]);
imgs.enter()
.append("svg:image")
.attr("xlink:href", "https://outbox.eait.uq.edu.au/uqczhan2/photo_geo_1st/2017_02_09_12_58_geo_1st.jpg")
.attr("x", "00")
.attr("y", "50")
.attr("width", "1280")
.attr("height", "924");
svg_pic_realtime.append("text")
.text("Real-time results")
.style("font-size", "25px")
.attr("x", "0")
.attr("y", "1100");
// Adds the svg canvas
var svg_mo = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
var svg_temp = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// ---------------------below is data defination for the delta temp --------------------------
var key_del_temp=["del_temp_28e5_heating","del_temp_28e5_cooling","del_temp_2847_heating","del_temp_2847_cooling"];
var act_del_temp=[];
var legendSpace_del_temp = width/ key_del_temp.length;
var x_del_temp = d3.scaleTime().range([0, width]);
var y_del_temp = d3.scaleLinear().range([height, 0]);
//// Define the line for moisture
var valueline_del_temp=[];
key_del_temp.forEach(function(d,i) {
valueline_del_temp[i]=d3.line()
.x(function(d) { return x_del_temp(d.timestamp); })
.y(function(d) { return y_del_temp(d[key_del_temp[i]]); });
})
var svg_del_temp = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// ---------------------above is data defination for the delta temperature --------------------------
// ---------------------below is data defination for the relative humidity sensor --------------------------
var key_rh=["saltrh_2_rh","saltrh_3_rh"];
var act_rh=[];
var legendSpace_rh = width/ key_rh.length;
var x_rh = d3.scaleTime().range([0, width]);
var y_rh = d3.scaleLinear().range([height, 0]);
//// Define the line for moisture
var valueline_rh=[];
key_rh.forEach(function(d,i) {
valueline_rh[i]=d3.line()
.x(function(d) { return x_rh(d.timestamp); })
.y(function(d) { return y_rh(d[key_rh[i]]); });
})
var svg_rh = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// ---------------------above is data defination for the relative humidity sensor --------------------------
// ---------------------below is data defination for load cell -----------------------------
var key_scale=["tas606","te"];
var act_scale=[];
var legendSpace_scale = width/ key_scale.length
var format_scale = d3.timeParse('"%Y-%b-%d %H:%M:%S"')
var float_to_string=String.valueOf()
// Set the ranges
var x_scale = d3.scaleTime().range([0, width]);
var y_scale = d3.scaleLinear().range([height, 0]);
//// Define the line for scaleisture
var valueline_scale=[];
key_scale.forEach(function(d,i) {
valueline_scale[i]=d3.line()
.x(function(d) { return x_scale(d.measure_local_time); })
.y(function(d) { return y_scale(d[key_scale[i]]); });
})
// Adds the svg canvas
var svg_scale = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// ---------------------above is data defination for load cell -----------------------------
// ----------------------below is to obtain the data from the sensors------------------------------
var data1;
var url = "https://data.sparkfun.com/output/9J2rX3QZ94s5RJ9LjrbN.json"
d3.json(url, function (error,json) {
//if (error) return console.warn(error);
if (error) throw error;
json.forEach(function(d) {
//d.timestamp = format(d.timestamp);
d.timestamp = d3.timeHour.offset(format(d.timestamp),+10); // http://stackoverflow.com/questions/18796291/d3-get-current-time-and-subtract-by-2-hours
d.del_temp_28e5_heating=d.suht_28e5_peak-d.suht_28e5_begin;
d.del_temp_28e5_cooling=d.suht_28e5_peak-d.suht_28e5_end;
d.del_temp_2847_heating=d.suht_2847_peak-d.suht_2847_begin;
d.del_temp_2847_cooling=d.suht_2847_peak-d.suht_2847_end;
//dataset.date = parseDate(d.date);
//dataset.close = +d.close;
//if (d.saltrh_3_tp == "NaN") {d.saltrh_3_tp=NaN}
//if (d.saltrh_3_rh == "NaN") {d.saltrh_3_rh=NaN}
});
data1=json;
console.log(data1)
// console.log(active1)
// http://stackoverflow.com/questions/10024866/remove-object-from-array-using-javascript
// remove all lines that has NaN
data1=data1.filter(function(el){
return el.saltrh_3_rh != "NaN";
});
console.log(JSON.stringify(data1, null, ' '));
// ----------------------above is to obtain the data ------------------------------
//-------------------below are for moisture sensor plot-------------------
x_mo.domain(d3.extent(data1, function(d) { return d.timestamp; }));
//y_mo.domain([200, d3.max(data1, function(d) { return d.mo_10; })]);
y_mo.domain([300, 550]);
//var color = d3.scaleOrdinal(d3.schemeCategory10);
var color = d3.scaleOrdinal(d3.schemeCategory20);
key_mo.forEach(function(d,i) {
svg_mo.append("path")
.attr("class", "line")
// .attr("stroke-width", 20)
.style("stroke", color(key_mo[i]))
.attr("d", valueline_mo[i](data1))
.attr("id", 'tag'+key_mo[i].replace(/\s+/g, '')); // assign id **
svg_mo.append("text")
.attr("x", (legendSpace_mo/2)+i*legendSpace_mo) // space legend
.attr("y", -20 )
//.attr("y", height + (margin.bottom/2)+ 5)
.attr("class", "legend") // style the legend
.style("fill", color(key_mo[i]))
.on("click", function(){ // ************
// Determine if current line is visible
var active = act_mo[i] ? false : true, // ************
newOpacity = active ? 0 : 1; // ************
// Hide or show the elements based on the ID
d3.select("#tag"+key_mo[i].replace(/\s+/g, '')) // *********
.transition().duration(100) // ************
.style("opacity", newOpacity); // ************
// Update whether or not the elements are active
act_mo[i] = active; // ************
}) // ************
.text(key_mo[i]);
});
// Add the X Axis
svg_mo.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x_mo));
// text label for the x axis
svg_mo.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.top + 10) + ")")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("TIME");
// Add the Y Axis
svg_mo.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y_mo));
// text label for the y axis
svg_mo.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("MOISTURE SENSOR READING");
// draw grid lines
svg_mo.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(make_x_gridlines(x_mo)
.tickSize(-height, 0, 0)
.tickFormat("")
)
svg_mo.append("g")
.attr("class", "grid")
.call(make_y_gridlines(y_mo)
.tickSize(-width, 0, 0)
.tickFormat("")
)
//---------------------------- below are to plot temperature sensors ----------------------
//x_temp.domain(d3.extent(data1, function(d) { return d.timestamp; }));
x_temp.domain(d3.extent(data1, function(d) { return d.timestamp; }));
// y_temp.domain([0, d3.max(data1, function(d) { return d.tp1; })]);
//y_temp.domain([20, d3.max(data1, function(d) { return d.suht_2847_begin; })]);
y_temp.domain([22, 65]);
var color_temp = d3.scaleOrdinal(d3.schemeCategory10);
key_temp.forEach(function(d,i) {
svg_temp.append("path")
.attr("class", "line")
.style("stroke", color_temp(key_temp[i]))
.attr("d", valueline_temp[i](data1))
.attr("id", 'tag'+key_temp[i].replace(/\s+/g, '')); // assign id **
svg_temp.append("text")
.attr("x", (legendSpace_temp/2)+i*legendSpace_temp) // space legend
.attr("y", -20 )
//.attr("y", height + (margin.bottom/2)+ 5)
.attr("class", "legend") // style the legend
.style("fill", color_temp(key_temp[i]))
.on("click", function(){ // ************
// Determine if current line is visible
var active = act_temp[i] ? false : true, // ************
newOpacity = active ? 0 : 1; // ************
// Hide or show the elements based on the ID
d3.select("#tag"+key_temp[i].replace(/\s+/g, '')) // *********
.transition().duration(100) // ************
.style("opacity", newOpacity); // ************
// Update whether or not the elements are active
act_temp[i] = active; // ************
}) // ************
.text(key_temp[i]);
});
// Add the X Axis
svg_temp.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x_temp));
// // Add the Y Axis
svg_temp.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y_temp));
// text label for the y axis
svg_temp.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("TEMPERATURE (CELSIUS)");
// text label for the x axis
svg_temp.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.top + 10) + ")")
.style("text-anchor", "middle")
.style("font-size", "20px")
.text("TIME");
// draw grid lines
svg_temp.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(make_x_gridlines(x_temp)
.tickSize(-height, 0, 0)
.tickFormat("")
)
svg_temp.append("g")
.attr("class", "grid")
.call(make_y_gridlines(y_temp)
.tickSize(-width, 0, 0)
.tickFormat("")
)
//---------------------------- below are for delta temperature ----------------------
x_del_temp.domain(d3.extent(data1, function(d) { return d.timestamp; }));
y_del_temp.domain([0, 30]);
var color_del_temp = d3.scaleOrdinal(d3.schemeCategory10);
key_del_temp.forEach(function(d,i) {
svg_del_temp.append("path")
.attr("class", "line")
.style("stroke", color_del_temp(key_del_temp[i]))
.attr("d", valueline_del_temp[i](data1))
.attr("id", 'tag'+key_del_temp[i].replace(/\s+/g, '')); // assign id **
svg_del_temp.append("text")
.attr("x", (legendSpace_del_temp/2)+i*legendSpace_del_temp) // space legend
.attr("y", -20 )
// .attr("y", height + (margin.bottom/2)+ 45)
.attr("class", "legend") // style the legend
.style("fill", color_del_temp(key_del_temp[i]))
.on("click", function(){ // ************
// Determine if current line is visible
var active = act_del_temp[i] ? false : true, // ************
newOpacity = active ? 0 : 1; // ************
// Hide or show the elements based on the ID
d3.select("#tag"+key_del_temp[i].replace(/\s+/g, '')) // *********
.transition().duration(100) // ************
.style("opacity", newOpacity); // ************
// Update whether or not the elements are active
act_del_temp[i] = active; // ************
}) // ************
.text(key_del_temp[i]);
});
// Add the X Axis
svg_del_temp.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x_del_temp));
// text label for the x axis
svg_del_temp.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.top + 40) + ")") // location of x axis
.style("text-anchor", "middle")
.style("font-size", "20px")
.text("TIME");
// Add the Y Axis
svg_del_temp.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y_del_temp));
// text label for the y axis
svg_del_temp.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("TEMPERATURE DIFFERENCE (CELSIUS)");
// draw grid lines
svg_del_temp.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(make_x_gridlines(x_del_temp)
.tickSize(-height, 0, 0)
.tickFormat("")
)
svg_del_temp.append("g")
.attr("class", "grid")
.call(make_y_gridlines(y_del_temp)
.tickSize(-width, 0, 0)
.tickFormat("")
)
// --------------------------above is for delta temperature -----------------------
//---------------------------- below are for humidity sensor ----------------------
x_rh.domain(d3.extent(data1, function(d) { return d.timestamp; }));
y_rh.domain([45, 105]);
var color_rh = d3.scaleOrdinal(d3.schemeCategory10);
key_rh.forEach(function(d,i) {
svg_rh.append("path")
.attr("class", "line")
.style("stroke", color_rh(key_rh[i]))
.attr("d", valueline_rh[i](data1))
.attr("id", 'tag'+key_rh[i].replace(/\s+/g, '')); // assign id **
svg_rh.append("text")
.attr("x", (legendSpace_rh/2)+i*legendSpace_rh) // space legend
.attr("y", -20 )
// .attr("y", height + (margin.bottom/2)+ 45)
.attr("class", "legend") // style the legend
.style("fill", color_rh(key_rh[i]))
.on("click", function(){ // ************
// Determine if current line is visible
var active = act_rh[i] ? false : true, // ************
newOpacity = active ? 0 : 1; // ************
// Hide or show the elements based on the ID
d3.select("#tag"+key_rh[i].replace(/\s+/g, '')) // *********
.transition().duration(100) // ************
.style("opacity", newOpacity); // ************
// Update whether or not the elements are active
act_rh[i] = active; // ************
}) // ************
.text(key_rh[i]);
});
// Add the X Axis
svg_rh.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x_rh));
// text label for the x axis
svg_rh.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.top + 40) + ")") // location of x axis
.style("text-anchor", "middle")
.style("font-size", "20px")
.text("TIME");
// Add the Y Axis
svg_rh.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y_rh));
// text label for the y axis
svg_rh.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("RELATIVE HUMIDITY (PERCENT)");
// draw grid lines
svg_rh.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(make_x_gridlines(x_rh)
.tickSize(-height, 0, 0)
.tickFormat("")
)
svg_rh.append("g")
.attr("class", "grid")
.call(make_y_gridlines(y_rh)
.tickSize(-width, 0, 0)
.tickFormat("")
)
// --------------------------above is for relative humidity sensor -----------------------
})
// ------------------------ below is to obtain the load cell data ------------------------
var data_scale;
var url_scale = "https://data.sparkfun.com/output/KJo3Nx8grJcMDpEWQOXg.json"
d3.json(url_scale, function (error,json) {
if (error) return console.warn(error);
json.forEach(function(d) {
d.measure_local_time = format_scale(d.measure_local_time);
d.tas606=d.tas606/16.73;
d.te=(d.te-104)/0.00597;
});
data_scale=json;
console.log(data_scale)
x_scale.domain(d3.extent(data_scale, function(d) { return d.measure_local_time; }));
y_scale.domain([10000,12200]);
// ------------------------ above is to obtain the load cell data ------------------------
// --------------------------below is for load cell sensor -----------------------
var color_scale = d3.scaleOrdinal(d3.schemeCategory10);
key_scale.forEach(function(d,i) {
svg_scale.append("path")
.attr("class", "line")
.style("stroke", color_scale(key_scale[i]))
.attr("d", valueline_scale[i](data_scale))
.attr("id", 'tag'+key_scale[i].replace(/\s+/g, '')); // assign id **
svg_scale.append("text")
.attr("x", (legendSpace_scale/2)+i*legendSpace_scale) // space legend
.attr("y", -20 )
//.attr("y", height + (margin.bottom/2)+ 5)
.attr("class", "legend") // style the legend
.style("fill", color_scale(key_scale[i]))
.on("click", function(){ // ************
// Determine if current line is visible
var active = act_scale[i] ? false : true, // ************
newOpacity = active ? 0 : 1; // ************
// Hide or show the elements based on the ID
d3.select("#tag"+key_scale[i].replace(/\s+/g, '')) // *********
.transition().duration(100) // ************
.style("opacity", newOpacity); // ************
// Update whether or not the elements are active
act_scale[i] = active; // ************
}) // ************
.text(key_scale[i]);
});
// Add the X Axis
svg_scale.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x_scale));
svg_scale.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.top + 10) + ")")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("TIME");
// Add the Y Axis
svg_scale.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y_scale));
// text label for the y axis
svg_scale.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-size", "18px")
.text("LOAD CELL READING (G)");
// draw grid lines
svg_scale.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(make_x_gridlines(x_scale)
.tickSize(-height, 0, 0)
.tickFormat("")
)
svg_scale.append("g")
.attr("class", "grid")
.call(make_y_gridlines(y_scale)
.tickSize(-width, 0, 0)
.tickFormat("")
)
// --------------------------------- above is plotting of scale results --------------------
}) //get result
// -----------------------below is to draw gec logo -------------------
var width_gec = 1250,
height_gec = 100;
var svg_gec = d3.select("body").append("svg")
.attr("width", width_gec)
.attr("height", height_gec);
var g_gec = svg_gec.append("g");
var img = g_gec.append("svg:image")
.attr("xlink:href", "https://outbox.eait.uq.edu.au/uqczhan2/photo_geo_1st/gec.PNG")
.attr("width", 1250)
.attr("height", 100)
.attr("x", 0)
.attr("y",0);
// -----------------------above is to draw gec logo------------------
</script>
</body>