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

ui-manchette: highlight selected train #293

Merged
merged 1 commit into from
Aug 1, 2024
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
9 changes: 7 additions & 2 deletions ui-manchette/src/components/Manchette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useIsOverflow } from '../hooks/useIsOverFlow';
type ManchetteProps = {
operationalPoints: OperationalPointType[];
projectPathTrainResult: ProjectPathTrainResult[];
selectedProjection?: number;
};
import usePaths from '../hooks/usePaths';
import type {
Expand All @@ -32,7 +33,11 @@ import type {
} from '../types';
import { getDiff } from '../utils/vector';

const Manchette: FC<ManchetteProps> = ({ operationalPoints, projectPathTrainResult }) => {
const Manchette: FC<ManchetteProps> = ({
operationalPoints,
projectPathTrainResult,
selectedProjection,
}) => {
const manchette = useRef<HTMLDivElement>(null);

const [state, setState] = useState<{
Expand Down Expand Up @@ -74,7 +79,7 @@ const Manchette: FC<ManchetteProps> = ({ operationalPoints, projectPathTrainResu
scales,
} = state;

const paths = usePaths(projectPathTrainResult);
const paths = usePaths(projectPathTrainResult, selectedProjection);

const zoomYIn = useCallback(() => {
if (yZoom < MAX_ZOOM_Y) setState((prev) => ({ ...prev, yZoom: yZoom + ZOOM_Y_DELTA }));
Expand Down
12 changes: 6 additions & 6 deletions ui-manchette/src/hooks/usePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ const transformCurve = (curve: SpaceTimeCurves, departureTime: string) =>
position,
}));

const usePaths = (projectPathTrainResult: ProjectPathTrainResult[]) =>
const usePaths = (projectPathTrainResult: ProjectPathTrainResult[], selectedProjection?: number) =>
useMemo(
() =>
projectPathTrainResult.map((path, index) => ({
id: path.departure_time,
label: `Train ${index + 1}`,
color: '#000000',
projectPathTrainResult.map((path) => ({
id: `${path.id}`,
label: path.name,
color: selectedProjection && selectedProjection === path.id ? '#201EDE' : '#000000',
points: path.space_time_curves.flatMap((curve) =>
transformCurve(curve, path.departure_time)
),
})),
[projectPathTrainResult]
[projectPathTrainResult, selectedProjection]
);

export default usePaths;
7 changes: 7 additions & 0 deletions ui-manchette/src/stories/Manchette.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const meta: Meta<typeof Manchette> = {
type: 'object',
},
},
selectedProjection: {
options: [undefined, ...SAMPLE_PATHS_DATA.map((path) => path.id)],
control: {
type: 'select',
},
},
},
};

Expand All @@ -33,5 +39,6 @@ export const Default: Story = {
args: {
operationalPoints: OperationalPointListData,
projectPathTrainResult: PathData,
selectedProjection: 3,
},
};
6 changes: 6 additions & 0 deletions ui-manchette/src/stories/assets/sampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export const SAMPLE_PATH_PROPERTIES_DATA: PathProperties = {

export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [
{
id: 1,
name: 'Train 1',
departure_time: '2024-06-26T13:57:56Z',
rolling_stock_length: 26070,
space_time_curves: [
Expand Down Expand Up @@ -623,6 +625,8 @@ export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [
],
},
{
id: 2,
name: 'Train 2',
departure_time: '2024-06-26T13:42:56Z',
rolling_stock_length: 26070,
space_time_curves: [
Expand Down Expand Up @@ -1060,6 +1064,8 @@ export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [
],
},
{
id: 3,
name: 'Train 3',
departure_time: '2024-06-26T14:12:56Z',
rolling_stock_length: 26070,
space_time_curves: [
Expand Down
4 changes: 4 additions & 0 deletions ui-manchette/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export type StyledOperationalPointType = OperationalPointType & {
};

export type ProjectPathTrainResult = {
/*Name of train */
name: string;
/*Id of train */
id: number;
/** List of signal updates along the path */
signal_updates: {
/** The labels of the new aspect */
Expand Down
Loading