55 TimelineSpanEventMarker ,
66 type TTimelineSpanEventMarker ,
77} from './TimelineSpanEventMarker' ;
8+ import { renderMs } from './utils' ;
89
910export type TTimelineEvent = {
1011 id : string ;
@@ -17,6 +18,7 @@ export type TTimelineEvent = {
1718 minWidthPerc ?: number ;
1819 isError ?: boolean ;
1920 markers ?: TTimelineSpanEventMarker [ ] ;
21+ showDuration ?: boolean ;
2022} ;
2123
2224type TimelineChartRowProps = {
@@ -57,6 +59,12 @@ export const TimelineChartRowEvents = memo(function ({
5759 const percMarginLeft =
5860 scale * ( ( ( e . start - lastEventEnd ) / maxVal ) * 100 ) ;
5961
62+ const durationMs = e . end - e . start ;
63+ const barCenter = ( e . start + e . end ) / 2 ;
64+ const timelineMidpoint = maxVal / 2 ;
65+ // Duration on left when majority of bar is past halfway, otherwise on right
66+ const durationOnRight = barCenter <= timelineMidpoint ;
67+
6068 return (
6169 < Tooltip
6270 key = { e . id }
@@ -72,32 +80,60 @@ export const TimelineChartRowEvents = memo(function ({
7280 } }
7381 >
7482 < div
75- onMouseEnter = { ( ) => onEventHover ?.( e . id ) }
76- className = "d-flex align-items-center h-100 cursor-pointer text-truncate hover-opacity"
7783 style = { {
78- userSelect : 'none ' ,
84+ position : 'relative ' ,
7985 minWidth : `${ percWidth . toFixed ( 6 ) } %` ,
8086 width : `${ percWidth . toFixed ( 6 ) } %` ,
8187 marginLeft : `${ percMarginLeft . toFixed ( 6 ) } %` ,
82- position : 'relative' ,
83- borderRadius : 2 ,
84- fontSize : height * 0.5 ,
85- color : e . color ,
86- backgroundColor : e . backgroundColor ,
88+ // overflow: 'visible',
8789 } }
8890 >
89- < div style = { { margin : 'auto' } } className = "px-2" >
90- { e . body }
91+ < div
92+ onMouseEnter = { ( ) => onEventHover ?.( e . id ) }
93+ className = "d-flex align-items-center h-100 cursor-pointer text-truncate hover-opacity"
94+ style = { {
95+ userSelect : 'none' ,
96+ width : '100%' ,
97+ position : 'relative' ,
98+ borderRadius : 2 ,
99+ fontSize : height * 0.5 ,
100+ color : e . color ,
101+ backgroundColor : e . backgroundColor ,
102+ } }
103+ >
104+ < div style = { { margin : 'auto' } } className = "px-2" >
105+ { e . body }
106+ </ div >
107+ { e . markers ?. map ( ( marker , idx ) => (
108+ < TimelineSpanEventMarker
109+ key = { `${ e . id } -marker-${ idx } ` }
110+ marker = { marker }
111+ eventStart = { e . start }
112+ eventEnd = { e . end }
113+ height = { height }
114+ />
115+ ) ) }
91116 </ div >
92- { e . markers ?. map ( ( marker , idx ) => (
93- < TimelineSpanEventMarker
94- key = { `${ e . id } -marker-${ idx } ` }
95- marker = { marker }
96- eventStart = { e . start }
97- eventEnd = { e . end }
98- height = { height }
99- />
100- ) ) }
117+ { ! ! e . showDuration && (
118+ < span
119+ style = { {
120+ position : 'absolute' ,
121+ top : 0 ,
122+ height : '100%' ,
123+ display : 'flex' ,
124+ alignItems : 'center' ,
125+ fontSize : height * 0.5 ,
126+ color : 'var(--color-text)' ,
127+ whiteSpace : 'nowrap' ,
128+ pointerEvents : 'none' ,
129+ ...( durationOnRight
130+ ? { left : '100%' , marginLeft : 4 }
131+ : { right : '100%' , marginRight : 4 } ) ,
132+ } }
133+ >
134+ { renderMs ( durationMs ) }
135+ </ span >
136+ ) }
101137 </ div >
102138 </ Tooltip >
103139 ) ;
0 commit comments