Skip to content

Commit 03f8b17

Browse files
committed
don't allocate new lanes when lanes above are free
1 parent 2390ecb commit 03f8b17

File tree

2 files changed

+17
-35
lines changed

2 files changed

+17
-35
lines changed

src/views/Validator/Browser/SessionPlayer/Timeline/TimelineActions.tsx

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@ interface TimelineActionsProps {
2323
}
2424

2525
interface Lane {
26-
id: number
27-
segments: Segment[]
26+
index: number
27+
segments: [Segment, ...Segment[]]
2828
}
2929

3030
interface Segment {
3131
id: string
32-
flex: number
3332
start: number
3433
end: number
35-
lane: number
3634
action: BrowserActionEvent
3735
}
3836

3937
function 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`

src/views/Validator/Browser/SessionPlayer/Timeline/TimelineSlider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export function TimelineSlider({
6161
// an extra element that is absolutely positioned and there's no way to target
6262
// it directly, so we need to target it using the :nth-child selector.
6363
> :nth-child(2) {
64-
top: -2px;
65-
bottom: -2px;
64+
top: -1px;
65+
bottom: -1px;
6666
}
6767
`}
6868
value={[time.current]}

0 commit comments

Comments
 (0)