@@ -26,6 +26,7 @@ export const description = "An interactive area chart";
2626const ChartType = {
2727 IncidentsCount : "incidentsCount" ,
2828 IncidentsAvgDuration : "incidentsAvgDuration" ,
29+ IncidentsTotalDuration : "incidentsTotalDuration" ,
2930} as const ;
3031
3132type ChartType = ( typeof ChartType ) [ keyof typeof ChartType ] ;
@@ -35,6 +36,8 @@ interface IncidentStatsItem {
3536 count : number ;
3637 avg_duration : number ; // in seconds
3738 avg_duration_human : string ; // for human-readable format
39+ total_duration : number ; // in seconds
40+ total_duration_human : string ; // for human-readable format
3841}
3942
4043export function ChartIncidentsStats ( ) {
@@ -52,11 +55,15 @@ export function ChartIncidentsStats() {
5255 label :
5356 chartType === ChartType . IncidentsCount
5457 ? "Incidents Count"
55- : "Avg Duration" ,
58+ : chartType === ChartType . IncidentsAvgDuration
59+ ? "Avg Duration"
60+ : "Total Duration" ,
5661 color :
5762 chartType === ChartType . IncidentsCount
58- ? "var(--chart-1)"
59- : "var(--chart-2)" ,
63+ ? "var(--chart-6)"
64+ : chartType === ChartType . IncidentsAvgDuration
65+ ? "var(--chart-2)"
66+ : "var(--chart-3)" ,
6067 } ,
6168 } ) ,
6269 [ chartType ]
@@ -92,6 +99,8 @@ export function ChartIncidentsStats() {
9299 count : item . count || 0 ,
93100 avg_duration : item . avg_duration || 0 ,
94101 avg_duration_human : item . avg_duration_human || "" ,
102+ total_duration : item . total_duration || 0 ,
103+ total_duration_human : item . total_duration_human || "" ,
95104 } ) ) ;
96105 setIncidentsData ( formattedData ) ;
97106 } )
@@ -109,13 +118,16 @@ export function ChartIncidentsStats() {
109118 const dataKey =
110119 chartType === ChartType . IncidentsCount
111120 ? item . count
112- : Math . round ( item . avg_duration ) ;
121+ : chartType === ChartType . IncidentsAvgDuration
122+ ? Math . round ( item . avg_duration )
123+ : Math . round ( item . total_duration ) ;
113124
114125 return {
115126 date : item . date ,
116127 incidents : dataKey ,
117128 count : item . count ,
118129 avg_duration_human : item . avg_duration_human ,
130+ total_duration_human : item . total_duration_human ,
119131 formattedDate : date . toLocaleDateString ( "en-US" , {
120132 month : "short" ,
121133 day : "numeric" ,
@@ -159,6 +171,12 @@ export function ChartIncidentsStats() {
159171 >
160172 Average duration
161173 </ SelectItem >
174+ < SelectItem
175+ value = { ChartType . IncidentsTotalDuration }
176+ className = "rounded-lg"
177+ >
178+ Total duration
179+ </ SelectItem >
162180 </ SelectContent >
163181 </ Select >
164182
@@ -194,17 +212,21 @@ export function ChartIncidentsStats() {
194212 offset = "5%"
195213 stopColor = {
196214 chartType === ChartType . IncidentsCount
197- ? "var(--chart-1)"
198- : "var(--chart-2)"
215+ ? "var(--chart-6)"
216+ : chartType === ChartType . IncidentsAvgDuration
217+ ? "var(--chart-2)"
218+ : "var(--chart-3)"
199219 }
200220 stopOpacity = { 0.8 }
201221 />
202222 < stop
203223 offset = "95%"
204224 stopColor = {
205225 chartType === ChartType . IncidentsCount
206- ? "var(--chart-1)"
207- : "var(--chart-2)"
226+ ? "var(--chart-6)"
227+ : chartType === ChartType . IncidentsAvgDuration
228+ ? "var(--chart-2)"
229+ : "var(--chart-3)"
208230 }
209231 stopOpacity = { 0.1 }
210232 />
@@ -248,12 +270,16 @@ export function ChartIncidentsStats() {
248270 < span className = "text-[0.70rem] uppercase text-muted-foreground" >
249271 { chartType === ChartType . IncidentsCount
250272 ? "Count"
251- : "Duration" }
273+ : chartType === ChartType . IncidentsAvgDuration
274+ ? "Avg Duration"
275+ : "Total Duration" }
252276 </ span >
253277 < span className = "font-bold" >
254- { chartType === ChartType . IncidentsAvgDuration
255- ? data . avg_duration_human || "0s"
256- : data . count }
278+ { chartType === ChartType . IncidentsCount
279+ ? data . count
280+ : chartType === ChartType . IncidentsAvgDuration
281+ ? data . avg_duration_human || "0s"
282+ : data . total_duration_human || "0s" }
257283 </ span >
258284 </ div >
259285 </ div >
@@ -269,8 +295,10 @@ export function ChartIncidentsStats() {
269295 fill = "url(#fillIncidents)"
270296 stroke = {
271297 chartType === ChartType . IncidentsCount
272- ? "var(--chart-1)"
273- : "var(--chart-2)"
298+ ? "var(--chart-6)"
299+ : chartType === ChartType . IncidentsAvgDuration
300+ ? "var(--chart-2)"
301+ : "var(--chart-3)"
274302 }
275303 />
276304 </ AreaChart >
0 commit comments