Skip to content

Commit 5a84612

Browse files
committed
Infer dt from first two timestamps
1 parent 24aed1e commit 5a84612

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

webapp/script.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,19 @@ loadDataBtn.addEventListener('click', async function() {
562562
// Set up the time slider based on the density data's maximum time value
563563
const timeSlider = document.getElementById('timeSlider');
564564
const timeLabel = document.getElementById('timeLabel');
565-
// Round up max to the nearest 300 for step consistency
566-
timeSlider.max = (densities.length - 1) * 300;
567-
timeSlider.step = 300;
565+
// Dynamically determine dt from the first two density datapoints
566+
let dt = 300;
567+
if (densities.length > 1) {
568+
dt = Math.round((densities[1].datetime - densities[0].datetime) / 1000); // in seconds
569+
if (dt <= 0) dt = 300;
570+
}
571+
timeSlider.max = (densities.length - 1) * dt;
572+
timeSlider.step = dt;
568573
timeLabel.textContent = `${formatTime(timeStamp)}`;
569574

570575
// Update the visualization when the slider value changes
571576
timeSlider.addEventListener('input', function() {
572-
const index = Math.floor(parseInt(timeSlider.value) / 300);
577+
const index = Math.floor(parseInt(timeSlider.value) / dt);
573578
timeStamp = densities[index].datetime;
574579
timeLabel.textContent = `${formatTime(timeStamp)}`;
575580
update();

0 commit comments

Comments
 (0)