Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ import {
} from 'reducers/simulationResults/selectors';
import type { SelectionSource } from 'reducers/simulationResults/types';
import { useAppDispatch } from 'store';
import { Duration } from 'utils/duration';
import { Duration, subtractDurationFromDate } from 'utils/duration';
import { usePrevious } from 'utils/hooks/state';
import {
extractEditoastIdFromTrainScheduleId,
extractExceptionIdFromOccurrenceId,
Expand Down Expand Up @@ -522,13 +523,23 @@ const SpaceTimeChartWrapper = ({
(waypointsPanelData?.filteredWaypoints ?? operationalPoints).at(0)?.position || 0,
});

const previousProjectionId = usePrevious(selectedProjectionId);

useEffect(() => {
const trainId = isTrainScheduleId(selectedProjectionId)
const firstOccurrenceId = isTrainScheduleId(selectedProjectionId)
? formatTrainScheduleIdToIndexedOccurrenceId(selectedProjectionId, 0)
: selectedProjectionId;
const trainUsedForProjection = projectedTrains.find((train) => train.id === trainId);
: undefined;
const trainUsedForProjection = projectedTrains.find(
(train) => train.id === selectedProjectionId || train.id === firstOccurrenceId
);
if (trainUsedForProjection) {
setTimeOrigin(+trainUsedForProjection.departureTime);
// Center the view on the newly projected train (+5mn).
setTimeOrigin(
+subtractDurationFromDate(trainUsedForProjection.departureTime, new Duration({ minutes: 5 }))
);
if (previousProjectionId !== selectedProjectionId && spaceTimeChartProps.xOffset) {
pan({ dx: -spaceTimeChartProps.xOffset });
}
Comment on lines +540 to +542

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see the difference from the previous behavior with this new condition ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this condition if we remove or add a train to the timetable, we won't loose the actual pan on the std.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some docs above this condition to explain the purpose of it then ? :)

} else {
const minTime = Math.min(
...trainScheduleProjections
Expand Down
Loading