@@ -23,23 +23,21 @@ interface TimelineActionsProps {
2323}
2424
2525interface Lane {
26- id : number
27- segments : Segment [ ]
26+ index : number
27+ segments : [ Segment , ... Segment [ ] ]
2828}
2929
3030interface Segment {
3131 id : string
32- flex : number
3332 start : number
3433 end : number
35- lane : number
3634 action : BrowserActionEvent
3735}
3836
3937function buildLanes ( actions : BrowserActionEvent [ ] , time : Time ) {
40- const segments : Segment [ ] = [ ]
38+ const lanes : Lane [ ] = [ ]
4139
42- for ( const [ index , action ] of actions . entries ( ) ) {
40+ for ( const action of actions ) {
4341 if ( action . timestamp . started > time . end ) {
4442 continue
4543 }
@@ -50,42 +48,26 @@ function buildLanes(actions: BrowserActionEvent[], time: Time) {
5048 const start = Math . max ( 0 , actionStarted - time . start )
5149 const end = Math . min ( time . total , actionEnded - time . start )
5250
53- const duration = Math . max ( 0 , end - start )
54-
5551 const segment : Segment = {
5652 id : action . eventId ,
57- flex : duration ,
5853 start,
5954 end,
60- lane : 0 ,
6155 action,
6256 }
6357
64- // We need to figure out which lane the segment should be in.
65- //
66- // We do this by walking backwards through the segments until we find a
67- // segment that doesn't intersect with the current segment. The segment's
68- // lane is one lane above the top-most intersecting segment's lane.
69- for ( let i = index - 1 ; i >= 0 ; i -- ) {
70- const previous = segments [ i ]
71-
72- if ( previous === undefined || ! isIntersecting ( previous , segment ) ) {
73- break
74- }
75-
76- segment . lane = Math . max ( segment . lane , previous . lane + 1 )
77- }
78-
79- segments . push ( segment )
80- }
81-
82- const lanes : Lane [ ] = [ ]
58+ /**
59+ * From top-to-bottom, find the first lane that doesn't intersect with the current segment.
60+ * This is the lane where we will put the current segment. If no such lane exists, we will
61+ * hvae to create a new lane.
62+ */
63+ const lane = lanes . find ( ( lane ) => {
64+ const lastSegment = lane . segments [ lane . segments . length - 1 ]
8365
84- for ( const segment of segments ) {
85- const lane = lanes [ segment . lane ]
66+ return lastSegment !== undefined && ! isIntersecting ( lastSegment , segment )
67+ } )
8668
8769 if ( lane === undefined ) {
88- lanes [ segment . lane ] = { id : segment . lane , segments : [ segment ] }
70+ lanes . push ( { index : lanes . length , segments : [ segment ] } )
8971
9072 continue
9173 }
@@ -220,7 +202,7 @@ export function TimelineActions({
220202 padding-bottom : 6px ;
221203 ` }
222204 >
223- { lanes . map ( ( { id, segments } ) => (
205+ { lanes . map ( ( { index : id , segments } ) => (
224206 < div
225207 key = { id }
226208 css = { css `
0 commit comments