Skip to content

Commit 6a812a3

Browse files
committed
Subsetting of PAHs
1 parent 4d8dc4d commit 6a812a3

6 files changed

Lines changed: 152 additions & 34 deletions

File tree

SedimentDataExplorer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<body>
3232
<div id="everything" style="display: none;">
33-
<h1>Sediment Data Explorer - v0.20250301</h1>
33+
<h1>Sediment Data Explorer - v0.20250309</h1>
3434
MMO Templates -
3535
<input type="file" id="fileInput" multiple onchange="importData()"> <!-- Allow multiple file selection -->
3636
<input type="text" id="urlInput" placeholder="Enter comma-separated URLs" onchange="importData()">

SedimentDataExplorer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@
3939
instanceType[i] = null;
4040
instanceSheet[i] = null;
4141
}
42+
determinands = {};
43+
determinands.pah = {};
44+
determinands.pah.all = ['Acenapthene', 'Acenapthylene', 'Anthracene', 'Benz[a]anthracene', 'Benzo[a]pyrene', 'Benzo[b]fluoranthene',
45+
'Benzo[g,h,i]perylene', 'Benzo[e]pyrene', 'Benzo[k]fluoranthene', 'C1-Napthalenes', 'C1-Phenanthrenes',
46+
'C2-Napthalenes', 'C3-Napthalenes', 'Chrysene', 'Dibenz[a,h]anthracene', 'Fluoranthene',
47+
'Fluorene', 'Indeno[123-c,d]pyrene', 'Napthalene', 'Perylene', 'Phenanthrene', 'Pyrene'];
48+
determinands.pah.lmw = ['Acenapthene', 'Acenapthylene', 'Anthracene', 'C1-Napthalenes', 'Fluorene','Napthalene', 'Phenanthrene'];
49+
determinands.pah.hmw = ['Benz[a]anthracene', 'Benzo[a]pyrene', 'Chrysene', 'Dibenz[a,h]anthracene', 'Fluoranthene', 'Pyrene'];
50+
determinands.pah.epa = ['Acenapthene', 'Acenapthylene', 'Anthracene', 'Benz[a]anthracene', 'Benzo[a]pyrene', 'Benzo[b]fluoranthene',
51+
'Benzo[g,h,i]perylene', 'Benzo[k]fluoranthene', 'Chrysene', 'Dibenz[a,h]anthracene', 'Fluoranthene',
52+
'Fluorene', 'Indeno[123-c,d]pyrene', 'Napthalene', 'Phenanthrene', 'Pyrene'];
53+
determinands.pah.smallpts = ['Acenapthene', 'Acenapthylene', 'Anthracene', 'Benzo[b]fluoranthene', 'Benzo[g,h,i]perylene',
54+
'Benzo[e]pyrene', 'Benzo[k]fluoranthene', 'Chrysene', 'Dibenz[a,h]anthracene', 'Fluoranthene',
55+
'Fluorene', 'Indeno[123-c,d]pyrene', 'Pyrene'];
4256
dataSheetNames = ['Physical Data','Trace metal data','PAH data','PCB data','BDE data','Organotins data','Organochlorine data'];
4357
dataSheetAbr = {'Physical Data': 'Phys','Trace metal data': 'TM','PAH data': 'PAH','PCB data': 'PCB','BDE data': 'BDE','Organotins data': 'OT',
4458
'Organochlorine data': 'OC'};
@@ -1620,6 +1634,11 @@ function removeButtons(chartInstanceNo) {
16201634
removeButton(chartInstanceNo, 's');
16211635
removeButton(chartInstanceNo, 'c');
16221636
removeButton(chartInstanceNo, 'e');
1637+
removeButton(chartInstanceNo, 'r');
1638+
removeButton(chartInstanceNo, 'epa');
1639+
removeButton(chartInstanceNo, 'lmw');
1640+
removeButton(chartInstanceNo, 'hmw');
1641+
removeButton(chartInstanceNo, 'smallpts');
16231642
}
16241643

