File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments