@@ -593,21 +593,62 @@ function computeACEByStorm(points) {
593593 totalRaw += rawAce ;
594594 } ) ;
595595
596- storms . sort ( ( a , b ) => b . ace - a . ace ) ;
597596 return { totalAce : + totalRaw . toFixed ( 4 ) , storms } ;
598597}
599598
600- function renderACEResults ( ace ) {
599+ function sortStormsByNumber ( storms ) {
600+ return [ ...storms ] . sort ( ( a , b ) => {
601+ const numA = parseInt ( a . name . match ( / \d + / ) ?. [ 0 ] || '9999' ) ;
602+ const numB = parseInt ( b . name . match ( / \d + / ) ?. [ 0 ] || '9999' ) ;
603+
604+ if ( ! isNaN ( numA ) && ! isNaN ( numB ) ) {
605+ return numA - numB ;
606+ }
607+
608+ return a . name . localeCompare ( b . name ) ;
609+ } ) ;
610+ }
611+
612+ function sortStormsByACE ( storms ) {
613+ return [ ...storms ] . sort ( ( a , b ) => b . ace - a . ace ) ;
614+ }
615+
616+ function renderACEResults ( ace , sortByNumber = true ) {
601617 const container = document . getElementById ( "ace-results" ) ;
602618 if ( ! container ) return ;
619+
620+ const sortedStorms = sortByNumber ? sortStormsByNumber ( ace . storms ) : sortStormsByACE ( ace . storms ) ;
621+ const sortIcon = sortByNumber ? '🔢' : '📊' ;
622+ const sortLabel = sortByNumber ? 'by number' : 'by ACE' ;
623+ const nextSort = sortByNumber ? 'ACE' : 'number' ;
624+
603625 container . classList . remove ( "hidden-2" ) ;
604626 container . innerHTML = `
605- <h3 style="margin:.25rem 0;">ACE</h3>
606- <div class="ace-total">Total: ${ ace . totalAce } </div>
607- <ul class="ace-list">
608- ${ ace . storms . map ( s => `<li>${ s . name || "Unnamed" } : ${ s . ace } <span>(pts: ${ s . tsPoints } /${ s . points } )</span></li>` ) . join ( "" ) }
609- </ul>
610- ` ;
627+ <h3 style="margin:.25rem 0; display:flex; justify-content:space-between; align-items:center;">
628+ <span>ACE</span>
629+ <button id="ace-sort-toggle" style="background:rgba(255,255,255,0.1); border:1px solid rgba(255,255,255,0.2); border-radius:.3rem; color:inherit; cursor:pointer; font-size:.75em; padding:.2rem .4rem; transition:background .2s;" title="Sort by ${ nextSort } ">
630+ ${ sortIcon } ${ sortLabel }
631+ </button>
632+ </h3>
633+ <div class="ace-total">Total: ${ ace . totalAce } </div>
634+ <ul class="ace-list">
635+ ${ sortedStorms . map ( s => `<li>${ s . name || "Unnamed" } : ${ s . ace } <span>(pts: ${ s . tsPoints } /${ s . points } )</span></li>` ) . join ( "" ) }
636+ </ul>
637+ ` ;
638+
639+ // click handler for the sort toggle button
640+ const sortToggle = document . getElementById ( "ace-sort-toggle" ) ;
641+ if ( sortToggle ) {
642+ sortToggle . addEventListener ( "click" , ( ) => {
643+ renderACEResults ( ace , ! sortByNumber ) ;
644+ } ) ;
645+ sortToggle . addEventListener ( "mouseenter" , ( e ) => {
646+ e . target . style . background = "rgba(255,255,255,0.2)" ;
647+ } ) ;
648+ sortToggle . addEventListener ( "mouseleave" , ( e ) => {
649+ e . target . style . background = "rgba(255,255,255,0.1)" ;
650+ } ) ;
651+ }
611652}
612653
613654// determine point type (tropical/subtropical/extratropical) from available fields
0 commit comments