@@ -25,7 +25,8 @@ const SPEED_OPTIONS = [
2525
2626const HOVER_DELAY = 180 ;
2727
28- export const MAX_HISTORY_ENTRIES = 100 ;
28+ export const MAX_HISTORY_ROWS = 50 ;
29+ export const MAX_HISTORY_ENTRIES = MAX_HISTORY_ROWS ;
2930
3031export function extractScheduleTimestamp ( schedule ) {
3132 if ( ! schedule || typeof schedule !== 'object' ) {
@@ -122,8 +123,7 @@ export function createBalanceHistoryEntry(schedule, options = {}) {
122123 return null ;
123124 }
124125
125- const previousRunNumber = Number . isFinite ( options . runNumber ) ? options . runNumber : 1 ;
126- const runNumber = previousRunNumber ;
126+ const runNumber = Number . isFinite ( options . runNumber ) ? options . runNumber : 1 ;
127127 const timestamp = extractScheduleTimestamp ( schedule ) ;
128128 const entry = {
129129 id : options . id || `${ runNumber } -${ Date . now ( ) } ` ,
@@ -267,8 +267,9 @@ export class RadialUrchin {
267267 this . shareContainer = null ;
268268 this . historyView = null ;
269269 this . balanceHistory = [ ] ;
270+ this . totalRunCount = 0 ;
270271 this . isHistoryOpen = false ;
271- this . maxHistoryEntries = MAX_HISTORY_ENTRIES ;
272+ this . maxHistoryEntries = MAX_HISTORY_ROWS ;
272273
273274 this . handleResize = this . handleResize . bind ( this ) ;
274275 this . handlePointerMove = this . handlePointerMove . bind ( this ) ;
@@ -569,7 +570,7 @@ export class RadialUrchin {
569570 this . updateHistoryUi ( ) ;
570571 }
571572
572- setBalanceHistory ( entries ) {
573+ setBalanceHistory ( entries , totalRunCount ) {
573574 const next = Array . isArray ( entries ) ? entries . slice ( - this . maxHistoryEntries ) : [ ] ;
574575 this . balanceHistory = next . map ( ( entry ) => ( {
575576 ...entry ,
@@ -580,10 +581,22 @@ export class RadialUrchin {
580581 ? entry . activities . map ( ( activity ) => ( { ...activity } ) )
581582 : [ ] ,
582583 } ) ) ;
584+ if ( Number . isFinite ( totalRunCount ) ) {
585+ this . totalRunCount = totalRunCount ;
586+ } else if ( this . balanceHistory . length > 0 ) {
587+ const latest = this . balanceHistory [ this . balanceHistory . length - 1 ] ;
588+ if ( latest && Number . isFinite ( latest . runNumber ) ) {
589+ this . totalRunCount = latest . runNumber ;
590+ } else {
591+ this . totalRunCount = this . balanceHistory . length ;
592+ }
593+ } else {
594+ this . totalRunCount = 0 ;
595+ }
583596 this . updateHistoryUi ( { refreshEntries : true } ) ;
584597 }
585598
586- appendBalanceHistoryEntry ( entry ) {
599+ appendBalanceHistoryEntry ( entry , totalRunCount ) {
587600 if ( ! entry || typeof entry !== 'object' ) {
588601 return ;
589602 }
@@ -596,32 +609,34 @@ export class RadialUrchin {
596609 ? entry . activities . map ( ( activity ) => ( { ...activity } ) )
597610 : [ ] ,
598611 } ;
599- const next = [ ... this . balanceHistory , normalized ] ;
600- if ( next . length > this . maxHistoryEntries ) {
601- next . splice ( 0 , next . length - this . maxHistoryEntries ) ;
602- }
612+ const next =
613+ this . balanceHistory . length >= this . maxHistoryEntries
614+ ? [ ... this . balanceHistory . slice ( 1 ) , normalized ]
615+ : [ ... this . balanceHistory , normalized ] ;
603616 this . balanceHistory = next ;
617+ if ( Number . isFinite ( totalRunCount ) ) {
618+ this . totalRunCount = totalRunCount ;
619+ } else if ( Number . isFinite ( normalized . runNumber ) ) {
620+ const previousTotal = Number . isFinite ( this . totalRunCount ) ? this . totalRunCount : 0 ;
621+ this . totalRunCount = Math . max ( previousTotal , normalized . runNumber ) ;
622+ } else {
623+ const previousTotal = Number . isFinite ( this . totalRunCount ) ? this . totalRunCount : 0 ;
624+ this . totalRunCount = previousTotal + 1 ;
625+ }
604626 this . updateHistoryUi ( { refreshEntries : true } ) ;
605627 }
606628
607629 captureBalanceSnapshot ( schedule , signature ) {
608- const previous =
609- this . balanceHistory . length > 0
610- ? this . balanceHistory [ this . balanceHistory . length - 1 ]
611- : null ;
612- const runNumber =
613- ( previous && Number . isFinite ( previous . runNumber )
614- ? previous . runNumber
615- : this . balanceHistory . length ) + 1 ;
630+ const nextRunNumber = ( Number . isFinite ( this . totalRunCount ) ? this . totalRunCount : 0 ) + 1 ;
616631 const entry = createBalanceHistoryEntry ( schedule , {
617- runNumber,
632+ runNumber : nextRunNumber ,
618633 highContrast : this . state . highContrast ,
619634 signature,
620635 } ) ;
621636 if ( ! entry ) {
622637 return ;
623638 }
624- this . appendBalanceHistoryEntry ( entry ) ;
639+ this . appendBalanceHistoryEntry ( entry , nextRunNumber ) ;
625640 }
626641
627642 getRunMetaSlot ( ) {
0 commit comments