@@ -340,75 +340,81 @@ export default defineComponent({
340
340
}
341
341
342
342
function computeEventVerticalPosition (event : TimelineEvent ) {
343
- const offset = event .layer .groupsOnly ? 0 : 12
343
+ // Skip if the event is not visible
344
+ // or if the group graphics is not visible
345
+ if ((event .time >= startTime .value && event .time <= endTime .value ) ||
346
+ (event .group ?.firstEvent === event && event .group .lastEvent .time >= startTime .value && event .group .lastEvent .time <= endTime .value )) {
347
+ // Collision offset for non-flamecharts
348
+ const offset = event .layer .groupsOnly ? 0 : 12
344
349
345
- let y = 0
346
- if (event .group && event !== event .group .firstEvent ) {
347
- // If the event is inside a group, just use the group position
348
- y = event .group .y
349
- } else {
350
- const firstEvent = event .group ? event .group .firstEvent : event
351
- const lastEvent = event .group ? event .group .lastEvent : event
352
- const lastOffset = event .layer .groupsOnly && event .group ?.duration > 0 ? - 1 : 0
353
- // Check for 'collision' with other event groups
354
- const l = event .layer .groups .length
355
- let checkAgain = true
356
- while (checkAgain ) {
357
- checkAgain = false
358
- for (let i = 0 ; i < l ; i ++ ) {
359
- const otherGroup = event .layer .groups [i ]
360
- if (
361
- // Different group
362
- (
363
- ! event .group ||
364
- event .group !== otherGroup
365
- ) &&
366
- // Same row
367
- otherGroup .y === y &&
368
- (
369
- // Horizontal intersection (first event)
350
+ let y = 0
351
+ if (event .group && event !== event .group .firstEvent ) {
352
+ // If the event is inside a group, just use the group position
353
+ y = event .group .y
354
+ } else {
355
+ const firstEvent = event .group ? event .group .firstEvent : event
356
+ const lastEvent = event .group ? event .group .lastEvent : event
357
+ const lastOffset = event .layer .groupsOnly && event .group ?.duration > 0 ? - 1 : 0
358
+ // Check for 'collision' with other event groups
359
+ const l = event .layer .groups .length
360
+ let checkAgain = true
361
+ while (checkAgain ) {
362
+ checkAgain = false
363
+ for (let i = 0 ; i < l ; i ++ ) {
364
+ const otherGroup = event .layer .groups [i ]
365
+ if (
366
+ // Different group
370
367
(
371
- getTimePosition (firstEvent .time ) >= getTimePosition (otherGroup .firstEvent .time ) - offset &&
372
- getTimePosition (firstEvent .time ) <= getTimePosition (otherGroup .lastEvent .time ) + offset + lastOffset
373
- ) ||
374
- // Horizontal intersection (last event)
368
+ ! event .group ||
369
+ event .group !== otherGroup
370
+ ) &&
371
+ // Same row
372
+ otherGroup .y === y &&
375
373
(
376
- getTimePosition (lastEvent .time ) >= getTimePosition (otherGroup .firstEvent .time ) - offset - lastOffset &&
377
- getTimePosition (lastEvent .time ) <= getTimePosition (otherGroup .lastEvent .time ) + offset
374
+ // Horizontal intersection (first event)
375
+ (
376
+ getTimePosition (firstEvent .time ) >= getTimePosition (otherGroup .firstEvent .time ) - offset &&
377
+ getTimePosition (firstEvent .time ) <= getTimePosition (otherGroup .lastEvent .time ) + offset + lastOffset
378
+ ) ||
379
+ // Horizontal intersection (last event)
380
+ (
381
+ getTimePosition (lastEvent .time ) >= getTimePosition (otherGroup .firstEvent .time ) - offset - lastOffset &&
382
+ getTimePosition (lastEvent .time ) <= getTimePosition (otherGroup .lastEvent .time ) + offset
383
+ )
378
384
)
379
- )
380
- ) {
381
- // Collision!
382
- if ( event . group && event . group . duration > otherGroup . duration && firstEvent . time <= otherGroup . firstEvent . time ) {
383
- // Invert positions because current group has higher priority
384
- queueEventPositionUpdate ( otherGroup . firstEvent )
385
- } else {
386
- // Offset the current group/event
387
- y ++
388
- // We need to check all the layers again since we moved the event
389
- checkAgain = true
390
- break
385
+ ) {
386
+ // Collision!
387
+ if ( event . group && event . group . duration > otherGroup . duration && firstEvent . time <= otherGroup . firstEvent . time ) {
388
+ // Invert positions because current group has higher priority
389
+ queueEventPositionUpdate ( otherGroup . firstEvent )
390
+ } else {
391
+ // Offset the current group/event
392
+ y ++
393
+ // We need to check all the layers again since we moved the event
394
+ checkAgain = true
395
+ break
396
+ }
391
397
}
392
398
}
393
399
}
394
- }
395
400
396
- // If the event is the first in a group, update group position
397
- if (event .group ) {
398
- event .group .y = y
399
- }
401
+ // If the event is the first in a group, update group position
402
+ if (event .group ) {
403
+ event .group .y = y
404
+ }
400
405
401
- // Might update the layer's height as well
402
- if (y + 1 > event .layer .height ) {
403
- const oldLayerHeight = event .layer .height
404
- const newLayerHeight = event .layer .height = y + 1
405
- if (oldLayerHeight !== newLayerHeight ) {
406
- updateLayerPositions ()
407
- drawLayerBackgroundEffects ()
406
+ // Might update the layer's height as well
407
+ if (y + 1 > event .layer .height ) {
408
+ const oldLayerHeight = event .layer .height
409
+ const newLayerHeight = event .layer .height = y + 1
410
+ if (oldLayerHeight !== newLayerHeight ) {
411
+ updateLayerPositions ()
412
+ drawLayerBackgroundEffects ()
413
+ }
408
414
}
409
415
}
416
+ event .container .y = (y + 1 ) * LAYER_SIZE
410
417
}
411
- event .container .y = (y + 1 ) * LAYER_SIZE
412
418
413
419
// Next
414
420
updateEventPositionQueue .delete (event )
0 commit comments