Skip to content

Commit

Permalink
front: fix space time chart scales error
Browse files Browse the repository at this point in the history
For a brief moment, the computed scales passed to the space time chart can be an empty array.
Add a condition to be sure we render the chart only if there at least of scale.

Signed-off-by: SharglutDev <[email protected]>
  • Loading branch information
SharglutDev committed Oct 15, 2024
1 parent b4d2388 commit 31eca18
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const SimulationResults = ({
[projectionData]
);

// TODO: remove this after closing https://github.com/OpenRailAssociation/osrd-ui/issues/648
const projectPathTrainResult = useMemo(
() =>
projectionData?.projectedTrains.filter((train) => train.space_time_curves.length > 0) || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,24 @@ const ManchetteWithSpaceTimeChartWrapper = ({
height: `${heightOfManchetteWithSpaceTimeChart - 6}px`,
}}
>
<SpaceTimeChart
className="inset-0 absolute h-full"
spaceOrigin={
(waypointsPanelData?.filteredWaypoints ?? operationalPoints)[0]?.position || 0
}
timeOrigin={Math.min(...projectPathTrainResult.map((p) => +new Date(p.departure_time)))}
{...spaceTimeChartProps}
>
{spaceTimeChartProps.paths.map((path) => (
<PathLayer key={path.id} path={path} color={path.color} />
))}
</SpaceTimeChart>
{/* TODO: remove this condition after closing
https://github.com/OpenRailAssociation/osrd-ui/issues/648 */}
{spaceTimeChartProps.spaceScales.length > 0 && (
<SpaceTimeChart
className="inset-0 absolute h-full"
spaceOrigin={
(waypointsPanelData?.filteredWaypoints ?? operationalPoints)[0]?.position || 0
}
timeOrigin={Math.min(
...projectPathTrainResult.map((p) => +new Date(p.departure_time))
)}
{...spaceTimeChartProps}
>
{spaceTimeChartProps.paths.map((path) => (
<PathLayer key={path.id} path={path} color={path.color} />
))}
</SpaceTimeChart>
)}
</div>
</div>
</div>
Expand Down

0 comments on commit 31eca18

Please sign in to comment.