@@ -332,9 +332,9 @@ export function generateAlertsDateArray(alertsData: Array<Alert>): Array<number>
332332 }
333333
334334 // Add some padding to make the timeline more readable
335- // Padding: 10 % of the time span, minimum 1 hour, maximum 24 hours
335+ // Padding: 5 % of the time span, minimum 1 hour, maximum 24 hours
336336 const timeSpan = maxTimestamp - minTimestamp ;
337- const paddingSeconds = Math . max ( 3600 , Math . min ( 86400 , timeSpan * 0.1 ) ) ;
337+ const paddingSeconds = Math . max ( 3600 , Math . min ( 86400 , timeSpan * 0.05 ) ) ;
338338
339339 const paddedMin = minTimestamp - paddingSeconds ;
340340 const paddedMax = maxTimestamp + paddingSeconds ;
@@ -651,6 +651,36 @@ const onSelect = (event, selection, dispatch, incidentsActiveFilters, filterCate
651651 } ) ;
652652} ;
653653
654+ /**
655+ * Calculates the domain boundaries for the incidents chart timeline
656+ * @param dateValues - Array of timestamp values representing the ticks
657+ * @param chartData - Array of chart bar data containing incident information
658+ * @returns Domain boundaries as Date tuple or undefined if no data
659+ */
660+ export const calculateChartDomain = (
661+ dateValues : Array < number > ,
662+ chartData : Array < Array < any > > ,
663+ ) : [ Date , Date ] | undefined => {
664+ if ( dateValues . length === 0 ) return undefined ;
665+ let maxTimestamp = Math . max ( ...dateValues ) ;
666+
667+ // Find the maximum timestamp from chartData (incident data points)
668+ if ( chartData . length > 0 ) {
669+ const chartMaxTimestamp = Math . max ( ...chartData . flat ( ) . map ( ( bar ) => bar . y . getTime ( ) / 1000 ) ) ;
670+ maxTimestamp = Math . max ( maxTimestamp , chartMaxTimestamp ) ;
671+ }
672+
673+ // Calculate minTimestamp based on maxTimestamp and number of days
674+ const daysInSeconds = dateValues . length * 86400 ; // Convert days to seconds
675+ const minTimestamp = maxTimestamp - daysInSeconds ;
676+
677+ const timespan = maxTimestamp - minTimestamp ;
678+ const padding = timespan * 0.02 ;
679+ const domainMin = new Date ( ( minTimestamp - padding ) * 1000 ) ;
680+ const domainMax = new Date ( ( maxTimestamp + padding ) * 1000 ) ;
681+ return [ domainMin , domainMax ] as [ Date , Date ] ;
682+ } ;
683+
654684export const parseUrlParams = ( search ) => {
655685 const params = new URLSearchParams ( search ) ;
656686 const result : { [ key : string ] : any } = { } ;
0 commit comments