16251644
function removeButton(chartInstanceNo, buttonType) {

sdeCalcs4Charts.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function dataForCharting(sheetName) {
142142
let ct = sheetName;
143143
let unitTitle = blankSheets[ct]['Unit of measurement'];
144144
let measChart = {};
145-
datesSampled.sort();
145+
//srg250308 datesSampled.sort();
146146
datesSampled.forEach(ds => {
147147
if (ct in selectedSampleMeasurements[ds]) {
148148
// if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null )) {
@@ -153,9 +153,9 @@ function dataForCharting(sheetName) {
153153
measChart[c] = {};
154154
}
155155
let allSamples = Object.keys(selectedSampleInfo[ds].position);
156-
allSamples.sort();
156+
//srg250308 allSamples.sort();
157157
//console.log(ds);
158-
allSamples.sortSamples(ds, 'totalArea');
158+
//srg250308 allSamples.sortSamples(ds, 'totalArea');
159159
allSamples.forEach(s => {
160160
if (selectedSampleMeasurements[ds][ct].chemicals[c].samples[s] == undefined || selectedSampleMeasurements[ds][ct].chemicals[c].samples[s] == null) {
161161
measChart[c][ds + ': ' + s] = 0.0;
@@ -171,7 +171,7 @@ function dataForCharting(sheetName) {
171171
measChart[c] = {};
172172
}
173173
let allSamples = Object.keys(selectedSampleInfo[ds].position);
174-
allSamples.sort();
174+
//srg250308 allSamples.sort();
175175
allSamples.forEach(s => {
176176
measChart[c][ds + ': ' + s] = 0.0;
177177
});
@@ -180,9 +180,9 @@ function dataForCharting(sheetName) {
180180
});
181181
unitTitle = blankSheets[ct]['Unit of measurement'];
182182
//console.log(sheetName,measChart);
183-
// if (!(xAxisSort === 'normal')) {
183+
if (!(xAxisSort === 'normal')) {
184184
measChart = measChartSort(measChart);
185-
// }
185+
}
186186
//console.log(measChart);
187187
return { unitTitle, measChart }
188188
}
@@ -229,7 +229,7 @@ function dataForPSDCharting(sheetName) {
229229
let splitRelativeAreas = {};
230230
let cumWeights = {};
231231
let cumAreas = {};
232-
datesSampled.sort();
232+
//srg250308 datesSampled.sort();
233233
datesSampled.forEach (ds => {
234234
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null)) {
235235
ptsSizes = selectedSampleMeasurements[ds][ct].sizes;
@@ -387,15 +387,15 @@ function sumsForCongenerCharting() {
387387
let datesSampled = Object.keys(selectedSampleMeasurements);
388388
let measChart = {};
389389
// for (const ds in selected) {
390-
datesSampled.sort();
390+
//srg250308 datesSampled.sort();
391391
datesSampled.forEach (ds => {
392392
// if (!(selectedSampleMeasurements[ds]['PCB data'] == undefined || selectedSampleMeasurements[ds]['PCB data'] == null)) {
393393
testOne = selectedSampleMeasurements[ds];
394394
if ('PCB data' in selectedSampleMeasurements[ds]) {
395395
// for (const s in selected[ds]['PCB data'].congenerTest) {
396396
// for (const s in selectedSampleInfo[ds].position) {
397397
const allSamples = Object.keys(selectedSampleInfo[ds].position);
398-
allSamples.sort();
398+
//srg250308 allSamples.sort();
399399
allSamples.forEach(s => {
400400
//console.log(ds,s);
401401
if (selectedSampleMeasurements[ds]['PCB data'].congenerTest[s] == undefined || selectedSampleMeasurements[ds]['PCB data'].congenerTest[s] == null) {
@@ -407,7 +407,7 @@ testOne = selectedSampleMeasurements[ds];
407407
} else {
408408
// for (const s in selectedSampleInfo[ds].position) {
409409
const allSamples = Object.keys(selectedSampleInfo[ds].position);
410-
allSamples.sort();
410+
//srg250308 allSamples.sort();
411411
allSamples.forEach(s => {
412412
measChart[ds + ': ' + s] = { All : 0.0, ICES7 : 0.0};
413413
});
@@ -425,17 +425,17 @@ function sumsForGorhamCharting() {
425425
ct = 'PAH data';
426426
let datesSampled = Object.keys(selectedSampleMeasurements);
427427
let measChart = {};
428-
datesSampled.sort();
428+
//srg250308 datesSampled.sort();
429429
datesSampled.forEach(ds => {
430430
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
431431
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
432432
const allChemicals = Object.keys(selectedSampleMeasurements[ds]['PAH data'].chemicals);
433433
//console.log(allChemicals);
434434
const allSamples = Object.keys(selectedSampleMeasurements[ds]['PAH data'].chemicals[allChemicals[0]].samples);
435435
//console.log(allSamples);
436-
allSamples.sort();
436+
//srg250308 allSamples.sort();
437437
// allSamples.sort((a, b) => selectedSampleInfo[ds].position[a]['Position latitude'] - selectedSampleInfo[ds].position[b]['Position latitude']);
438-
allSamples.sortSamples(ds,'totalArea');
438+
//srg250308 allSamples.sortSamples(ds,'totalArea');
439439
//console.log(allSamples);
440440
allSamples.forEach(s => {
441441
if (selectedSampleMeasurements[ds]['PAH data'].gorhamTest[s] == undefined || selectedSampleMeasurements[ds]['PAH data'].gorhamTest[s] == null) {
@@ -446,7 +446,7 @@ allSamples.sortSamples(ds,'totalArea');
446446
});
447447
} else {
448448
const allSamples = Object.keys(selectedSampleInfo[ds].position);
449-
allSamples.sort();
449+
//srg250308 allSamples.sort();
450450
allSamples.forEach(s => {
451451
measChart[ds + ': ' + s] = { hmwSum: 0.0, lmwSum: 0.0 };
452452
});
@@ -466,10 +466,10 @@ function sumsForTotalHCCharting() {
466466
unitTitle = blankSheets[ct]['totalHCUnit'];
467467
let measChart = {};
468468
sampleNo = -1;
469-
datesSampled.sort();
469+
//srg250308 datesSampled.sort();
470470
datesSampled.forEach(ds => {
471471
const allSamples = Object.keys(selectedSampleInfo[ds].position);
472-
allSamples.sort();
472+
//srg250308 allSamples.sort();
473473
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
474474
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
475475
//console.log(ds,allSamples);
@@ -525,21 +525,21 @@ function ratiosForPAHs() {
525525
unitTitle = 'Ratio';
526526
measChart = {};
527527
sampleNo = -1;
528-
datesSampled.sort();
528+
//srg250308 datesSampled.sort();
529529
datesSampled.forEach (ds => {
530530
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
531531
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
532532
const ratios = sampleMeasurements[ds]['PAH data'].ratios;
533533
const allSamples = Object.keys(selectedSampleInfo[ds].position);
534-
allSamples.sort();
534+
//srg250308 allSamples.sort();
535535
allSamples.forEach(s => {
536536
measChart[ds + ': ' + s] = ratios[s];
537537
sampleNo += 1;
538538
//console.log(sampleNo,ds,s);
539539
});
540540
} else {
541541
const allSamples = Object.keys(selectedSampleInfo[ds].position);
542-
allSamples.sort();
542+
//srg250308 allSamples.sort();
543543
allSamples.forEach(s => {
544544
const m = {};
545545
//IP/(IP+B(ghi)P)
@@ -573,21 +573,21 @@ function simpleRatiosForPAHs() {
573573
let unitTitle = 'Ratio';
574574
let measChart = {};
575575
let sampleNo = -1;
576-
datesSampled.sort();
576+
//srg250308 datesSampled.sort();
577577
datesSampled.forEach (ds => {
578578
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
579579
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
580580
let simpleRatios = sampleMeasurements[ds]['PAH data'].simpleRatios;
581581
let allSamples = Object.keys(selectedSampleInfo[ds].position);
582-
allSamples.sort();
582+
//srg250308 allSamples.sort();
583583
allSamples.forEach(s => {
584584
measChart[ds + ': ' + s] = simpleRatios[s];
585585
sampleNo += 1;
586586
//console.log(sampleNo,ds,s);
587587
});
588588
} else {
589589
const allSamples = Object.keys(selectedSampleInfo[ds].position);
590-
allSamples.sort();
590+
//srg250308 allSamples.sort();
591591
allSamples.forEach(s => {
592592
const m = {};
593593
//IP/(IP+B(ghi)P) ????????????????????????????????????
@@ -621,13 +621,13 @@ function epaRatiosForPAHs() {
621621
let unitTitle = 'Fraction';
622622
let measChart = {};
623623
let sampleNo = -1;
624-
datesSampled.sort();
624+
//srg250308 datesSampled.sort();
625625
datesSampled.forEach (ds => {
626626
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
627627
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
628628
let ringSums = sampleMeasurements[ds]['PAH data'].ringSums;
629629
let allSamples = Object.keys(selectedSampleInfo[ds].position);
630-
allSamples.sort();
630+
//srg250308 allSamples.sort();
631631
allSamples.forEach(s => {
632632
let rs = ringSums[s];
633633
let total = rs['Total EPA PAHs'];
@@ -640,7 +640,7 @@ function epaRatiosForPAHs() {
640640
});
641641
} else {
642642
let allSamples = Object.keys(selectedSampleInfo[ds].position);
643-
allSamples.sort();
643+
//srg250308 allSamples.sort();
644644
allSamples.forEach(s => {
645645
const m = {};
646646
m['LPAHs/Total'] = 0.0;
@@ -664,13 +664,13 @@ function ringFractionsForPAHs() {
664664
let unitTitle = 'Fraction per ring size';
665665
let measChart = {};
666666
let sampleNo = -1;
667-
datesSampled.sort();
667+
//srg250308 datesSampled.sort();
668668
datesSampled.forEach (ds => {
669669
if (!(selectedSampleMeasurements[ds][ct] == undefined || selectedSampleMeasurements[ds][ct] == null ||
670670
(ct === 'PAH data' && !('Acenapthene' in selectedSampleMeasurements[ds][ct].chemicals) ) )) {
671671
let ringSums = sampleMeasurements[ds]['PAH data'].ringSums;
672672
let allSamples = Object.keys(selectedSampleInfo[ds].position);
673-
allSamples.sort();
673+
//srg250308 allSamples.sort();
674674
allSamples.forEach(s => {
675675
let rs = ringSums[s];
676676
let total = rs['Total all rings'];
@@ -686,7 +686,7 @@ function ringFractionsForPAHs() {
686686
});
687687
} else {
688688
let allSamples = Object.keys(selectedSampleInfo[ds].position);
689-
allSamples.sort();
689+
//srg250308 allSamples.sort();
690690
allSamples.forEach(s => {
691691
let m = {};
692692
m['2rings/tot'] = 0;

sdeCharts.js

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,86 @@ function displayPsdSplits(sums, sheetName, instanceNo, unitTitle, subTitle) {
102102
}
103103

104104

105+
// Function to toggle dataset visibility
106+
function toggleDataset(instanceNo, chemicalGroup) {
107+
const chart = chartInstance[instanceNo];
108+
if (!chart) return;
109+
110+
dataset = chart.data.datasets.forEach((ds, index) => {
111+
if (!determinands.pah[chemicalGroup.toLowerCase()].includes(ds.label)) {
112+
ds.hidden = true;
113+
// Ensure internal Chart.js tracking is also updated
114+
if (chart._metasets && chart._metasets[index]) {
115+
chart._metasets[index].hidden = true;
116+
}
117+
}
118+
});
119+
chart.update();
120+
document.getElementById('button'+chemicalGroup.toLowerCase()+instanceNo).disabled = true;
121+
}
122+
123+
// Function to create a button for resetting samples in a chart
124+
function createDisplayChemicals(instanceNo,chemicalGroup) {
125+
//console.log('creating zoom buttom',instanceNo);
126+
let chart = chartInstance[instanceNo];
127+
const container = document.getElementById('chartContainer');
128+
const button = document.createElement('button');
129+
button.id = 'button'+chemicalGroup.toLowerCase()+instanceNo
130+
button.textContent = 'Select ' + chemicalGroup;
131+
button.addEventListener('click', () => {
132+
toggleDataset(instanceNo,chemicalGroup);
133+
});
134+
container.appendChild(button);
135+
}
136+
137+
138+
139+
// Function to reset chart (show all chemical
140+
// s)
141+
function resetDataset(instanceNo) {
142+
const chart = chartInstance[instanceNo];
143+
if (!chart) {
144+
console.log('Chart not found');
145+
return;
146+
}
147+
chart.data.datasets.forEach((ds, index) => {
148+
if (ds.hidden) {
149+
ds.hidden = false;
150+
}
151+
});
152+
// Reset internal Chart.js hidden state (for legend toggling)
153+
if (chart._metasets) {
154+
chart._metasets.forEach(meta => {
155+
meta.hidden = false;
156+
});
157+
}
158+
enableDataButtons(instanceNo,['epa','lmw','hmw','smallpts']);
159+
chart.update();
160+
}
161+
162+
function enableDataButtons(instanceNo,chemicalGroups) {
163+
for (let i = 0; i < chemicalGroups.length; i++) {
164+
document.getElementById('button'+chemicalGroups[i].toLowerCase()+instanceNo).disabled = false;
165+
}
166+
}
167+
//document.getElementById(id).disabled = false;
168+
169+
170+
// Function to create a button for resetting samples in a chart
171+
function createResetChart(instanceNo) {
172+
//console.log('creating zoom buttom',instanceNo);
173+
let chart = chartInstance[instanceNo];
174+
const container = document.getElementById('chartContainer');
175+
const button = document.createElement('button');
176+
button.id = 'buttonr'+instanceNo
177+
button.textContent = 'Reset Dataset';
178+
button.addEventListener('click', () => {
179+
resetDataset(instanceNo);
180+
});
181+
container.appendChild(button);
182+
}
183+
184+
105185

106186
function displayCharts(sheetName, instanceNo) {
107187
// totalAreasAvailable = true;
@@ -178,6 +258,16 @@ fred=selectedMeas;
178258
if (subsToDisplay['samplegroup']) {
179259
instanceNo += 1;
180260
displaySampleChart(selectedMeas, sheetName, instanceNo, unitTitle);
261+
console.log(sheetName, selectedMeas, instanceNo, unitTitle);
262+
/* if(sheetName === 'PAH data') {
263+
//This is where to create the buttons which show different PAH groups
264+
console.log('PAH data reset');
265+
createDisplayChemicals(instanceNo,'EPA');
266+
createDisplayChemicals(instanceNo,'LMW');
267+
createDisplayChemicals(instanceNo,'HMW');
268+
createDisplayChemicals(instanceNo,'SmallPts');
269+
createResetChart(instanceNo);
270+
}*/
181271
if (completeSheet['Physical Data']) {
182272
if (resuspensionSize > 0) {
183273
instanceNo += 1;
@@ -836,6 +926,15 @@ function displaySampleChart(meas, sheetName, instanceNo, unitTitle) {
836926
};
837927
});
838928
displayAnySampleChart(meas, allSamples,datasets,instanceNo,sheetName,unitTitle,false);
929+
if(sheetName === 'PAH data') {
930+
//This is where to create the buttons which show different PAH groups
931+
console.log('PAH data reset');
932+
createDisplayChemicals(instanceNo, 'EPA');
933+
createDisplayChemicals(instanceNo, 'LMW');
934+
createDisplayChemicals(instanceNo, 'HMW');
935+
createDisplayChemicals(instanceNo, 'SmallPts');
936+
createResetChart(instanceNo);
937+
}
839938
}
840939

841940
function highlightMapLocation(clickedIndex) {
@@ -1589,12 +1688,12 @@ console.log('createHighlights',hoveredSample,dateSampled);
15891688
noSamples = 0;
15901689
samples = [];
15911690
const datesSampled = Object.keys(selectedSampleInfo);
1592-
datesSampled.sort();
1691+
//srg250308 datesSampled.sort();
15931692
datesSampled.forEach(dateSampled => {
15941693
const ok = Object.keys(selectedSampleInfo[dateSampled].position);
15951694
noSamples += ok.length;
15961695
const allSamples = Object.keys(selectedSampleInfo[dateSampled].position);
1597-
allSamples.sort();
1696+
//srg250308 allSamples.sort();
15981697
allSamples.forEach(sample => {
15991698
samples.push(dateSampled + ': ' + sample);
16001699
});

0 commit comments

Comments
 (0)