@@ -21,6 +21,7 @@ import {
21
21
getLegBadgeProps ,
22
22
isCallAgencyLeg ,
23
23
getInterliningLegs ,
24
+ isFirstInterliningLeg ,
24
25
getTotalDistance ,
25
26
getRouteText ,
26
27
legTime ,
@@ -361,9 +362,6 @@ const Itinerary = (
361
362
let waitLength ;
362
363
const startMs = legTime ( leg . start ) ;
363
364
const endMs = legTime ( leg . end ) ;
364
- const isNextLegLast = i + 1 === compressedLegs . length - 1 ;
365
- const shouldRenderLastLeg =
366
- isNextLegLast && lastLegLength < renderBarThreshold ;
367
365
const previousLeg = i > 0 ? compressedLegs [ i - 1 ] : null ;
368
366
const nextLeg =
369
367
i < compressedLegs . length - 1 ? compressedLegs [ i + 1 ] : null ;
@@ -387,24 +385,37 @@ const Itinerary = (
387
385
}
388
386
}
389
387
390
- const [ interliningLines , interliningLegs ] = getInterliningLegs (
391
- compressedLegs ,
392
- i ,
393
- ) ;
394
-
395
- const lastLegWithInterline = interliningLegs [ interliningLegs . length - 1 ] ;
396
- if ( lastLegWithInterline ) {
388
+ if ( isFirstInterliningLeg ( compressedLegs , i ) ) {
389
+ const [ interliningLines , interliningLegs ] = getInterliningLegs (
390
+ compressedLegs ,
391
+ i ,
392
+ ) ;
397
393
interliningWithRoute = interliningLines . join ( ' / ' ) ;
398
- legLength =
399
- ( ( legTime ( lastLegWithInterline . end ) - startMs ) / durationWithoutSlack ) *
400
- 100 ;
394
+ const lastLegWithInterline = interliningLegs [ interliningLegs . length - 1 ] ;
395
+ legLength = relativeLength ( legTime ( lastLegWithInterline . end ) - startMs ) ;
396
+ if (
397
+ compressedLegs . length - 2 === i + interliningLegs . length &&
398
+ lastLegLength < renderBarThreshold
399
+ ) {
400
+ // If the last interlining leg is the next to last leg and
401
+ // if the last leg is too short add its length to the interlining leg.
402
+ legLength += lastLegLength ;
403
+ }
404
+ } else if ( leg . interlineWithPreviousLeg ) {
405
+ // Interlining legs after the first one should be skipped, this skips to the next index.
406
+ return ;
407
+ } else if (
408
+ compressedLegs . length - 2 === i &&
409
+ lastLegLength < renderBarThreshold
410
+ ) {
411
+ // Interlining legs handle this addition differently.
412
+ // If this leg is the next to last leg and
413
+ // if the last leg is too short add its length to the leg before it.
414
+ legLength += lastLegLength ;
401
415
}
416
+
402
417
legLength += addition ;
403
418
addition = 0 ;
404
-
405
- if ( shouldRenderLastLeg ) {
406
- legLength += lastLegLength ; // if the last leg is too short add its length to the leg before it
407
- }
408
419
if ( legLength < renderBarThreshold && isLegOnFoot ( leg ) ) {
409
420
// don't render short legs that are on foot at all
410
421
renderBar = false ;
@@ -593,25 +604,23 @@ const Itinerary = (
593
604
legLength > renderRouteNumberThreshold &&
594
605
! longName &&
595
606
transitLegCount < 7 ;
596
- if ( ! leg . interlineWithPreviousLeg ) {
597
- legs . push (
598
- < RouteLeg
599
- key = { `${ leg . mode } _${ startMs } ` }
600
- leg = { leg }
601
- fitRouteNumber = {
602
- ( fitAllRouteNumbers && ! longName ) || renderRouteNumberForALongLeg
603
- }
604
- interliningWithRoute = { interliningWithRoute }
605
- intl = { intl }
606
- legLength = { legLength }
607
- large = { breakpoint === 'large' }
608
- withBicycle = { withBicycle }
609
- withCar = { withCar }
610
- hasOneTransitLeg = { hasOneTransitLeg ( itinerary ) }
611
- shortenLabels = { shortenLabels }
612
- /> ,
613
- ) ;
614
- }
607
+ legs . push (
608
+ < RouteLeg
609
+ key = { `${ leg . mode } _${ startMs } ` }
610
+ leg = { leg }
611
+ fitRouteNumber = {
612
+ ( fitAllRouteNumbers && ! longName ) || renderRouteNumberForALongLeg
613
+ }
614
+ interliningWithRoute = { interliningWithRoute }
615
+ intl = { intl }
616
+ legLength = { legLength }
617
+ large = { breakpoint === 'large' }
618
+ withBicycle = { withBicycle }
619
+ withCar = { withCar }
620
+ hasOneTransitLeg = { hasOneTransitLeg ( itinerary ) }
621
+ shortenLabels = { shortenLabels }
622
+ /> ,
623
+ ) ;
615
624
vehicleNames . push (
616
625
formatMessage (
617
626
{
0 commit comments