Skip to content

Commit b1b4eed

Browse files
committed
fix: fix incidents timeline X domain
1 parent 6102a5f commit b1b4eed

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import '../incidents-styles.css';
2727
import { IncidentsTooltip } from '../IncidentsTooltip';
2828
import { Incident } from '../model';
29-
import { createIncidentsChartBars, generateDateArray } from '../utils';
29+
import { calculateChartDomain, createIncidentsChartBars, generateDateArray } from '../utils';
3030
import { dateTimeFormatter } from '../../console/utils/datetime';
3131
import { useTranslation } from 'react-i18next';
3232

@@ -172,6 +172,7 @@ const IncidentsChart = ({
172172
tickLabelComponent={
173173
<ChartLabel style={{ fill: theme === 'light' ? '#1b1d21' : '#e0e0e0' }} />
174174
}
175+
domain={calculateChartDomain(dateValues, chartData)}
175176
/>
176177
<ChartGroup horizontal>
177178
{chartData.map((bar) => {

web/src/components/Incidents/utils.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
654684
export const parseUrlParams = (search) => {
655685
const params = new URLSearchParams(search);
656686
const result: { [key: string]: any } = {};

0 commit comments

Comments
 (0)