Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: spacetimechart: fix drag behaviour when draging train to the left #10625

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
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 @@ -3,6 +3,7 @@ import { useEffect, useState, useMemo } from 'react';
import { ChevronLeft, ChevronRight } from '@osrd-project/ui-icons';
import cx from 'classnames';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { type Conflict } from 'common/api/osrdEditoastApi';
import SimulationWarpedMap from 'common/Map/WarpedMap/SimulationWarpedMap';
Expand All @@ -23,6 +24,7 @@ import TimesStopsOutput from 'modules/timesStops/TimesStopsOutput';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import { updateViewport, type Viewport } from 'reducers/map';
import { updateSelectedTrainId } from 'reducers/simulationResults';
import { getTrainIdUsedForProjection } from 'reducers/simulationResults/selectors';
import { useAppDispatch } from 'store';
import { getPointCoordinates } from 'utils/geometry';

Expand Down Expand Up @@ -64,6 +66,8 @@ const SimulationResults = ({
path,
} = useSimulationResults();

const trainIdUsedForProjection = useSelector(getTrainIdUsedForProjection);

const [extViewport, setExtViewport] = useState<Viewport>();
const [showWarpedMap, setShowWarpedMap] = useState(false);

Expand Down Expand Up @@ -203,21 +207,24 @@ const SimulationResults = ({

<div className="osrd-simulation-container d-flex flex-grow-1 flex-shrink-1">
<div className="chart-container">
<ManchetteWithSpaceTimeChartWrapper
operationalPoints={projectedOperationalPoints}
projectPathTrainResult={projectPathTrainResult}
selectedTrainScheduleId={selectedTrainSchedule?.id}
waypointsPanelData={{
filteredWaypoints: filteredOperationalPoints,
setFilteredWaypoints: setFilteredOperationalPoints,
projectionPath: projectionData.trainSchedule.path,
}}
conflicts={conflictZones}
projectionLoaderData={projectionData.projectionLoaderData}
height={manchetteWithSpaceTimeChartHeight - MANCHETTE_HEIGHT_DIFF}
handleTrainDrag={handleTrainDrag}
onTrainClick={(trainId) => dispatch(updateSelectedTrainId(trainId))}
/>
{trainIdUsedForProjection && (
<ManchetteWithSpaceTimeChartWrapper
operationalPoints={projectedOperationalPoints}
projectPathTrainResult={projectPathTrainResult}
selectedTrainScheduleId={selectedTrainSchedule?.id}
waypointsPanelData={{
filteredWaypoints: filteredOperationalPoints,
setFilteredWaypoints: setFilteredOperationalPoints,
projectionPath: projectionData.trainSchedule.path,
}}
conflicts={conflictZones}
projectionLoaderData={projectionData.projectionLoaderData}
height={manchetteWithSpaceTimeChartHeight - MANCHETTE_HEIGHT_DIFF}
handleTrainDrag={handleTrainDrag}
onTrainClick={(trainId) => dispatch(updateSelectedTrainId(trainId))}
selectedProjection={trainIdUsedForProjection}
/>
)}
</div>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type ManchetteWithSpaceTimeChartProps = {
) => Promise<void>;
height?: number;
onTrainClick?: (trainId: number) => void;
selectedProjection?: number;
};

export const MANCHETTE_WITH_SPACE_TIME_CHART_DEFAULT_HEIGHT = 561;
Expand All @@ -80,6 +81,7 @@ const ManchetteWithSpaceTimeChartWrapper = ({
height = MANCHETTE_WITH_SPACE_TIME_CHART_DEFAULT_HEIGHT,
handleTrainDrag,
onTrainClick,
selectedProjection,
}: ManchetteWithSpaceTimeChartProps) => {
const dispatch = useAppDispatch();

Expand All @@ -95,6 +97,15 @@ const ManchetteWithSpaceTimeChartWrapper = ({

const [waypointsPanelIsOpen, setWaypointsPanelIsOpen] = useState(false);

const [minDepartureTime, setMinDepartureTime] = useState<number | null>(null);
useEffect(() => {
const projectedTrains = projectPathTrainResult.filter(
(train) => train.spaceTimeCurves.length > 0
);
const minTime = Math.min(...projectedTrains.map((p) => +p.departureTime));
setMinDepartureTime(minTime);
}, [selectedProjection, projectPathTrainResult.length]);

const [tmpSelectedTrain, setTmpSelectedTrain] = useState(selectedTrainScheduleId);
useEffect(() => {
setTmpSelectedTrain(selectedTrainScheduleId);
Expand Down Expand Up @@ -381,41 +392,43 @@ const ManchetteWithSpaceTimeChartWrapper = ({
onClose={() => setShowSettingsPanel(false)}
/>
)}
<SpaceTimeChart
className="inset-0 absolute h-full"
height={height}
spaceOrigin={
(waypointsPanelData?.filteredWaypoints ?? operationalPoints).at(0)?.position || 0
}
timeOrigin={Math.min(...projectPathTrainResult.map((p) => +p.departureTime))}
{...spaceTimeChartProps}
onPan={onPanOverloaded}
onClick={handleClick}
onHoveredChildUpdate={handleHoveredChildUpdate}
>
{spaceTimeChartProps.paths.map((path) => (
<PathLayer
key={path.id}
path={path}
{...getPathStyle(hoveredItem, path, !!draggingState)}
/>
))}
{workSchedules && (
<WorkScheduleLayer
workSchedules={workSchedules.map((ws) => ({
type: ws.type,
timeStart: new Date(ws.start_date_time),
timeEnd: new Date(ws.end_date_time),
spaceRanges: ws.path_position_ranges.map(({ start, end }) => [start, end]),
}))}
imageUrl={upward}
/>
)}
{settings.showConflicts && <ConflictLayer conflicts={cutConflicts} />}
{settings.showSignalsStates && (
<OccupancyBlockLayer occupancyBlocks={occupancyBlocks} />
)}
</SpaceTimeChart>
{minDepartureTime !== null && (
<SpaceTimeChart
className="inset-0 absolute h-full"
height={height}
spaceOrigin={
(waypointsPanelData?.filteredWaypoints ?? operationalPoints).at(0)?.position || 0
}
timeOrigin={minDepartureTime}
{...spaceTimeChartProps}
onPan={onPanOverloaded}
onClick={handleClick}
onHoveredChildUpdate={handleHoveredChildUpdate}
>
{spaceTimeChartProps.paths.map((path) => (
<PathLayer
key={path.id}
path={path}
{...getPathStyle(hoveredItem, path, !!draggingState)}
/>
))}
{workSchedules && (
<WorkScheduleLayer
workSchedules={workSchedules.map((ws) => ({
type: ws.type,
timeStart: new Date(ws.start_date_time),
timeEnd: new Date(ws.end_date_time),
spaceRanges: ws.path_position_ranges.map(({ start, end }) => [start, end]),
}))}
imageUrl={upward}
/>
)}
{settings.showConflicts && <ConflictLayer conflicts={cutConflicts} />}
{settings.showSignalsStates && (
<OccupancyBlockLayer occupancyBlocks={occupancyBlocks} />
)}
</SpaceTimeChart>
)}
</div>
</div>
<Slider
Expand Down
Loading