@@ -139,8 +139,11 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
139139 }
140140
141141 private getEdgeLineTextOddOffsetClass ( n : Node , timeSelector : "Departure" | "Arrival" ) {
142- const tr = this . trainrunService . getSelectedTrainrun ( ) ;
143- const trainrunSection = n . getTrainrunSection ( tr ) ;
142+ const selectedTrainrun = this . trainrunService . getSelectedTrainrun ( ) ;
143+ if ( ! selectedTrainrun ) {
144+ return "" ;
145+ }
146+ const trainrunSection = n . getEndingTrainrunSection ( selectedTrainrun ) ;
144147 if ( timeSelector === "Departure" ) {
145148 return TrainrunSectionsView . getTrainrunSectionTimeElementOddOffsetTag (
146149 trainrunSection . getTargetNodeId ( ) === n . getId ( )
@@ -208,43 +211,30 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
208211 return undefined ;
209212 }
210213 const selectedTrainrunId = selectedTrainrun . getId ( ) ;
211- const trainrunSections =
212- this . trainrunSectionService . getAllTrainrunSectionsForTrainrun ( selectedTrainrunId ) ;
213214 const [ startNode , endNode ] = [
214215 this . trainrunService . getLeftOrTopNodeWithTrainrunId ( selectedTrainrunId ) ,
215216 this . trainrunService . getRightOrBottomNodeWithTrainrunId ( selectedTrainrunId ) ,
216217 ] ;
217218
218- // Try to find startNode → endNode
219- let firstTrainrunSection = trainrunSections . find (
220- ( ts ) => ts . getSourceNodeId ( ) === startNode . getId ( ) ,
221- ) ;
222- let lastTrainrunSection = [ ...trainrunSections ]
223- . reverse ( )
224- . find ( ( ts ) => ts . getTargetNodeId ( ) === endNode . getId ( ) ) ;
225-
226- // If not found, swap first and last sections (and source and target nodes)
227- if ( ! firstTrainrunSection && ! lastTrainrunSection ) {
228- firstTrainrunSection = trainrunSections . find (
229- ( ts ) => ts . getSourceNodeId ( ) === endNode . getId ( ) ,
230- ) ;
231- lastTrainrunSection = [ ...trainrunSections ]
232- . reverse ( )
233- . find ( ( ts ) => ts . getTargetNodeId ( ) === startNode . getId ( ) ) ;
234- [ firstTrainrunSection , lastTrainrunSection ] = [ lastTrainrunSection , firstTrainrunSection ] ;
235- return {
236- leftDepartureTime : firstTrainrunSection . getTargetDeparture ( ) ,
237- leftArrivalTime : firstTrainrunSection . getTargetArrival ( ) ,
238- rightDepartureTime : lastTrainrunSection . getSourceDeparture ( ) ,
239- rightArrivalTime : lastTrainrunSection . getSourceArrival ( ) ,
240- } ;
241- }
219+ const firstTrainrunSection = startNode . getEndingTrainrunSection ( selectedTrainrun ) ;
220+ const lastTrainrunSection = endNode . getEndingTrainrunSection ( selectedTrainrun ) ;
221+
222+ const isFirstSectionAtSourceNode = firstTrainrunSection . getSourceNodeId ( ) === startNode . getId ( ) ;
223+ const isLastSectionAtSourceNode = lastTrainrunSection . getSourceNodeId ( ) === endNode . getId ( ) ;
242224
243225 return {
244- leftDepartureTime : firstTrainrunSection . getSourceDeparture ( ) ,
245- leftArrivalTime : firstTrainrunSection . getSourceArrival ( ) ,
246- rightDepartureTime : lastTrainrunSection . getTargetDeparture ( ) ,
247- rightArrivalTime : lastTrainrunSection . getTargetArrival ( ) ,
226+ leftDepartureTime : isFirstSectionAtSourceNode
227+ ? firstTrainrunSection . getSourceDeparture ( )
228+ : firstTrainrunSection . getTargetDeparture ( ) ,
229+ leftArrivalTime : isFirstSectionAtSourceNode
230+ ? firstTrainrunSection . getSourceArrival ( )
231+ : firstTrainrunSection . getTargetArrival ( ) ,
232+ rightDepartureTime : isLastSectionAtSourceNode
233+ ? lastTrainrunSection . getSourceDeparture ( )
234+ : lastTrainrunSection . getTargetDeparture ( ) ,
235+ rightArrivalTime : isLastSectionAtSourceNode
236+ ? lastTrainrunSection . getSourceArrival ( )
237+ : lastTrainrunSection . getTargetArrival ( ) ,
248238 } ;
249239 }
250240}
0 commit comments