Skip to content

Commit

Permalink
front: add a new util function to determine the style of an hovered path
Browse files Browse the repository at this point in the history
Signed-off-by: Math_R_ <[email protected]>
  • Loading branch information
Math-R committed Jan 16, 2025
1 parent 04d380d commit 51a7a73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { updateSelectedTrainId } from 'reducers/simulationResults';
import { useAppDispatch } from 'store';

import SettingsPanel from './SettingsPanel';
import { getIdFromTrainPath } from './utils';
import { getIdFromTrainPath, getPathStyle } from './utils';
import ManchetteMenuButton from '../SpaceTimeChart/ManchetteMenuButton';
import ProjectionLoadingMessage from '../SpaceTimeChart/ProjectionLoadingMessage';
import useWaypointMenu from '../SpaceTimeChart/useWaypointMenu';
Expand Down Expand Up @@ -393,7 +393,11 @@ const ManchetteWithSpaceTimeChartWrapper = ({
onHoveredChildUpdate={handleHoveredChildUpdate}
>
{spaceTimeChartProps.paths.map((path) => (
<PathLayer key={path.id} path={path} color={path.color} />
<PathLayer
key={path.id}
path={path}
{...getPathStyle(hoveredItem, path, !!draggingState)}
/>
))}
{workSchedules && (
<WorkScheduleLayer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
import type { PathLevel } from '@osrd-project/ui-spacetimechart';
import type { HoveredItem } from '@osrd-project/ui-spacetimechart/dist/lib/types';

import { PATH_COLORS } from 'modules/simulationResult/consts';

/* eslint-disable import/prefer-default-export */
export const getIdFromTrainPath = (trainPath: string): number => +trainPath.split('-')[0];

export const getPathStyle = (
hovered: HoveredItem | null,
path: { color: string; id: string },
dragging: boolean
): { color: string; level?: PathLevel } => {
if (hovered && 'pathId' in hovered.element && path.id === hovered?.element.pathId && !dragging) {
return { color: PATH_COLORS.HOVERED_PATH, level: 1 };
}
return { color: path.color };
};
4 changes: 4 additions & 0 deletions front/src/modules/simulationResult/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ export const ASPECT_LABELS_COLORS: Record<AspectLabel, string> = {
'080A': OCCUPANCY_BLOCKS_COLORS.GREY,
'000': OCCUPANCY_BLOCKS_COLORS.GREY,
};

export const PATH_COLORS = {
HOVERED_PATH: '#6B532E',
};

0 comments on commit 51a7a73

Please sign in to comment.