-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 320 bug graphical timetable streckengrafik renders only one trai…
…nrun segement (#325) * Initial fix for sorting/orientation issue - partial progress * Added documentation and comments * Propagated consecutiveTime over each train run segment separately * Removed debug console logs (clean) * Fixed lint issues * Updated CREATE_TRAINRUN.md with images * Improved code (array.concat and indexOf) for data filtering * Fixed train run part issue in pearls view * Refactored and cleaned up code, added tests * Enhanced UX and documentation --------- Co-authored-by: Serge Croisé <[email protected]>
- Loading branch information
1 parent
ff3e72c
commit 790f53b
Showing
13 changed files
with
584 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Trainrun iterator | ||
|
||
## Sample code | ||
|
||
https://github.com/SchweizerischeBundesbahnen/netzgrafik-editor-frontend/pull/325 | ||
|
||
### Simple trainrun iterator - just one trainrun part | ||
To iterate starting from a node of interest with the orientation passed through the trainrun section, you can use the sample code (pattern) below. | ||
The iteration will proceed along the trainrun. Be aware that this does not ensure traveling through the full train run. | ||
|
||
https://github.com/SchweizerischeBundesbahnen/netzgrafik-editor-frontend/blob/main/documentation/CREATE_TRAINRUN.md#trainrun-path-with-holes-missing-sections | ||
|
||
```typescript | ||
|
||
// create forward iterator | ||
const iterator: TrainrunIterator = this.trainrunService.getIterator( | ||
startForwardNode, | ||
startTrainrunSection, | ||
); | ||
while (iterator.hasNext()) { | ||
// move iterator forward | ||
const currentTrainrunSectionNodePair = iterator.next(); | ||
|
||
// get data | ||
const trainrunSection = currentTrainrunSectionNodePair.trainrunSection; | ||
const node = currentTrainrunSectionNodePair.node; | ||
|
||
... | ||
user | ||
defined | ||
data | ||
processing | ||
... | ||
|
||
} | ||
} | ||
``` | ||
|
||
### Complete Train Run Iterator - Over All Train Run Parts | ||
Iterator pattern for iterating through all train run parts separately. | ||
|
||
```typescript | ||
getForwardTrainrunPartIterator(trainrunSection : TrainrunSection) { | ||
// find both start nodes ( N1 - N2 - N3 - N4 ) => N1 , N2 | ||
const bothEndNodes = | ||
this.trainrunService.getBothEndNodesFromTrainrunPart(trainrunSection); | ||
|
||
// get start / end node from Top/Left -> Botton / Right | ||
const startForwardNode = GeneralViewFunctions.getLeftOrTopNode( | ||
bothEndNodes.endNode1, | ||
bothEndNodes.endNode2, | ||
); | ||
|
||
// get start trainrun section -> forward direction/orientation | ||
const startTrainrunSection = startForwardNode.getStartTrainrunSection( | ||
trainrun.getId(), | ||
); | ||
|
||
// create forward iterator | ||
const iterator: TrainrunIterator = this.trainrunService.getIterator( | ||
startForwardNode, | ||
startTrainrunSection, | ||
); | ||
return iterator; | ||
} | ||
|
||
simpleTrainrunAllPartsIterator(trainrun: Trainrun) { | ||
let alltrainrunsections = | ||
this.trainrunSectionService | ||
.getAllTrainrunSectionsForTrainrun(trainrun.getId()); | ||
|
||
while (alltrainrunsections.length > 0) { | ||
// traverse over all trainrun parts | ||
const iterator= getForwardTrainrunPartIterator(alltrainrunsections[0]); | ||
|
||
while (iterator.hasNext()) { | ||
// move iterator forward | ||
const currentTrainrunSectionNodePair = iterator.next(); | ||
|
||
// get data | ||
const trainrunSection = currentTrainrunSectionNodePair.trainrunSection; | ||
const node = currentTrainrunSectionNodePair.node; | ||
|
||
... | ||
user | ||
defined | ||
data | ||
processing | ||
... | ||
|
||
// filter all still visited trainrun sections | ||
alltrainrunsections = alltrainrunsections.filter(ts => | ||
ts.getId() !== trainrunSection.getId() | ||
); | ||
} | ||
|
||
|
||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.