Skip to content

Commit 4f2b1e3

Browse files
committed
ui-manchette: highlight selected train
1 parent f95f2c6 commit 4f2b1e3

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

ui-manchette/src/components/Manchette.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useIsOverflow } from '../hooks/useIsOverFlow';
2323
type ManchetteProps = {
2424
operationalPoints: OperationalPointType[];
2525
projectPathTrainResult: ProjectPathTrainResult[];
26+
selectedProjection?: number;
2627
};
2728
import usePaths from '../hooks/usePaths';
2829
import type {
@@ -32,7 +33,11 @@ import type {
3233
} from '../types';
3334
import { getDiff } from '../utils/vector';
3435

35-
const Manchette: FC<ManchetteProps> = ({ operationalPoints, projectPathTrainResult }) => {
36+
const Manchette: FC<ManchetteProps> = ({
37+
operationalPoints,
38+
projectPathTrainResult,
39+
selectedProjection,
40+
}) => {
3641
const manchette = useRef<HTMLDivElement>(null);
3742

3843
const [state, setState] = useState<{
@@ -74,7 +79,7 @@ const Manchette: FC<ManchetteProps> = ({ operationalPoints, projectPathTrainResu
7479
scales,
7580
} = state;
7681

77-
const paths = usePaths(projectPathTrainResult);
82+
const paths = usePaths(projectPathTrainResult, selectedProjection);
7883

7984
const zoomYIn = useCallback(() => {
8085
if (yZoom < MAX_ZOOM_Y) setState((prev) => ({ ...prev, yZoom: yZoom + ZOOM_Y_DELTA }));

ui-manchette/src/hooks/usePaths.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ const transformCurve = (curve: SpaceTimeCurves, departureTime: string) =>
88
position,
99
}));
1010

11-
const usePaths = (projectPathTrainResult: ProjectPathTrainResult[]) =>
11+
const usePaths = (projectPathTrainResult: ProjectPathTrainResult[], selectedProjection?: number) =>
1212
useMemo(
1313
() =>
14-
projectPathTrainResult.map((path, index) => ({
15-
id: path.departure_time,
16-
label: `Train ${index + 1}`,
17-
color: '#000000',
14+
projectPathTrainResult.map((path) => ({
15+
id: `${path.id}`,
16+
label: path.name,
17+
color: selectedProjection && selectedProjection === path.id ? '#201EDE' : '#000000',
1818
points: path.space_time_curves.flatMap((curve) =>
1919
transformCurve(curve, path.departure_time)
2020
),
2121
})),
22-
[projectPathTrainResult]
22+
[projectPathTrainResult, selectedProjection]
2323
);
2424

2525
export default usePaths;

ui-manchette/src/stories/Manchette.stories.ts

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const meta: Meta<typeof Manchette> = {
2323
type: 'object',
2424
},
2525
},
26+
selectedProjection: {
27+
options: [undefined, ...SAMPLE_PATHS_DATA.map((path) => path.id)],
28+
control: {
29+
type: 'select',
30+
},
31+
},
2632
},
2733
};
2834

@@ -33,5 +39,6 @@ export const Default: Story = {
3339
args: {
3440
operationalPoints: OperationalPointListData,
3541
projectPathTrainResult: PathData,
42+
selectedProjection: 3,
3643
},
3744
};

ui-manchette/src/stories/assets/sampleData.ts

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ export const SAMPLE_PATH_PROPERTIES_DATA: PathProperties = {
186186

187187
export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [
188188
{
189+
id: 1,
190+
name: 'Train 1',
189191
departure_time: '2024-06-26T13:57:56Z',
190192
rolling_stock_length: 26070,
191193
space_time_curves: [
@@ -623,6 +625,8 @@ export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [
623625
],
624626
},
625627
{
628+
id: 2,
629+
name: 'Train 2',
626630
departure_time: '2024-06-26T13:42:56Z',
627631
rolling_stock_length: 26070,
628632
space_time_curves: [
@@ -1060,6 +1064,8 @@ export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [
10601064
],
10611065
},
10621066
{
1067+
id: 3,
1068+
name: 'Train 3',
10631069
departure_time: '2024-06-26T14:12:56Z',
10641070
rolling_stock_length: 26070,
10651071
space_time_curves: [

ui-manchette/src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ export type StyledOperationalPointType = OperationalPointType & {
8989
};
9090

9191
export type ProjectPathTrainResult = {
92+
/*Name of train */
93+
name: string;
94+
/*Id of train */
95+
id: number;
9296
/** List of signal updates along the path */
9397
signal_updates: {
9498
/** The labels of the new aspect */

0 commit comments

Comments
 (0)