-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdeCharts.js
2083 lines (1982 loc) · 84.8 KB
/
sdeCharts.js
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
function updateChart(){
//console.log('UPDATECHART*******************');
if (lastInstanceNo > 0) {
const canvas = [];
for (i = 1; i < lastInstanceNo + 1; i++) {
canvas[i] = document.getElementById('chart' + i);
clearCanvasAndChart(canvas[i], i);
}
}
for (i = 0; i < dataSheetNames.length; i++) {
sheetName = dataSheetNames[i];
sheetsToDisplay[dataSheetNames[i]] = document.getElementById(dataSheetNamesCheckboxes[i]).checked ? true : false; // Check the checkbox state
}
for (i = 0; i < subChartNames.length; i++) {
subName = subChartNames[i];
subsToDisplay[subName] = document.getElementById(subName).checked ? true : false; // Check the checkbox state
}
xAxisSort = document.querySelector('input[name="sorting"]:checked').value; //
lastInstanceNo = 0;
blankSheets = {};
setBlanksForCharting();
//console.log(sheetsToDisplay);
for (sheetName in sheetsToDisplay) {
if (sheetsToDisplay[sheetName] && chemicalTypeHasData(sheetName)) {
lastInstanceNo = displayCharts(sheetName, lastInstanceNo);
}
}
if (!(radarPlot === "None")) {
retData = dataForCharting(radarPlot);
unitTitle = retData['unitTitle'];
selectedMeas = retData['measChart'];
createRadarPlot(selectedMeas, radarPlot);
}
//console.log('lastInstanceNo ',lastInstanceNo);
//console.log(selectedMeas);
sampleMap(selectedMeas);
filenameDisplay();
}
function displayPsdSplits(sums, sheetName, instanceNo, unitTitle, subTitle) {
// console.log(sums);
createCanvas(instanceNo);
const convas = document.getElementById("chart" + instanceNo);
convas.style.display = "block";
instanceType[instanceNo] = 'PSD splits by ' + subTitle;
instanceSheet[instanceNo] = sheetName;
const allSamples = Object.keys(sums);
const allParticles = Object.keys(sums[allSamples[0]]); // Assuming all samples have the particles
const datasets = allParticles.map((particle, index) => {
const data = allSamples.map(sample => sums[sample][particle]);
return {
label: particle,
data: data,
borderWidth: 1,
yAxisID: 'y',
};
});
displayAnySampleChart(sums, allSamples, datasets, instanceNo, sheetName + ': PSD splits by ' + subTitle, unitTitle + ' by ' + subTitle, true);
y1Title = 'PSD Split by ' + subTitle;
chartInstance[instanceNo].options.plugins.annotation.annotations = {};
chartInstance[instanceNo].options.plugins.legend.display = true;
legends[instanceNo] = true;
// Update the chart
chartInstance[instanceNo].options.scales.x.stacked = true;
chartInstance[instanceNo].options.scales.y.stacked = true;
chartInstance[instanceNo].update();
}
function displayCharts(sheetName, instanceNo) {
if(sheetName === 'Physical Data') {
retData = dataForPSDCharting(sheetName);
unitTitle = retData['unitTitle'];
//console.log('unitTitle displayCharts ',unitTitle);
sizes = retData['ptsSizes'];
selectedMeas = retData['measChart'];
fred=selectedMeas;
selectedMeasRelativeArea = retData['measChartRelativeArea'];
selectedMeasArea = retData['measChartArea'];
splitWeights = retData['splitWeights'];
splitRelativeAreas = retData['splitRelativeAreas'];
splitAreas = retData['splitAreas'];
cumWeights = retData['cumWeights'];
cumAreas = retData['cumAreas'];
//console.log(sizes);
//console.log('selectedMeas ', selectedMeas);
instanceNo += 1;
displayPSDChart(sizes, selectedMeas, sheetName, instanceNo, unitTitle, 'Relative Weight');
instanceNo += 1;
displayPSDChart(sizes, selectedMeasRelativeArea, sheetName, instanceNo, unitTitle, 'Relative Area');
instanceNo += 1;
displayPSDChart(sizes, selectedMeasArea, sheetName, instanceNo, unitTitle, 'Absolute Area');
instanceNo += 1;
displayPSDChart(sizes, cumWeights, sheetName, instanceNo, unitTitle, 'Cumlative by Weight');
instanceNo += 1;
displayPSDChart(sizes, cumAreas, sheetName, instanceNo, unitTitle, 'Cumulative by Area');
instanceNo += 1;
displayPsdSplits(splitWeights, sheetName, instanceNo, unitTitle, 'Weight');
instanceNo += 1;
displayPsdSplits(splitRelativeAreas, sheetName, instanceNo, unitTitle, 'Relative Area');
instanceNo += 1;
displayPsdSplits(splitAreas, sheetName, instanceNo, unitTitle, 'Absolute Area');
} else {
retData = dataForCharting(sheetName);
unitTitle = retData['unitTitle'];
console.log('unitTitle displayCharts ',unitTitle);
selectedMeas = retData['measChart'];
console.log('selectedMeas ', selectedMeas);
if (subsToDisplay['samplegroup']) {
instanceNo += 1;
displaySampleChart(selectedMeas, sheetName, instanceNo, unitTitle);
selectedMeasArea = {};
for (chemical in selectedMeas) {
selectedMeasArea[chemical] = {};
for (sample in selectedMeas[chemical]) {
let parts = sample.split(": ");
//console.log(parts);
totalArea = selectedSampleMeasurements[parts[0]]['Physical Data'].samples[parts[1]].totalArea;
selectedMeasArea[chemical][sample] = selectedMeas[chemical][sample] / totalArea;
}
}
instanceNo += 1;
//console.log(selectedMeasArea);
displaySampleChart(selectedMeasArea, sheetName, instanceNo, unitTitle + ' / Area');
}
if (subsToDisplay['chemicalgroup']) {
instanceNo += 1;
displayChemicalChart(selectedMeas, sheetName, instanceNo, unitTitle);
instanceNo += 1;
//console.log(selectedMeasArea);
displayChemicalChart(selectedMeasArea, sheetName, instanceNo, unitTitle + ' / Area', false);
}
largeInstanceNo = -1;
if (subsToDisplay['positionplace']) {
retData = dataForScatterCharting(sheetName);
unitTitle = retData['unitTitle'];
//console.log('unitTitle displayCharts ',unitTitle);
scatterData = retData['scatterData'];
chemicalData = retData['chemicalData'];
const allChemicals = Object.keys(chemicalData);
instanceNo += 1;
displayCombinedScatterChart(scatterData, sheetName, instanceNo, 'fred');
largeInstanceNo = instanceNo;
// Step 1: Create a table element
const scatterTable = document.createElement('table');
const noCharts = allChemicals.length;
const startInstanceNo = instanceNo;
// Step 2: Loop to create rows and cells for the table
for (let i = 0; i < noCharts; i++) {
instanceNo += 1;
if (i % 4 === 0) {
// console.log('created row');
row = scatterTable.insertRow(); // Create a row
// console.log(row);
}
const cell = row.insertCell(); // Create a cell
const canvas = document.createElement('canvas'); // Create a canvas for the chart
canvas.id = 'chart' + instanceNo;; // Unique id for each chart canvas
cell.appendChild(canvas); // Append the canvas to the cell
// }
}
// Step 3: Append the table to a container element in your HTML (e.g., <div id="container"></div>)
const chartContainer = document.getElementById('chartContainer');
// first add a div for the buttons
if (largeInstanceNo > 1) {
const divContainer = document.createElement('div');
divContainer.id = 'chartButtons';
chartContainer.appendChild(divContainer);
}
chartContainer.appendChild(scatterTable);
instanceNo = startInstanceNo;
i = 0;
for (const c in chemicalData) {
instanceNo += 1;
//console.log(c,scatterData, chemicalData[c]);
displayScatterChart(scatterData, chemicalData[c], sheetName, instanceNo, c, 'Longitude', 'Latitude', largeInstanceNo);
i += 1;
}
}
if (subsToDisplay['positionplace']) {
retData = dataForTotalAreaScatterCharting(sheetName);
unitTitle = retData['unitTitle'];
//console.log('unitTitle displayCharts ',unitTitle);
scatterData = retData['scatterData'];
chemicalData = retData['chemicalData'];
fitConcentration = retData['fitConcentration'];
fitPredictors = retData['fitPredictors'];
const allChemicals = Object.keys(chemicalData);
//console.log(chemicalData);
instanceNo += 1;
displayCombinedScatterChart(scatterData, sheetName, instanceNo, 'fred');
largeInstanceNo = instanceNo;
// Step 1: Create a table element
const scatterTable = document.createElement('table');
const noCharts = allChemicals.length;
const startInstanceNo = instanceNo;
// Step 2: Loop to create rows and cells for the table
for (let i = 0; i < noCharts; i++) {
instanceNo += 1;
if (i % 4 === 0) {
// console.log('created row');
row = scatterTable.insertRow(); // Create a row
// console.log(row);
}
const cell = row.insertCell(); // Create a cell
const canvas = document.createElement('canvas'); // Create a canvas for the chart
canvas.id = 'chart' + instanceNo;; // Unique id for each chart canvas
cell.appendChild(canvas); // Append the canvas to the cell
// }
}
// Step 3: Append the table to a container element in your HTML (e.g., <div id="container"></div>)
const chartContainer = document.getElementById('chartContainer');
if (largeInstanceNo > 1) {
const divContainer = document.createElement('div');
divContainer.id = 'chartButtons';
chartContainer.appendChild(divContainer);
}
chartContainer.appendChild(scatterTable);
instanceNo = startInstanceNo;
i = 0;
for (const c in chemicalData) {
retData = concentrationFitter(fitConcentration[c], fitPredictors[c], '2023/10/19 f MLA/2015/00088/6 : CHART 7');
beta = retData['beta'];
R_squared = retData['R_squared'];
instanceNo += 1;
//console.log(c,scatterData[c], chemicalData[c]);
// displayScatterChart(scatterData[c], chemicalData[c], sheetName, instanceNo, c + ' : ' R_squared, 'Total Area ', 'Concentration',largeInstanceNo);
displayScatterChart(scatterData[c], chemicalData[c], sheetName, instanceNo, `${c} : ${R_squared.toFixed(4)}`, 'Total Area ', 'Concentration',largeInstanceNo);
i += 1;
//console.log(c, beta, R_squared);
}
}
if (subsToDisplay['positionplace']) {
retData = dataForTotalHCScatterCharting(sheetName);
unitTitle = retData['unitTitle'];
//console.log('unitTitle displayCharts ',unitTitle);
scatterData = retData['scatterData'];
chemicalData = retData['chemicalData'];
const allChemicals = Object.keys(chemicalData);
//console.log(chemicalData);
instanceNo += 1;
displayCombinedScatterChart(scatterData, sheetName, instanceNo, 'fred');
largeInstanceNo = instanceNo;
// Step 1: Create a table element
const scatterTable = document.createElement('table');
const noCharts = allChemicals.length;
const startInstanceNo = instanceNo;
// Step 2: Loop to create rows and cells for the table
for (let i = 0; i < noCharts; i++) {
instanceNo += 1;
if (i % 4 === 0) {
// console.log('created row');
row = scatterTable.insertRow(); // Create a row
// console.log(row);
}
const cell = row.insertCell(); // Create a cell
const canvas = document.createElement('canvas'); // Create a canvas for the chart
canvas.id = 'chart' + instanceNo;; // Unique id for each chart canvas
cell.appendChild(canvas); // Append the canvas to the cell
// }
}
// Step 3: Append the table to a container element in your HTML (e.g., <div id="container"></div>)
const chartContainer = document.getElementById('chartContainer');
if (largeInstanceNo > 1) {
const divContainer = document.createElement('div');
divContainer.id = 'chartButtons';
chartContainer.appendChild(divContainer);
}
chartContainer.appendChild(scatterTable);
instanceNo = startInstanceNo;
i = 0;
for (const c in chemicalData) {
instanceNo += 1;
//console.log(c,scatterData[c], chemicalData[c]);
displayScatterChart(scatterData[c], chemicalData[c], sheetName, instanceNo, c, 'Total Hydrocarbon', 'Concentration',largeInstanceNo);
i += 1;
}
}
if (sheetName == 'PAH data' && Object.keys(chemInfo).length != 0) {
const chemicalNames = Object.keys(chemInfo);
const properties = Object.keys(chemInfo[chemicalNames[0]]);
for (i = 0; i<14 ; i++) {
// Step 2: Sort the chemical names based on the property (e.g., molWeight)
chemicalNames.sort((a, b) => chemInfo[a][properties[i]] - chemInfo[b][properties[i]]);
// Step 3-6: Iterate through the sorted chemical names and populate selectedMeas
const sortedSelectedMeas = {};
chemicalNames.forEach((chemical) => {
if (selectedMeas[chemical]) {
sortedSelectedMeas[chemical] = selectedMeas[chemical];
}
});
// console.log(sortedSelectedMeas);
instanceNo += 1;
displaySampleChart(sortedSelectedMeas, sheetName + ': Sorted by ' + properties[i], instanceNo, unitTitle);
instanceNo += 1;
displayChemicalChart(sortedSelectedMeas, sheetName + ': Sorted by ' + properties[i], instanceNo, unitTitle);
}
}
if (sheetName === 'PAH data' && subsToDisplay['gorhamtest']) {
instanceNo += 1;
selectedSums = sumsForGorhamCharting();
console.log(selectedSums);
displayGorhamTest(selectedSums, sheetName, instanceNo, unitTitle);
// retData = null;
}
if (sheetName === 'PAH data' && subsToDisplay['totalhc']) {
instanceNo += 1;
retData = sumsForTotalHCCharting();
unitTitle = retData['unitTitle'];
selectedSums = retData['measChart'];
//console.log(Object.keys(selectedSums));
displayTotalHC(selectedSums, sheetName, instanceNo, unitTitle);
}
if (sheetName === 'PAH data' && subsToDisplay['pahratios']) {
instanceNo += 1;
retData = ratiosForPAHs();
unitTitle = retData['unitTitle'];
selectedSums = retData['measChart'];
displayPAHRatios(selectedSums, sheetName, instanceNo, unitTitle);
}
if (sheetName === 'PAH data' && subsToDisplay['ringfractions']) {
instanceNo += 1;
retData = ringFractionsForPAHs();
unitTitle = retData['unitTitle'];
selectedSums = retData['measChart'];
displayRingFractions(selectedSums, sheetName, instanceNo, unitTitle);
}
if (sheetName === 'PAH data' && subsToDisplay['eparatios']) {
instanceNo += 1;
retData = epaRatiosForPAHs();
unitTitle = retData['unitTitle'];
selectedSums = retData['measChart'];
displayEpaRatios(selectedSums, sheetName, instanceNo, unitTitle);
}
if (sheetName === 'PAH data' && subsToDisplay['simpleratios']) {
instanceNo += 1;
retData = simpleRatiosForPAHs();
unitTitle = retData['unitTitle'];
selectedSums = retData['measChart'];
displaySimpleRatios(selectedSums, sheetName, instanceNo, unitTitle);
}
if (sheetName === 'PCB data' && subsToDisplay['congenertest']) {
instanceNo += 1;
selectedSums = sumsForCongenerCharting();
displayCongener(selectedSums, sheetName, instanceNo, unitTitle);
}
}
// Display the canvas
//console.log('Display the canvas ',instanceNo);
return instanceNo
}
function dataForCharting(sheetName) {
let datesSampled = Object.keys(selectedSampleMeasurements);
let ct = sheetName;
let unitTitle = blankSheets[ct]['Unit of measurement'];
let measChart = {};
datesSampled.sort();
datesSampled.forEach(ds => {
if (ct in selectedSampleMeasurements[ds]) {
// if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null )) {
/* if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals)))) {*/
for (const c in selectedSampleMeasurements[ds][ct].chemicals) {
if (measChart[c] == undefined || measChart[c] == null) {
measChart[c] = {};
}
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.sortSamples(ds, 'totalArea');
allSamples.forEach(s => {
if (selectedSampleMeasurements[ds][ct].chemicals[c].samples[s] == undefined || selectedSampleMeasurements[ds][ct].chemicals[c].samples[s] == null) {
measChart[c][ds + ': ' + s] = 0.0;
} else {
measChart[c][ds + ': ' + s] = selectedSampleMeasurements[ds][ct].chemicals[c].samples[s];
}
});
}
} else {
// Have to deal with samples without measurements set everything to zero
for (const c in blankSheets[ct].chemicals) {
if (measChart[c] == undefined || measChart[c] == null) {
measChart[c] = {};
}
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
measChart[c][ds + ': ' + s] = 0.0;
});
}
}
});
unitTitle = blankSheets[ct]['Unit of measurement'];
//console.log(sheetName,measChart);
if (!(xAxisSort === 'normal')) {
measChart = measChartSort(measChart);
}
//console.log(measChart);
return { unitTitle, measChart }
}
function measChartSort(measChart) {
let sortedChart = {};
let allChemicals = Object.keys(measChart);
let allSamples = Object.keys(measChart[allChemicals[0]]);
//console.log(allChemicals);
//console.log(allSamples);
allSamples.sortComplexSamples();
for (c in measChart) {
sortedChart[c] = {};
allSamples.forEach(sample => {
sortedChart[c][sample] = measChart[c][sample];
});
}
return sortedChart
}
function propertyChartSort(measChart) {
let allSamples = Object.keys(measChart);
//console.log(allSamples);
allSamples.sortComplexSamples();
let sortedChart = {};
allSamples.forEach(sample => {
sortedChart[sample] = measChart[sample];
});
return sortedChart
}
function sumsForCongenerCharting() {
let datesSampled = Object.keys(selectedSampleMeasurements);
let measChart = {};
// for (const ds in selected) {
datesSampled.sort();
datesSampled.forEach (ds => {
// if (!(selectedSampleMeasurements[ds]['PCB data'] == undefined || selectedSampleMeasurements[ds]['PCB data'] == null)) {
testOne = selectedSampleMeasurements[ds];
if ('PCB data' in selectedSampleMeasurements[ds]) {
// for (const s in selected[ds]['PCB data'].congenerTest) {
// for (const s in selectedSampleInfo[ds].position) {
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
//console.log(ds,s);
if (selectedSampleMeasurements[ds]['PCB data'].congenerTest[s] == undefined || selectedSampleMeasurements[ds]['PCB data'].congenerTest[s] == null) {
measChart[ds + ': ' + s] = { ICES7 : 0.0, All : 0.0 };
} else {
measChart[ds + ': ' + s] = selectedSampleMeasurements[ds]['PCB data'].congenerTest[s];
}
});
} else {
// for (const s in selectedSampleInfo[ds].position) {
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
measChart[ds + ': ' + s] = { All : 0.0, ICES7 : 0.0};
});
}
});
//console.log(measChart);
if (!(xAxisSort === 'normal')) {
measChart = propertyChartSort(measChart);
//console.log(measChart);
}
return measChart
}
function sumsForGorhamCharting() {
ct = 'PAH data';
let datesSampled = Object.keys(selectedSampleMeasurements);
let measChart = {};
datesSampled.sort();
datesSampled.forEach(ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
const allChemicals = Object.keys(selectedSampleMeasurements[ds]['PAH data'].chemicals);
//console.log(allChemicals);
const allSamples = Object.keys(selectedSampleMeasurements[ds]['PAH data'].chemicals[allChemicals[0]].samples);
//console.log(allSamples);
allSamples.sort();
// allSamples.sort((a, b) => selectedSampleInfo[ds].position[a]['Position latitude'] - selectedSampleInfo[ds].position[b]['Position latitude']);
allSamples.sortSamples(ds,'totalArea');
//console.log(allSamples);
allSamples.forEach(s => {
if (selectedSampleMeasurements[ds]['PAH data'].gorhamTest[s] == undefined || selectedSampleMeasurements[ds]['PAH data'].gorhamTest[s] == null) {
measChart[ds + ': ' + s] = { hmwSum: 0.0, lmwSum: 0.0 };
} else {
measChart[ds + ': ' + s] = selectedSampleMeasurements[ds]['PAH data'].gorhamTest[s];
}
});
} else {
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
measChart[ds + ': ' + s] = { hmwSum: 0.0, lmwSum: 0.0 };
});
}
});
//console.log(measChart);
if (!(xAxisSort === 'normal')) {
measChart = propertyChartSort(measChart);
//console.log(measChart);
}
return measChart
}
function sumsForTotalHCCharting() {
ct = 'PAH data';
let datesSampled = Object.keys(selectedSampleMeasurements);
unitTitle = blankSheets[ct]['totalHCUnit'];
let measChart = {};
sampleNo = -1;
datesSampled.sort();
datesSampled.forEach(ds => {
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
//console.log(ds,allSamples);
allSamples.forEach(s => {
if (s in selectedSampleMeasurements[ds]['PAH data'].totalHC) {
measChart[ds + ': ' + s] = {totalHC: selectedSampleMeasurements[ds]['PAH data'].totalHC[s]};
} else {
measChart[ds + ': ' + s] = {totalHC: 0.0};
}
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
} else {
allSamples.forEach(s => {
measChart[ds + ': ' + s] = {totalHC: 0.0};
sampleNo += 1;
// console.log(sampleNo, ds, s);
});
}
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
allSamples.forEach(s => {
if (!(selectedSampleMeasurements[ds]['PAH data'].total[s] == undefined || selectedSampleMeasurements[ds]['PAH data'].total[s] == null)) {
measChart[ds + ': ' + s].fractionPAH = selectedSampleMeasurements[ds]['PAH data'].total[s] / 1000;
} else {
measChart[ds + ': ' + s].fractionPAH = 0.0;
}
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
} else {
allSamples.forEach(s => {
measChart[ds + ': ' + s].fractionPAH = 0.0;
sampleNo += 1;
// console.log(sampleNo, ds, s);
});
}
});
//console.log(measChart);
//console.log(xAxisSort);
if (!(xAxisSort === 'normal')) {
//console.log(measChart);
measChart = propertyChartSort(measChart);
//console.log(Object.keys(measChart));
}
//console.log(measChart);
return { unitTitle, measChart }
}
function ratiosForPAHs() {
ct = 'PAH data';
const datesSampled = Object.keys(selectedSampleMeasurements);
unitTitle = 'Ratio';
measChart = {};
sampleNo = -1;
datesSampled.sort();
datesSampled.forEach (ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
const ratios = sampleMeasurements[ds]['PAH data'].ratios;
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
measChart[ds + ': ' + s] = ratios[s];
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
} else {
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
const m = {};
//IP/(IP+B(ghi)P)
m['IP/(IP+B(ghi)P)'] = 0.0;
//BaA/(BaA+Chr)
m['BaA/(BaA+Chr)'] = 0.0;
//BaP/(BaP+Chr)
m['BaP/(BaP+Chr)'] = 0.0;
//Phen/(Phen+Anth)
m['Phen/(Phen+Anth)'] = 0.0;
//BaA/(BaA+BaP)
m['BaA/(BaA+BaP)'] = 0.0;
//BbF/(BbF+BkF)
m['BbF/(BbF+BkF)'] = 0.0;
measChart[ds + ': ' + s] = m;
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
}
});
//console.log('ratios',measChart);
if (!(xAxisSort === 'normal')) {
measChart = propertyChartSort(measChart);
}
return {unitTitle, measChart}
}
function simpleRatiosForPAHs() {
ct = 'PAH data';
let datesSampled = Object.keys(selectedSampleMeasurements);
let unitTitle = 'Ratio';
let measChart = {};
let sampleNo = -1;
datesSampled.sort();
datesSampled.forEach (ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
let simpleRatios = sampleMeasurements[ds]['PAH data'].simpleRatios;
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
measChart[ds + ': ' + s] = simpleRatios[s];
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
} else {
const allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
const m = {};
//IP/(IP+B(ghi)P) ????????????????????????????????????
m['IP/(IP+B(ghi)P)'] = 0.0;
//BaA/(BaA+Chr)
m['BaA/(BaA+Chr)'] = 0.0;
//BaP/(BaP+Chr)
m['BaP/(BaP+Chr)'] = 0.0;
//Phen/(Phen+Anth)
m['Phen/(Phen+Anth)'] = 0.0;
//BaA/(BaA+BaP)
m['BaA/(BaA+BaP)'] = 0.0;
//BbF/(BbF+BkF)
m['BbF/(BbF+BkF)'] = 0.0;
measChart[ds + ': ' + s] = m;
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
}
});
//console.log('ratios',measChart);
if (!(xAxisSort === 'normal')) {
measChart = propertyChartSort(measChart);
}
return {unitTitle, measChart}
}
function epaRatiosForPAHs() {
ct = 'PAH data';
let datesSampled = Object.keys(selectedSampleMeasurements);
let unitTitle = 'Fraction';
let measChart = {};
let sampleNo = -1;
datesSampled.sort();
datesSampled.forEach (ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
let ringSums = sampleMeasurements[ds]['PAH data'].ringSums;
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
let rs = ringSums[s];
let total = rs['Total EPA PAHs'];
let m = {};
m['LPAHs/Total'] = rs['LPAHs'] / total;
m['HPAHs/Total'] = rs['HPAHs'] / total;
measChart[ds + ': ' + s] = m;
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
} else {
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
const m = {};
m['LPAHs/Total'] = 0.0;
m['HPAHs/Total'] = 0.0;
measChart[ds + ': ' + s] = m;
sampleNo += 1;
// console.log(sampleNo,ds,s);
});
}
});
//console.log('ratios',measChart);
if (!(xAxisSort === 'normal')) {
measChart = propertyChartSort(measChart);
}
return {unitTitle, measChart}
}
function ringFractionsForPAHs() {
ct = 'PAH data';
let datesSampled = Object.keys(selectedSampleMeasurements);
let unitTitle = 'Fraction per ring size';
let measChart = {};
let sampleNo = -1;
datesSampled.sort();
datesSampled.forEach (ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
let ringSums = sampleMeasurements[ds]['PAH data'].ringSums;
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
let rs = ringSums[s];
let total = rs['Total all rings'];
let m = {};
m['2rings/tot'] = rs['Sum of 2 rings'] / total;
m['3rings/tot'] = rs['Sum of 3 rings'] / total;
m['4rings/tot'] = rs['Sum of 4 rings'] / total;
m['5rings/tot'] = rs['Sum of 5 rings'] / total;
m['6rings/tot'] = rs['Sum of 6 rings'] / total;
measChart[ds + ': ' + s] = m;
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
} else {
let allSamples = Object.keys(selectedSampleInfo[ds].position);
allSamples.sort();
allSamples.forEach(s => {
let m = {};
m['2rings/tot'] = 0;
m['3rings/tot'] = 0;
m['4rings/tot'] = 0;
m['5rings/tot'] = 0;
m['6rings/tot'] = 0;
measChart[ds + ': ' + s] = m;
sampleNo += 1;
//console.log(sampleNo,ds,s);
});
}
});
//console.log('ratios',measChart);
if (!(xAxisSort === 'normal')) {
measChart = propertyChartSort(measChart);
}
return {unitTitle, measChart}
}
function setBlanksForCharting() {
let datesSampled = Object.keys(selectedSampleMeasurements);
// Have to deal with samples without measurements set everything to zero
for (const ds in selectedSampleMeasurements) {
for (const ct in selectedSampleMeasurements[ds]) {
if (blankSheets[ct] == null || blankSheets[ct] == undefined) {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null)) {
blankSheets[ct] = selectedSampleMeasurements[ds][ct];
}
}
}
}
return
}
function dataForPSDCharting(sheetName) {
let datesSampled = Object.keys(selectedSampleMeasurements);
let ct = sheetName;
let unitTitle = blankSheets[ct]['Unit of measurement'];
let measChart = {};
let measChartArea = {};
let measChartRelativeArea = {};
let ptsSizes = null;
let ptsAreas = null;
let ptsVolumes = null;
let splitWeights = {};
let splitAreas = {};
let splitRelativeAreas = {};
let cumWeights = {};
let cumAreas = {};
datesSampled.sort();
datesSampled.forEach (ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null)) {
ptsSizes = selectedSampleMeasurements[ds][ct].sizes;
ptsSizes = ptsSizes.map(phiSize => Math.pow(2, -phiSize)/1000);
ptsAreas = ptsSizes.map(size => (Math.PI * size * size) / 4);
ptsVolumes = ptsSizes.map(size => (Math.PI * size * size * size) / 6);
for (const s in selectedSampleMeasurements[ds][ct].samples) {
currentPsd = selectedSampleMeasurements[ds][ct].samples[s].psd;
measChart[ds + ': ' + s] = currentPsd;
// measChart[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].psd;
measChartArea[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].psdAreas;
measChartRelativeArea[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].psdRelativeAreas;
splitWeights[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].splitWeights;
splitAreas[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].splitAreas;
splitRelativeAreas[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].splitRelativeAreas;
cumWeights[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].cumWeights;
cumAreas[ds + ': ' + s] = selectedSampleMeasurements[ds][ct].samples[s].cumAreas;
//console.log(sizes.length);
/* totalArea = 0;
for (i=0;i<ptsSizes.length;i++) {
currentArea = ptsAreas[i] * currentPsd[i] / ptsVolumes[i];
areas[i] = currentArea;
totalArea += currentArea;
}
measChartArea[ds + ': ' + s + ' : ' + totalArea] = areas;
splitWeights[ds + ': ' + s] = psdSplit(currentPsd);
splitAreas[ds + ': ' + s] = psdSplit(areas);*/
//console.log(ds + ': ' + s, totalArea);
}
} else {
for (const s in selectedSampleInfo[ds].position) {
measChart[ds + ': ' + s] = new Array(42).fill(0.0);
measChartArea[ds + ': ' + s] = new Array(42).fill(0.0);
}
}
});
//console.log('dataforPSD ', unitTitle,ptsSizes,ptsAreas,ptsVolumes,measChart,measChartArea);
return {unitTitle, ptsSizes, measChart, measChartArea, measChartRelativeArea, splitWeights, splitAreas, splitRelativeAreas, cumWeights, cumAreas}
}
function dataForScatterCharting(sheetName) {
let datesSampled = Object.keys(selectedSampleMeasurements);
let ct = sheetName;
let unitTitle = blankSheets[ct]['Unit of measurement'];
let scatterData = [];
let chemicalData = {};
i = 0;
datesSampled.forEach (ds => {
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
let allChemicals = Object.keys(selectedSampleMeasurements[ds][ct].chemicals);
for (const s in selectedSampleMeasurements[ds][ct].chemicals[allChemicals[0]].samples) {
scatterData[i] = ({
x: sampleInfo[ds].position[s]['Position longitude'],
y: sampleInfo[ds].position[s]['Position latitude']
});
i += 1;
//console.log(sampleInfo[ds].position[s]['Position latitude']);
//console.log(sampleInfo[ds].position[s]['Position longitude']);
}
for (const c in selectedSampleMeasurements[ds][ct].chemicals) {
if (chemicalData[c] == undefined || chemicalData[c] == null) {
chemicalData[c] = {};
}
currentChemical = selectedSampleMeasurements[ds][ct].chemicals[c];
//console.log(currentChemical);
for (const s in currentChemical.samples) {
chemicalData[c][ds + ' : ' + s] = currentChemical.samples[s];
//console.log(currentChemical.samples[s])
}
}
}
});
//console.log('data ',sheetName,scatterData);
return {unitTitle, scatterData, chemicalData}
}
function dataForTotalAreaScatterCharting(sheetName) {
let datesSampled = Object.keys(selectedSampleMeasurements);
let ct = sheetName;
// unitTitle = selected[datesSampled[0]][ct]['Unit of measurement'];
let unitTitle = blankSheets[ct]['Unit of measurement'];
let scatterData = {};
let chemicalData = {};
let fitConcentration = {};
let fitPredictors = {};
datesSampled.forEach(ds => {
if (ct in selectedSampleMeasurements[ds]) {
/* if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals)))) {*/
let allChemicals = Object.keys(selectedSampleMeasurements[ds][ct].chemicals);
for (const c in selectedSampleMeasurements[ds][ct].chemicals) {
i = 0;
scatterData[c] = [];
if (chemicalData[c] == undefined || chemicalData[c] == null) {
chemicalData[c] = {};
}
if (fitConcentration[c] == undefined || chemicalData[c] == null) {
fitConcentration[c] = {};
fitPredictors[c] = {};
}
currentChemical = selectedSampleMeasurements[ds][ct].chemicals[c];
for (const s in selectedSampleMeasurements[ds][ct].chemicals[c].samples) {
scatterData[c][i] = ({
x: sampleMeasurements[ds]['Physical Data'].samples[s].totalArea,
y: currentChemical.samples[s]
});
chemicalData[c][ds + ' : ' + s] = currentChemical.samples[s];
i += 1;
fitConcentration[c][ds + ' : ' + s] = currentChemical.samples[s];
fitPredictors[c][ds + ' : ' + s] = [sampleMeasurements[ds]['Physical Data'].samples[s].totalArea, sampleMeasurements[ds]['PAH data'].totalHC[s]];
}
}
}
});
console.log('data ',sheetName,scatterData,chemicalData);
return {unitTitle, scatterData, chemicalData, fitConcentration, fitPredictors}
}
function dataForTotalHCScatterCharting(sheetName) {
let datesSampled = Object.keys(selectedSampleMeasurements);
let ct = sheetName;
// unitTitle = selected[datesSampled[0]][ct]['Unit of measurement'];
let unitTitle = blankSheets[ct]['Unit of measurement'];
let scatterData = {};
let chemicalData = {};
datesSampled.forEach(ds => {
if (ct in selectedSampleMeasurements[ds]) {
/* if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals)))) {*/
let allChemicals = Object.keys(selectedSampleMeasurements[ds][ct].chemicals);
for (const c in selectedSampleMeasurements[ds][ct].chemicals) {
i = 0;
scatterData[c] = [];
if (chemicalData[c] == undefined || chemicalData[c] == null) {
chemicalData[c] = {};
}
currentChemical = selectedSampleMeasurements[ds][ct].chemicals[c];
for (const s in selectedSampleMeasurements[ds][ct].chemicals[c].samples) {
scatterData[c][i] = ({
x: sampleMeasurements[ds]['PAH data'].totalHC[s],
y: currentChemical.samples[s]
});
chemicalData[c][ds + ' : ' + s] = currentChemical.samples[s];
i += 1;
}
}
}
});
//console.log('data ',sheetName,scatterData,chemicalData);
return {unitTitle, scatterData, chemicalData}
}
// Function to interpolate between two colors based on the value
function colorGradient(value, color1, color2) {
// Ensure the value is between 0 and 1
value = Math.max(0, Math.min(1, value));
// Convert colors from hex to RGB
const color1RGB = hexToRgb(color1);
const color2RGB = hexToRgb(color2);
// Calculate the interpolated color
const r = Math.round(color1RGB.r + value * (color2RGB.r - color1RGB.r));
const g = Math.round(color1RGB.g + value * (color2RGB.g - color1RGB.g));
const b = Math.round(color1RGB.b + value * (color2RGB.b - color1RGB.b));
// Return the color in 'rgb(r,g,b)' format
return `rgb(${r},${g},${b},0.5)`;
}
// Helper function to convert hex color to RGB
function hexToRgb(hex) {
// Remove the hash symbol if present
hex = hex.replace(/^#/, '');
// Parse the red, green, and blue components
const bigint = parseInt(hex, 16);
return {
r: (bigint >> 16) & 255,
g: (bigint >> 8) & 255,
b: bigint & 255
};
}
function resizeChart(chart) {
// Get the parent container of the chart
var container = chart.canvas.parentNode;
// Toggle the class to resize the chart
container.classList.toggle('large-chart');
// Update the chart to reflect the new size
chart.resize();