-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
308 lines (282 loc) · 10.2 KB
/
index.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
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BRADIPLOT - Grafico interattivo Plotly per dati CSV Gossip</title>
<!-- Aggiornato a Plotly versione 3 -->
<script src="https://cdn.plot.ly/plotly-3.0.1.min.js" charset="utf-8"></script>
<!-- Aggiornato a PapaParse versione 5.3.2 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.2/papaparse.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
background-color: #eaeaea;
display: flex;
flex-direction: column;
align-items: center;
}
#title {
font-size: 24px;
margin: 20px;
}
/* Contenitore principale della UI con controlli e statistiche */
#ui-container {
width: 80%;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 15px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
#controls {
margin: 20px 0;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}
/* Sezione degli slider */
.sliderContainer {
margin-bottom: 20px;
}
.sliderGroup {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
.slider-label {
font-size: 16px;
margin-top: 10px;
text-align: center;
}
/* Sezione statistiche */
#info {
margin: 20px 0;
font-size: 18px;
display: flex;
flex-direction: column;
align-items: center;
}
/* Grafico Plotly */
#chart {
width: 80%;
height: 800px;
margin-bottom: 40px;
}
</style>
</head>
<body>
<div id="title">Carica il tuo file CSV dei terremoti GOSSIP</div>
<div id="ui-container">
<div id="controls">
<input type="file" id="fileInput" accept=".csv">
<label for="xSelect">Asse X:</label>
<select id="xSelect"></select>
<label for="ySelect">Asse Y:</label>
<select id="ySelect"></select>
</div>
<div class="sliderContainer">
<div class="sliderGroup">
<label for="mdRangeMin">MD Min:</label>
<input type="range" id="mdRangeMin" min="1" max="5" step="0.1" value="1">
<label for="mdRangeMax">MD Max:</label>
<input type="range" id="mdRangeMax" min="1" max="5" step="0.1" value="5">
</div>
<p id="mdRangeLabel" class="slider-label">MD: 1 - 5</p>
</div>
<div class="sliderContainer">
<div class="sliderGroup">
<label for="depthRangeMin">Depth Min (km):</label>
<input type="range" id="depthRangeMin" min="0" max="10" step="0.1" value="0">
<label for="depthRangeMax">Depth Max (km):</label>
<input type="range" id="depthRangeMax" min="0" max="10" step="0.1" value="10">
</div>
<p id="depthRangeLabel" class="slider-label">Depth km: 0 - 10</p>
</div>
<div id="info">
<p id="totalPoints">Totale terremoti filtrati: 0</p>
<p id="md1">MD >= 1 e < 2: 0</p>
<p id="md2">MD >= 2 e < 3: 0</p>
<p id="md3">MD >= 3 e < 4: 0</p>
<p id="md4">MD >= 4 e <= 5: 0</p>
</div>
</div>
<div id="chart"></div>
<script>
let originalData = [];
let filteredData = [];
// Carica il file CSV e processa i dati
document.getElementById('fileInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (!file) return;
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
originalData = results.data;
// Filtro iniziale per MD maggiore o uguale a 1
filteredData = originalData.filter(row => row.MD >= 1);
filteredData = filteredData.map(row => {
row.Time = normalizeTime(row.Time);
row.Depth = parseFloat(row.Depth);
return row;
});
updateStatistics(filteredData);
populateSelectBoxes(results.meta.fields);
updateChart();
}
});
});
// Popola le select con le intestazioni del CSV
function populateSelectBoxes(headers) {
const xSelect = document.getElementById('xSelect');
const ySelect = document.getElementById('ySelect');
xSelect.innerHTML = '';
ySelect.innerHTML = '';
headers.forEach(header => {
const optionX = document.createElement('option');
optionX.value = header;
optionX.text = header;
xSelect.appendChild(optionX);
const optionY = document.createElement('option');
optionY.value = header;
optionY.text = header;
ySelect.appendChild(optionY);
});
xSelect.addEventListener('change', updateChart);
ySelect.addEventListener('change', updateChart);
}
// Aggiungi event listener agli slider per aggiornare il grafico al variare dei valori
document.getElementById('mdRangeMin').addEventListener('input', updateChart);
document.getElementById('mdRangeMax').addEventListener('input', updateChart);
document.getElementById('depthRangeMin').addEventListener('input', updateChart);
document.getElementById('depthRangeMax').addEventListener('input', updateChart);
// Funzione per aggiornare il grafico e le statistiche
function updateChart() {
const xSelectValue = document.getElementById('xSelect').value;
const ySelectValue = document.getElementById('ySelect').value;
const mdMin = parseFloat(document.getElementById('mdRangeMin').value);
const mdMax = parseFloat(document.getElementById('mdRangeMax').value);
const depthMin = parseFloat(document.getElementById('depthRangeMin').value);
const depthMax = parseFloat(document.getElementById('depthRangeMax').value);
if (!xSelectValue || !ySelectValue) {
console.error('Seleziona entrambe le colonne X e Y.');
return;
}
// Aggiorna le etichette degli slider
document.getElementById('mdRangeLabel').innerText = `MD: ${mdMin} - ${mdMax}`;
document.getElementById('depthRangeLabel').innerText = `Depth km: ${depthMin} - ${depthMax}`;
// Filtra i dati in base ai valori degli slider
filteredData = originalData.filter(row =>
row.MD >= mdMin && row.MD <= mdMax &&
row.Depth >= depthMin && row.Depth <= depthMax
);
filteredData = filteredData.map(row => {
row.Time = normalizeTime(row.Time);
return row;
});
updateStatistics(filteredData);
createChart(filteredData, xSelectValue, ySelectValue);
}
// Crea il grafico Plotly con i dati filtrati
function createChart(data, xColumn, yColumn) {
// Mappa i dati e, se l'asse è "Depth", trasforma i valori in negativi
const parsedData = data.map(row => {
let xVal = row[xColumn];
let yVal = row[yColumn];
if(xColumn === "Depth") {
xVal = -Math.abs(row.Depth);
}
if(yColumn === "Depth") {
yVal = -Math.abs(row.Depth);
}
return {
x: xVal,
y: yVal,
time: new Date(row.Time).toLocaleString('it-IT', {
day: '2-digit', month: '2-digit', year: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit'
}),
md: row.MD,
depth: row.Depth,
size: Math.pow(row.MD || 1, 2.5),
color: row.MD
};
});
// Se "MD" è selezionato in uno degli assi, ordina in ordine crescente per disegnare per ultimi i valori più alti
if(xColumn === "MD" || yColumn === "MD") {
parsedData.sort((a, b) => a.md - b.md);
} else {
// Altrimenti, ordina per dare una priorità visiva (i più alti in fondo)
parsedData.sort((a, b) => b.md - a.md);
}
const trace = {
name: "", // Rimuove il nome del trace ("trace 0")
x: parsedData.map(d => d.x),
y: parsedData.map(d => d.y),
mode: 'markers',
marker: {
symbol: 'circle-open',
size: parsedData.map(d => d.size),
color: parsedData.map(d => d.color),
colorscale: 'Rainbow',
showscale: true,
colorbar: {
title: { text: 'MD' },
thickness: 20,
len: 0.75,
x: 1.1,
y: 0.5
},
line: {
width: 2,
color: 'rgba(0,0,0,0.5)'
}
},
text: parsedData.map(d => `Time: ${d.time}<br>MD: ${d.md}<br>Depth: ${d.depth} km`),
hoverinfo: 'text', // Mostra solo il testo del tooltip
hovertemplate: '<b>%{text}</b>'
};
const layout = {
margin: { l: 80, r: 100, t: 80, b: 80 },
height: 850,
dragmode: 'pan',
hovermode: 'closest',
xaxis: {
title: { text: xColumn },
type: (xColumn === 'Time') ? 'date' : 'linear',
tickformat: (xColumn === 'Time') ? '%d/%m/%Y %H:%M:%S' : '',
rangeslider: { visible: true, thickness: 0.2, borderwidth: 1 }
},
yaxis: {
title: { text: yColumn },
type: (yColumn === 'Time') ? 'date' : 'linear'
},
showlegend: false
};
Plotly.newPlot('chart', [trace], layout);
}
// Funzione per normalizzare il formato dell'orario rimuovendo le frazioni di secondo
function normalizeTime(time) {
return time ? time.split('.')[0] : '';
}
// Aggiorna le statistiche relative ai dati filtrati
function updateStatistics(data) {
const totalPoints = data.length;
const md1 = data.filter(d => d.MD >= 1 && d.MD < 2).length;
const md2 = data.filter(d => d.MD >= 2 && d.MD < 3).length;
const md3 = data.filter(d => d.MD >= 3 && d.MD < 4).length;
const md4 = data.filter(d => d.MD >= 4 && d.MD <= 5).length;
document.getElementById('totalPoints').textContent = `Totale terremoti filtrati: ${totalPoints}`;
document.getElementById('md1').textContent = `MD >= 1 e < 2: ${md1}`;
document.getElementById('md2').textContent = `MD >= 2 e < 3: ${md2}`;
document.getElementById('md3').textContent = `MD >= 3 e < 4: ${md3}`;
document.getElementById('md4').textContent = `MD >= 4 e <= 5: ${md4}`;
}
</script>
</body>
</html>