-
Notifications
You must be signed in to change notification settings - Fork 83
ui-charts: display a GOV in a GET in Storybook #11636
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9ee9fdc
ui-charts: improves splitting manchette and STC
jacomyal 9b98f31
ui-charts: makes space-time chart more resilient
jacomyal 5fd4fee
ui-charts: makes manchette more resilient
jacomyal 1cc625c
ui-charts: adds new TrackOccupancyStandalone
jacomyal 936a85d
ui-charts: fixes some manchette stories
jacomyal 659480c
ui-charts: normalizes millimeters in stories
jacomyal 4e200e4
ui-charts: drafts TOD within STC story
jacomyal 9cf660b
ui-charts: restores clicking trains in the TOD
jacomyal bc04fc7
ui-charts: adds top and bottom borders to TOD
jacomyal 9312e39
ui-charts: integrates various minor changes
jacomyal 933a456
ui-charts: draws times in TrackOccupancyStandalone
jacomyal cb41c5b
ui-charts: fixes shift+wheel on SpaceTimeChart
jacomyal 5a9e83e
ui-charts: integrates various minor changes
jacomyal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...t/ui/storybook/stories/ui-charts/manchetteWithSpaceTimeChart/assets/trackOccupancyData.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export const TRACKS = [ | ||
| { id: '1', name: 'EV', line: '123456' }, | ||
| { id: '2', name: '2', line: '456123' }, | ||
| { id: '3', name: '2bis', line: '135246' }, | ||
| { id: '4', name: 'Z', line: '654321' }, | ||
| { id: '5', name: '1bis', line: '615243' }, | ||
| { id: '6', name: '1', line: '523416' }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
front/ui/storybook/stories/ui-charts/manchetteWithSpaceTimeChart/track-occupancy.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import React, { useMemo, useRef, useState } from 'react'; | ||
|
|
||
| import { | ||
| Manchette, | ||
| PathLayer, | ||
| SpaceTimeChart, | ||
| TrackOccupancyCanvas, | ||
| TrackOccupancyManchette, | ||
| useManchetteWithSpaceTimeChart, | ||
| WaypointComponent, | ||
| TRACK_HEIGHT_CONTAINER, | ||
| type OccupancyZone, | ||
| type Track, | ||
| isInteractiveWaypoint, | ||
| type OccupancyZonePickingElement, | ||
| isPointPickingElement, | ||
| isSegmentPickingElement, | ||
| } from '@osrd-project/ui-charts'; | ||
| import '@osrd-project/ui-charts/dist/theme.css'; | ||
| import '@osrd-project/ui-core/dist/theme.css'; | ||
| import type { Meta } from '@storybook/react'; | ||
|
|
||
| import { | ||
| getOccupancyZonesFromPathAtGivenWaypoint, | ||
| OPERATIONAL_POINTS, | ||
| PATHS, | ||
| } from '../spaceTimeChart/helpers/paths'; | ||
|
|
||
| const BASE_WAYPOINT_HEIGHT = 32; | ||
|
|
||
| /** | ||
| * This story shows how to render a Manchette with a SpaceTimeChart, and showing a | ||
| * TrackOccupancyDiagram layer when selecting an operational point. | ||
| */ | ||
|
|
||
| /** | ||
| * This component shows how to use the useManchetteWithSpaceTimeChart hook with track-occupancy | ||
| * diagrams: | ||
| */ | ||
| const TrackOccupancyDiagramWithinSpaceTimeChartWrapper = ({ height = 561 }: { height: number }) => { | ||
| // TODO: Restore trains selection from GOV | ||
| const [selectedTrain, setSelectedTrain] = useState<string>(); | ||
| const [selectedWaypoint, setSelectedWaypoint] = useState<undefined | string>( | ||
| OPERATIONAL_POINTS[2].id | ||
| ); | ||
| const manchetteWithSpaceTimeChartRef = useRef<HTMLDivElement>(null); | ||
| const spaceTimeChartRef = useRef<HTMLDivElement>(null); | ||
| const operationalPoints = OPERATIONAL_POINTS; | ||
| const paths = PATHS; | ||
|
|
||
| const splitPoints = useMemo(() => { | ||
| const operationalPoint = operationalPoints.find((wp) => wp.id === selectedWaypoint); | ||
| if (!operationalPoint) return []; | ||
|
|
||
| // Fake tracks: | ||
| const tracks: Track[] = [ | ||
| { id: '1', name: 'EV', line: 'line' }, | ||
| { id: '2', name: '2', line: 'line' }, | ||
| { id: '3', name: '2bis', line: 'line' }, | ||
| ]; | ||
| const occupancyZones: OccupancyZone[] = paths.flatMap((path, i) => | ||
| getOccupancyZonesFromPathAtGivenWaypoint(path.points, operationalPoint.position, { | ||
| trainId: path.id, | ||
| trackId: tracks[i % tracks.length].id, // (i.e. pick some random track) | ||
| arrivalTrainName: 'foo', | ||
| departureTrainName: 'bar', | ||
| color: path.color, | ||
| }) | ||
| ); | ||
|
|
||
| return [ | ||
| { | ||
| id: operationalPoint.id, | ||
| position: operationalPoint.position, | ||
| size: tracks.length * TRACK_HEIGHT_CONTAINER + BASE_WAYPOINT_HEIGHT, | ||
| spaceTimeChartNode: ( | ||
| <TrackOccupancyCanvas | ||
| position={operationalPoint.position} | ||
| tracks={tracks} | ||
| occupancyZones={occupancyZones} | ||
| selectedTrainId={selectedTrain} | ||
| onClose={() => setSelectedWaypoint(undefined)} | ||
| topPadding={BASE_WAYPOINT_HEIGHT} | ||
| /> | ||
| ), | ||
| manchetteNode: ( | ||
| <TrackOccupancyManchette tracks={tracks}> | ||
| <div className="waypoint-wrapper flex justify-start"> | ||
| <WaypointComponent | ||
| waypoint={{ | ||
| id: operationalPoint.id, | ||
| name: operationalPoint.label, | ||
| position: operationalPoint.position, | ||
| onClick: () => setSelectedWaypoint(undefined), | ||
| }} | ||
| isActive={false} | ||
| isMenuActive={false} | ||
| /> | ||
| </div> | ||
| </TrackOccupancyManchette> | ||
| ), | ||
| }, | ||
| ]; | ||
| }, [paths, selectedTrain, selectedWaypoint, operationalPoints]); | ||
|
|
||
| const { manchetteProps, spaceTimeChartProps, handleScroll } = useManchetteWithSpaceTimeChart({ | ||
| waypoints: operationalPoints.map((op) => ({ | ||
| id: op.id, | ||
| position: op.position, | ||
| name: op.label, | ||
| weight: op.importanceLevel, | ||
| })), | ||
| manchetteWithSpaceTimeChartRef, | ||
| height, | ||
| spaceTimeChartRef, | ||
| splitPoints, | ||
| defaultTimeOrigin: Math.min(...paths.map((p) => +p.points[0].time)), | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="manchette-space-time-chart-wrapper"> | ||
| <div | ||
| ref={manchetteWithSpaceTimeChartRef} | ||
| className="manchette flex" | ||
| style={{ height: `${height}px` }} | ||
| onScroll={handleScroll} | ||
| > | ||
| <Manchette | ||
| {...manchetteProps} | ||
| contents={manchetteProps.contents.map((content) => | ||
| isInteractiveWaypoint(content) | ||
| ? { ...content, onClick: (waypointId) => setSelectedWaypoint(waypointId) } | ||
| : content | ||
| )} | ||
| /> | ||
| <div className="space-time-chart-container w-full sticky" ref={spaceTimeChartRef}> | ||
| <SpaceTimeChart | ||
| className="inset-0 absolute h-full" | ||
| {...spaceTimeChartProps} | ||
| onClick={({ hoveredItem }) => { | ||
| // Handle clicking the occupancyZone items (on the TrackOccupancyCanvas layer): | ||
| if ( | ||
| hoveredItem?.layer === 'overlay' && | ||
| hoveredItem.element.type === 'occupancyZone' | ||
| ) { | ||
| const newId = (hoveredItem.element as OccupancyZonePickingElement).trainId; | ||
| setSelectedTrain(newId === selectedTrain ? undefined : newId); | ||
| } | ||
|
|
||
| // Handle clicking the path items (on the Path layers): | ||
| else if ( | ||
| hoveredItem?.layer === 'paths' && | ||
| (isPointPickingElement(hoveredItem.element) || | ||
| isSegmentPickingElement(hoveredItem.element)) | ||
| ) { | ||
| const newId = hoveredItem.element.pathId; | ||
| setSelectedTrain(newId === selectedTrain ? undefined : newId); | ||
| } | ||
| // Handle clicking the stage: | ||
| else { | ||
| setSelectedTrain(undefined); | ||
| } | ||
| }} | ||
| > | ||
| {paths.map((path) => ( | ||
| <PathLayer | ||
| key={path.id} | ||
| path={path} | ||
| color={path.color} | ||
| level={selectedTrain === path.id ? 1 : 2} | ||
| /> | ||
| ))} | ||
| </SpaceTimeChart> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const meta: Meta<typeof TrackOccupancyDiagramWithinSpaceTimeChartWrapper> = { | ||
| title: 'Manchette with SpaceTimeChart/Track-occupancy display', | ||
| component: TrackOccupancyDiagramWithinSpaceTimeChartWrapper, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| export const Default = { | ||
| args: {}, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.