-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSee-PT.html
322 lines (272 loc) · 8.61 KB
/
See-PT.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
<!DOCTYPE html>
<html>
<head>
<title>File Import</title>
<!-- Load Plotly library -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/g/filesaver.js"></script>
<style>
body {
text-align: left;
background-color: #f2f2f9; /* set the background color to light gray */
}
.header {
background-color: #b5e7a0;
height: 60px;
font-color: white;
display: flex;
flex-direction:row;
justify-content: flex-start;
align-items: left;
border-radius: 5px;
font-size: 1.0em;
margin-bottom: 5px;
}
h1 {
font-size: 1.75em;
font-family: Arial, sans-serif;
margin-top: 5;
align-items: flex-start; /* align items to the left */
margin-left: 10px; /* add margin to the left */
}
.container {
display: flex;
justify-content: center;
}
#fileContents {
display: block;
margin: 10px auto; /* added 20px margin top */
font-size: 1.1em;
display: flex;
justify-content: left;
width: 75vw;
height: 10vh;
}
#plot-container1, #plot-container2, #plot-container3 {
margin-top: 2vh;
background-color: transparent;
}
/* Button styles */
button#saveButton,
button#removeNegativesButton,
button#addValuesButton {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
}
/* Select styles */
select#removeNegativesSelect,
select#addValuesSelect {
padding: 10px;
font-size: 16px;
margin: 4px 2px;
border-radius: 5px;
}
/* Input styles */
input#addValuesInput {
padding: 10px;
font-size: 16px;
margin: 4px 2px;
border-radius: 5px;
border: none;
border: 1px solid #ccc;
}
/* File input styles */
input[type="file"]#fileInput {
display: none;
}
label[for="fileInput"] {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
}
#removeNegativesContainer {
float: right;
}
#addValuesContainer {
float: right;
margin-right: 20px;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
}
.header-right {
display: flex;
align-items: center;
}
</style>
</head>
<body>
<div class="header">
<h1>Sounding Plotter</h1>
<div>
<label for="fileInput">Upload File</label>
<input type="file" id="fileInput">
<button id="saveButton">Save</button>
</div>
<div id="removeNegativesContainer" style="float: right;">
<label for="removeNegativesSelect"></label>
<select id="removeNegativesSelect">
<option value="QC">QC</option>
<option value="FS">FS</option>
<option value="U">U</option>
</select>
<button id="removeNegativesButton">Remove Negative Values</button>
</div>
<div id="addValuesContainer" style="float: right;">
<select id="addValuesSelect">
<option value="QC">QC</option>
<option value="FS">FS</option>
<option value="U">U</option>
</select>
<input type="text" id="addValuesInput" placeholder="Enter the value to add">
<button id="addValuesButton">Baseline Shift</button>
</div>
</div>
<div class="content">
<textarea id="fileContents" rows="10" cols="50"></textarea>
<div class="container">
<div id="plot-container1"></div>
<div id="plot-container2"></div>
<div id="plot-container3"></div>
</div>
</div>
<script>
// Constants for parameter prefixes
const PARAM_PREFIXES = ["D=", "QC=", "FS=", "U="];
// Function to parse data and return an array of objects
function parseSoundingData(data) {
return data.split('\n')
.filter(line => PARAM_PREFIXES.some(prefix => line.startsWith(prefix)))
.map(line => {
const values = line.split("=").map(parseFloat);
return { D: values[1], QC: values[2], FS: values[3], U: values[4] };
});
}
// Function to update a single plot
function updateSinglePlot(containerId, xData, yData, title, xTitle, yTitle) {
const trace = {
x: xData,
y: yData,
mode: "lines+markers",
type: "scatter",
name: title,
marker: {
size: 2,
colorscale: "Viridis",
color: yData
}
};
const layout = {
title: title,
titlefont: { size: 14 },
margin: { t: 20 },
xaxis: { title: xTitle },
yaxis: { title: yTitle, autorange: "reversed" },
width: 400,
height: 700,
dragmode: 'pan',
plot_bgcolor: 'transparent',
paper_bgcolor: 'transparent',
};
const config = {
scrollZoom: true,
modeBarButtonsToRemove: ['lasso2d', 'select2d'],
displayModeBar: false,
responsive: true,
dragmode: 'pan',
hovermode: 'closest',
paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)'
};
Plotly.newPlot(containerId, [trace], layout, config);
}
// Function to update all plots
function updatePlots(soundingData) {
const depthData = soundingData.map(row => row.D);
const tipData = soundingData.map(row => row.QC);
const frictionData = soundingData.map(row => row.FS);
const pressureData = soundingData.map(row => row.U);
updateSinglePlot('plot-container1', tipData, depthData, "Tip Data", "Tip (kPa)", "Depth (m)");
updateSinglePlot('plot-container2', frictionData, depthData, "Friction Data", "Friction (kPa)", "Depth (m)");
updateSinglePlot('plot-container3', pressureData, depthData, "Pressure Data", "Pressure (kPa)", "Depth (m)");
}
// Event listener for file input
document.getElementById("fileInput").addEventListener("change", function (event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.addEventListener("load", function (event) {
const contents = event.target.result;
const decoder = new TextDecoder("windows-1252");
const decodedContents = decoder.decode(contents);
document.getElementById("fileContents").value = decodedContents;
const soundingData = parseSoundingData(decodedContents);
updatePlots(soundingData);
});
reader.readAsArrayBuffer(file);
});
// Event listener for text area input
document.getElementById("fileContents").addEventListener("input", function (event) {
const decodedContents = event.target.value;
const soundingData = parseSoundingData(decodedContents);
updatePlots(soundingData);
});
// Event listener for save button
document.getElementById("saveButton").addEventListener("click", function () {
const textArea = document.getElementById("fileContents");
let contents = textArea.value;
contents = contents.replace(/\n/g, "\r\n");
const importedFile = document.getElementById("fileInput").files[0];
const blob = new Blob([contents], { type: "text/plain;charset=windows-1252" });
saveAs(blob, importedFile.name);
});
// Event listener for remove negatives button
document.getElementById("removeNegativesButton").addEventListener("click", function () {
const fileContents = document.getElementById("fileContents").value;
const parameter = document.getElementById("removeNegativesSelect").value;
const updatedContents = fileContents.replace(new RegExp(`(${parameter})=(-\\d+)`, "g"), (match, p1, p2) => {
return `${p1}=${p2.substring(1)}`;
});
document.getElementById("fileContents").value = updatedContents;
const soundingData = parseSoundingData(updatedContents);
updatePlots(soundingData);
});
// Event listener for baseline shifting feature (add values button)
document.getElementById("addValuesButton").addEventListener("click", function () {
const fileContents = document.getElementById("fileContents").value;
const inputValue = parseFloat(document.getElementById("addValuesInput").value);
const parameter = document.getElementById("addValuesSelect").value;
const updatedContents = fileContents.replace(new RegExp(`(${parameter})=(-?\\d+(\\.\\d+)?)`, "g"), (match, p1, p2) => {
let newValue = parseFloat(p2) + inputValue;
if (p1 === "FS" || p1 === "U") {
newValue = newValue.toFixed(1);
} else {
newValue = newValue.toFixed(4);
}
return `${p1}=${newValue.toString()}`;
});
document.getElementById("fileContents").value = updatedContents;
const soundingData = parseSoundingData(updatedContents);
updatePlots(soundingData);
});
</script>
</body>
</html>