@@ -324,11 +324,69 @@ export function VerticalProfilePlot({
324324 const allLines = ( ) => [ ...profileLines ( ) , ...plumeLines ( ) , ...obsLines ( ) ] ;
325325
326326 /** Global axes extents across all experiments, times, and observations */
327- const allX = ( ) => allLines ( ) . flatMap ( ( d ) => d . data . map ( ( p ) => p . x ) ) ;
328- const allY = ( ) => allLines ( ) . flatMap ( ( d ) => d . data . map ( ( p ) => p . y ) ) ;
327+ const axisLimits = createMemo ( ( ) => {
328+ const variable = classVariable ( ) ;
329+
330+ let xMin = Number . POSITIVE_INFINITY ;
331+ let xMax = Number . NEGATIVE_INFINITY ;
332+ let yMin = Number . POSITIVE_INFINITY ;
333+ let yMax = Number . NEGATIVE_INFINITY ;
334+
335+ const updateMinMax = ( x : number , y : number ) => {
336+ if ( ! Number . isFinite ( x ) || ! Number . isFinite ( y ) ) return ;
337+ if ( x < xMin ) xMin = x ;
338+ if ( x > xMax ) xMax = x ;
339+ if ( y < yMin ) yMin = y ;
340+ if ( y > yMax ) yMax = y ;
341+ } ;
342+
343+ // --- 1. Profiles ---
344+ for ( const e of flatExperiments ( ) ) {
345+ const output = e . output ;
346+ if ( ! output ) continue ;
347+
348+ const profilesVar = output . profiles ?. [ variable ] ;
349+ if ( profilesVar ) {
350+ output . timeseries . utcTime . forEach ( ( _ , tIndex ) => {
351+ const pts = profilesVar [ tIndex ] ;
352+ if ( ! pts ) return ;
353+ for ( const p of pts . flat ( ) ) updateMinMax ( p . x , p . y ) ;
354+ } ) ;
355+ }
356+
357+ // --- 2. Plumes ---
358+ if ( isPlumeVariable ( variable ) ) {
359+ const plumesVar = output . plumes ?. [ variable ] ;
360+ if ( plumesVar ) {
361+ output . timeseries . utcTime . forEach ( ( _ , tIndex ) => {
362+ const pts = plumesVar [ tIndex ] ;
363+ if ( ! pts ) return ;
364+ for ( const p of pts . flat ( ) ) updateMinMax ( p . x , p . y ) ;
365+ } ) ;
366+ }
367+ }
368+ }
369+
370+ // --- 3. Observations ---
371+ for ( const obs of flatObservations ( ) ) {
372+ const o = observationsForProfile ( obs , variable ) ;
373+ if ( o ?. data ) {
374+ for ( const p of o . data ) updateMinMax ( p . x , p . y ) ;
375+ }
376+ }
377+
378+ // No valid data
379+ if ( xMin === Number . POSITIVE_INFINITY || yMin === Number . POSITIVE_INFINITY )
380+ return undefined ;
381+
382+ const xLimits = getNiceAxisLimits ( [ xMin , xMax ] ) ;
383+ const yLimits = getNiceAxisLimits ( [ yMin , yMax ] ) ;
384+
385+ return { xLimits, yLimits } ;
386+ } ) ;
329387
330- const xLim = ( ) => getNiceAxisLimits ( allX ( ) , 1 ) ;
331- const yLim = ( ) => [ 0 , getNiceAxisLimits ( allY ( ) , 0 ) [ 1 ] ] as [ number , number ] ;
388+ const xLim = ( ) => axisLimits ( ) ?. xLimits ?? [ 0 , 1 ] ;
389+ const yLim = ( ) => axisLimits ( ) ?. yLimits ?? [ 0 , 1 ] ;
332390
333391 /** Initialize toggles for legend */
334392 const [ toggles , setToggles ] = createStore < Record < string , boolean > > ( { } ) ;
0 commit comments