@osrd-project/ui-charts 0.0.70 → 0.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
1
  import React from 'react';
2
2
  import { type ManchetteProps } from './Manchette';
3
3
  import { type SpaceTimeChartProps } from '../../spaceTimeChart';
4
+ import { type SplitPoint } from '../hooks/useManchetteWithSpaceTimeChart';
4
5
  import { type ProjectPathTrainResult, type Waypoint } from '../types';
5
6
  export type ManchetteWithSpaceTimeChartProps = {
6
7
  waypoints: Waypoint[];
7
8
  projectPathTrainResult: ProjectPathTrainResult[];
8
- selectedTrain?: number;
9
9
  height?: number;
10
10
  children?: React.ReactNode;
11
11
  header?: React.ReactNode;
12
12
  manchetteProps?: ManchetteProps;
13
13
  spaceTimeChartProps?: SpaceTimeChartProps;
14
+ splitPoints?: SplitPoint[];
14
15
  };
15
16
  /**
16
17
  * A simple component to display a manchette and a space time chart.
@@ -18,5 +19,5 @@ export type ManchetteWithSpaceTimeChartProps = {
18
19
  * This only covers basic usage. For more advanced control over the manchette
19
20
  * and space time chart, the useManchetteWithSpaceTimeChart() hook can be used.
20
21
  */
21
- declare const ManchetteWithSpaceTimeChart: ({ waypoints, projectPathTrainResult, selectedTrain, height, children, header, manchetteProps: additionalManchetteProps, spaceTimeChartProps: additionalSpaceTimeChartProps, }: ManchetteWithSpaceTimeChartProps) => React.JSX.Element;
22
+ declare const ManchetteWithSpaceTimeChart: ({ waypoints, projectPathTrainResult, height, children, header, manchetteProps: additionalManchetteProps, spaceTimeChartProps: additionalSpaceTimeChartProps, splitPoints, }: ManchetteWithSpaceTimeChartProps) => React.JSX.Element;
22
23
  export default ManchetteWithSpaceTimeChart;
@@ -1,84 +1,72 @@
1
- import type { SpaceTimeChartProps } from '../../spaceTimeChart';
2
- import type { ProjectPathTrainResult, Waypoint } from '../types';
3
- declare const useManchetteWithSpaceTimeChart: ({ waypoints, projectPathTrainResult, manchetteWithSpaceTimeChartRef, selectedTrain, height, spaceTimeChartRef, defaultTimeOrigin, defaultSpaceOrigin, }: {
1
+ import React, { type ReactNode } from 'react';
2
+ import { type SpaceScale, type SpaceTimeChartProps } from '../../spaceTimeChart';
3
+ import type { ManchetteProps } from '../components/Manchette';
4
+ import type { Waypoint } from '../types';
5
+ type State = {
6
+ xZoom: number;
7
+ yZoom: number;
8
+ timeOrigin: number;
9
+ spaceOrigin: number;
10
+ /** current x PIXEL offset from x origin */
11
+ xOffset: number;
12
+ /** current y PIXEL offset from y origin (the current y-scroll of the view. always updates) */
13
+ yOffset: number;
14
+ /** only update after a zoom. used to update back the view scroll value */
15
+ scrollTo: number | null;
16
+ panning: {
17
+ initialOffset: {
18
+ x: number;
19
+ y: number;
20
+ };
21
+ } | null;
22
+ zoomMode: boolean;
23
+ rect: {
24
+ timeStart: Date;
25
+ timeEnd: Date;
26
+ spaceStart: number;
27
+ spaceEnd: number;
28
+ } | null;
29
+ pixelRect: {
30
+ xStart: number;
31
+ xEnd: number;
32
+ yStart: number;
33
+ yEnd: number;
34
+ } | null;
35
+ isProportional: boolean;
36
+ waypointsChart: Waypoint[];
37
+ scales: SpaceScale[];
38
+ };
39
+ export type SplitPoint = {
40
+ /** helper identify nodes for this split point in the React tree */
41
+ id: string;
42
+ /** position of this split point, in mm from start */
43
+ position: number;
44
+ /** size of this split point, in pixels on screen */
45
+ size: number;
46
+ /** a React node to render the split point, space/time chart side */
47
+ spaceTimeChartNode?: ReactNode;
48
+ /** a React node to render the split point, manchette side */
49
+ manchetteNode?: ReactNode;
50
+ };
51
+ declare const useManchetteWithSpaceTimeChart: ({ waypoints, manchetteWithSpaceTimeChartRef, height, spaceTimeChartRef, defaultTimeOrigin, defaultSpaceOrigin, splitPoints, }: {
4
52
  waypoints: Waypoint[];
5
- projectPathTrainResult: ProjectPathTrainResult[];
6
53
  manchetteWithSpaceTimeChartRef: React.RefObject<HTMLDivElement>;
7
- selectedTrain?: number;
8
54
  height?: number;
9
55
  spaceTimeChartRef?: React.RefObject<HTMLDivElement>;
10
56
  defaultTimeOrigin?: number;
11
57
  defaultSpaceOrigin?: number;
58
+ splitPoints?: SplitPoint[];
12
59
  }) => {
13
- manchetteProps: {
14
- contents: import("../types").InteractiveWaypoint[];
15
- zoomYIn: () => void;
16
- zoomYOut: () => void;
17
- resetZoom: () => void;
18
- toggleMode: () => void;
19
- yZoom: number;
20
- isProportional: boolean;
21
- yOffset: number;
22
- };
23
- spaceTimeChartProps: {
24
- operationalPoints: {
25
- id: string;
26
- label: string;
27
- position: number;
28
- importanceLevel: number;
29
- }[];
30
- spaceScales: {
31
- from: number;
32
- to: number;
33
- size: number;
34
- }[] | ({
35
- coefficient: number;
36
- size?: undefined;
37
- from: number;
38
- to: number;
39
- } | {
40
- size: number;
41
- coefficient?: undefined;
42
- from: number;
43
- to: number;
44
- })[];
45
- timeScale: number;
46
- paths: {
47
- id: string;
48
- label: string;
49
- color: string;
50
- level: import("../../spaceTimeChart").PathLevel;
51
- points: {
52
- time: number;
53
- position: number;
54
- }[];
55
- }[];
56
- xOffset: number;
57
- yOffset: number;
58
- timeOrigin: number;
59
- spaceOrigin: number;
60
- rect: {
61
- timeStart: Date;
62
- timeEnd: Date;
63
- spaceStart: number;
64
- spaceEnd: number;
65
- } | null;
66
- onZoom: ({ delta, position }: Parameters<NonNullable<SpaceTimeChartProps["onZoom"]>>[0]) => void;
67
- onPan: (payload: Parameters<NonNullable<SpaceTimeChartProps["onPan"]>>[0]) => void;
68
- };
60
+ manchetteProps: ManchetteProps;
61
+ spaceTimeChartProps: SpaceTimeChartProps;
69
62
  handleScroll: () => void;
70
63
  handleXZoom: (newXZoom: number, xPosition?: number) => void;
71
64
  xZoom: number;
72
65
  toggleZoomMode: () => void;
73
66
  zoomMode: boolean;
74
- rect: {
75
- timeStart: Date;
76
- timeEnd: Date;
77
- spaceStart: number;
78
- spaceEnd: number;
79
- } | null;
67
+ rect: State["rect"];
80
68
  timeScale: number;
81
69
  spaceScale: number;
82
- setTimeOrigin: (newTimeOrigin: number) => void;
70
+ setTimeOrigin: (v: number) => void;
83
71
  };
84
72
  export default useManchetteWithSpaceTimeChart;
@@ -1,13 +1,11 @@
1
- import { type PathLevel } from '../../spaceTimeChart';
2
1
  import { type ProjectPathTrainResult } from '../types';
3
- declare const usePaths: (projectPathTrainResult: ProjectPathTrainResult[], selectedTrain?: number) => {
2
+ declare const usePaths: (projectPathTrainResult: ProjectPathTrainResult[]) => {
4
3
  id: string;
5
4
  label: string;
6
- color: string;
7
- level: PathLevel;
8
5
  points: {
9
6
  time: number;
10
7
  position: number;
11
8
  }[];
9
+ color: string;
12
10
  }[];
13
11
  export default usePaths;
@@ -2,8 +2,10 @@ import '@osrd-project/ui-core/dist/theme.css';
2
2
  import './styles/main.css';
3
3
  import './consts';
4
4
  export { default as Manchette, type ManchetteProps } from './components/Manchette';
5
- export { default as ManchetteWithSpaceTimeChart } from './components/ManchetteWithSpaceTimeChart';
5
+ export { default as ManchetteWithSpaceTimeChart, type ManchetteWithSpaceTimeChartProps, } from './components/ManchetteWithSpaceTimeChart';
6
6
  export { DEFAULT_ZOOM_MS_PER_PX } from './consts';
7
7
  export { default as useManchetteWithSpaceTimeChart } from './hooks/useManchetteWithSpaceTimeChart';
8
+ export { default as usePaths } from './hooks/usePaths';
8
9
  export type { WaypointMenuData, Waypoint, ProjectPathTrainResult, InteractiveWaypoint, } from './types';
9
- export { timeScaleToZoomValue } from './utils/helpers';
10
+ export { positionMmToKm } from './utils';
11
+ export { timeScaleToZoomValue, isInteractiveWaypoint } from './utils/helpers';
@@ -16,7 +16,7 @@ export type WaypointMenuData = {
16
16
  manchetteWrapperRef: React.RefObject<HTMLDivElement>;
17
17
  };
18
18
  export type ProjectPathTrainResult = {
19
- id: number;
19
+ id: string;
20
20
  name: string;
21
21
  spaceTimeCurves: {
22
22
  positions: number[];
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from 'react';
1
2
  import type { InteractiveWaypoint, Waypoint } from '../types';
2
3
  export declare const zoomValueToTimeScale: (slider: number) => number;
3
4
  export declare const timeScaleToZoomValue: (timeScale: number) => number;
@@ -22,7 +23,7 @@ type WaypointsOptions = {
22
23
  height: number;
23
24
  };
24
25
  export declare const filterVisibleElements: (elements: Waypoint[], totalDistance: number, heightWithoutFinalWaypoint: number, minSpace: number) => Waypoint[];
25
- export declare const computeWaypointsToDisplay: (waypoints: Waypoint[], { height, isProportional, yZoom }: WaypointsOptions, minZoomMillimeterPerPx: number, maxZoomMillimeterPerPx: number) => InteractiveWaypoint[];
26
+ export declare const selectWaypointsToDisplay: (waypoints: Waypoint[], { height, isProportional, yZoom }: WaypointsOptions) => Waypoint[];
26
27
  /**
27
28
  * 2 modes for space scales
28
29
  * km (isProportional): { coefficient: gives a scale in meter/pixel }
@@ -43,4 +44,5 @@ export declare const getScales: (waypoints: Waypoint[], { isProportional, yZoom
43
44
  from: number;
44
45
  to: number;
45
46
  })[];
47
+ export declare const isInteractiveWaypoint: (item: InteractiveWaypoint | ReactNode) => item is InteractiveWaypoint;
46
48
  export {};
@@ -4,6 +4,7 @@ export type OccupancyBlock = {
4
4
  spaceStart: number;
5
5
  spaceEnd: number;
6
6
  color: string;
7
+ blinking?: boolean;
7
8
  };
8
9
  export type OccupancyBlockLayerProps = {
9
10
  occupancyBlocks: OccupancyBlock[];
@@ -1,3 +1 @@
1
- export declare const CAPTION_SIZE = 33;
2
- declare const TimeCaptions: () => null;
3
- export default TimeCaptions;
1
+ export declare const TimeCaptions: () => null;
@@ -1,3 +1,20 @@
1
1
  import { type SpaceTimeChartTheme } from './types';
2
+ export declare const BLACK = "#000000";
3
+ export declare const BLUE = "#2170B9";
4
+ export declare const GREY_10 = "#EDEDED";
5
+ export declare const GREY_30 = "#B6B3AF";
6
+ export declare const GREY_50 = "#797671";
7
+ export declare const WHITE = "#FFFFFF";
8
+ export declare const WHITE_75 = "#FFFFFFC0";
9
+ export declare const AMBIANT_A10 = "#EFF3F5";
10
+ export declare const ERROR_30 = "#FF6868";
11
+ export declare const ERROR_60 = "#D91C1C";
12
+ export declare const OCCUPANCY_FREE = "#CAEDDB";
13
+ export declare const OCCUPANCY_SEMAPHORE = "#FFD4D8";
14
+ export declare const OCCUPANCY_WARNING = "#FFEABF";
15
+ export declare const FONT_SIZE = 10;
16
+ export declare const FONT = "IBM Plex Sans, sans-serif";
17
+ export declare const SECOND = 1000;
2
18
  export declare const MINUTE: number;
19
+ export declare const HOUR: number;
3
20
  export declare const DEFAULT_THEME: SpaceTimeChartTheme;
@@ -49,8 +49,8 @@ export type PathData = {
49
49
  };
50
50
  export type OperationalPoint = {
51
51
  id: string;
52
- label: string;
53
52
  position: number;
53
+ label?: string;
54
54
  importanceLevel?: number;
55
55
  };
56
56
  export type Axis = 'x' | 'y';
@@ -106,6 +106,14 @@ export type LineStyle = {
106
106
  opacity?: number;
107
107
  dashArray?: number[];
108
108
  };
109
+ export type CaptionStyle = {
110
+ color: string;
111
+ font: string;
112
+ fontWeight?: string;
113
+ fontSize?: string;
114
+ topOffset?: number;
115
+ textAlign?: CanvasTextAlign;
116
+ };
109
117
  export type SpaceTimeChartTheme = {
110
118
  background: string;
111
119
  breakpoints: number[];
@@ -116,18 +124,16 @@ export type SpaceTimeChartTheme = {
116
124
  };
117
125
  spaceGraduationsStyles: Record<number, LineStyle>;
118
126
  timeCaptionsPriorities: number[][];
119
- timeCaptionsStyles: Record<number, {
120
- color: string;
121
- font: string;
122
- fontWeight?: string;
123
- fontSize?: string;
124
- topOffset?: number;
125
- }>;
127
+ timeCaptionsStyles: Record<number, CaptionStyle>;
128
+ timeCaptionsSize: number;
126
129
  timeGraduationsPriorities: number[][];
127
130
  timeGraduationsStyles: Record<number, LineStyle>;
131
+ dateCaptionsStyle: CaptionStyle;
132
+ dateCaptionsSize: number;
128
133
  };
129
134
  export type SpaceTimeChartProps = {
130
- children?: ReactNode[];
135
+ children?: ReactNode | ReactNode[];
136
+ additionalChildren?: ReactNode | ReactNode[];
131
137
  operationalPoints: OperationalPoint[];
132
138
  spaceOrigin: number;
133
139
  spaceScales: SpaceScale[];
@@ -139,6 +145,7 @@ export type SpaceTimeChartProps = {
139
145
  enableSnapping?: boolean;
140
146
  hideGrid?: boolean;
141
147
  hidePathsLabels?: boolean;
148
+ hideDates?: boolean;
142
149
  showTicks?: boolean;
143
150
  theme?: Partial<SpaceTimeChartTheme>;
144
151
  onPan?: Handler<{
@@ -202,8 +209,10 @@ export type SpaceTimeChartContextType = {
202
209
  tracks?: Track[];
203
210
  occupancyZones?: OccupancyZone[];
204
211
  theme: SpaceTimeChartTheme;
212
+ captionSize: number;
205
213
  enableSnapping: boolean;
206
214
  hideGrid: boolean;
207
215
  hidePathsLabels: boolean;
216
+ hideDates: boolean;
208
217
  showTicks: boolean;
209
218
  };
@@ -26,17 +26,19 @@ export declare function drawPathOutExtremity(ctx: CanvasRenderingContext2D, time
26
26
  */
27
27
  export declare function drawPathExtremity(ctx: CanvasRenderingContext2D, timePixel: number, spacePixel: number, swapAxis: boolean, extremityType: 'from' | 'to', pathDirection: Direction, pathEnd: PathEnd): void;
28
28
  /**
29
- *
30
29
  * @param minT number timestamp
31
30
  * @param maxT number timestamp
32
31
  * @param timeRanges time frames (24h, 12h, 6h, …)
33
32
  * @param gridlinesLevels width of the lines for each time frame
34
33
  * @param formatter function to format de values inside the output object
35
- * @returns Record<number, number>
36
34
  * Keys are times in ms
37
35
  * Values are the highest level on each time
38
36
  */
39
- export declare function computeVisibleTimeMarkers<T>(minT: number, maxT: number, timeRanges: number[], gridlinesLevels: number[], formatter?: (level: number, i: number) => T): Record<number, T>;
37
+ export declare function computeVisibleTimeMarkers<T extends object = {
38
+ level: number;
39
+ }>(minT: number, maxT: number, timeRanges: number[], gridlinesLevels: number[], formatter?: (level: number, i: number) => T): (T & {
40
+ time: number;
41
+ })[];
40
42
  /**
41
43
  * To get crisp horizontal or vertical lines on a canvas, we must draw them as thin as possible, in
42
44
  * terms of actual pixels on screen.
@@ -54,10 +56,11 @@ export type CanvasRect = {
54
56
  spaceStart: number;
55
57
  spaceEnd: number;
56
58
  };
57
- export declare function fillRect(ctx: CanvasRenderingContext2D, rect: CanvasRect, spaceTimeContext: SpaceTimeChartContextType): {
58
- areaTimeSize?: undefined;
59
- areaSpaceSize?: undefined;
60
- } | {
61
- areaTimeSize: number;
62
- areaSpaceSize: number;
59
+ /**
60
+ * You most likely need to wrap this function call with ctx.save ctx.restore
61
+ * as it modifies ctx current transformation matrix
62
+ */
63
+ export declare function fillRect(ctx: CanvasRenderingContext2D, { timeStart, timeEnd, spaceStart, spaceEnd }: CanvasRect, { getPoint }: SpaceTimeChartContextType): {
64
+ width: number;
65
+ height: number;
63
66
  };
@@ -29,7 +29,7 @@ export declare function getNormalizedScaleAtPixel(y: number, tree: NormalizedSca
29
29
  export declare function getTimeToPixel(timeOrigin: number, pixelOffset: number, timeScale: number): TimeToPixel;
30
30
  export declare function getPixelToTime(timeOrigin: number, pixelOffset: number, timeScale: number): PixelToTime;
31
31
  export declare function getSpaceToPixel(pixelOffset: number, binaryTree: NormalizedScaleTree): SpaceToPixel;
32
- export declare function getPixelToSpace(spaceOrigin: number, pixelOffset: number, binaryTree: NormalizedScaleTree): PixelToSpace;
32
+ export declare function getPixelToSpace(pixelOffset: number, binaryTree: NormalizedScaleTree): PixelToSpace;
33
33
  export declare function getPointToData(getTime: PixelToTime, getSpace: PixelToSpace, timeAxis: Axis, spaceAxis: Axis): PointToData;
34
34
  export declare function getDataToPoint(getTimePixel: TimeToPixel, getSpacePixel: SpaceToPixel, timeAxis: Axis, spaceAxis: Axis): DataToPoint;
35
35
  /**
package/dist/theme.css CHANGED
@@ -3102,7 +3102,7 @@ video {
3102
3102
  }
3103
3103
 
3104
3104
  .modal-ui-overlay {
3105
- position: fixed;
3105
+ position: absolute;
3106
3106
  top: 0;
3107
3107
  left: 0;
3108
3108
  right: 0;
@@ -4689,6 +4689,18 @@ video {
4689
4689
  font-size: 0.875rem;
4690
4690
  line-height: 14px;
4691
4691
  }
4692
+ .manchette-container .waypoints-list {
4693
+ width: 349px;
4694
+ border-bottom-left-radius: 0.25rem;
4695
+ padding-left: 0.5rem;
4696
+ padding-right: 1.625rem;
4697
+ --tw-bg-opacity: 1;
4698
+ background-color: rgba(255, 255, 255, 1);
4699
+ background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
4700
+ }
4701
+ .manchette-container .waypoints-list .waypoint-wrapper:last-child .waypoint::after {
4702
+ bottom: 16px;
4703
+ }
4692
4704
  .manchette-space-time-chart-wrapper {
4693
4705
  border-radius: 10px;
4694
4706
  box-shadow:
@@ -4707,9 +4719,10 @@ video {
4707
4719
  overflow-y: clip;
4708
4720
  }
4709
4721
  .manchette-space-time-chart-wrapper .space-time-chart-container {
4710
- height: 561px;
4711
- width: 100%;
4722
+ top: 0;
4723
+ right: 0;
4712
4724
  bottom: 0;
4725
+ left: 0;
4713
4726
  }
4714
4727
  .waypoint {
4715
4728
  --tw-text-opacity: 1;
@@ -4818,18 +4831,6 @@ video {
4818
4831
  background-color: rgba(148, 145, 142, 1);
4819
4832
  background-color: rgba(148, 145, 142, var(--tw-bg-opacity, 1));
4820
4833
  }
4821
- .waypoint-list {
4822
- width: 349px;
4823
- border-bottom-left-radius: 0.25rem;
4824
- padding-left: 0.5rem;
4825
- padding-right: 1.625rem;
4826
- --tw-bg-opacity: 1;
4827
- background-color: rgba(255, 255, 255, 1);
4828
- background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
4829
- }
4830
- .waypoint-list .waypoint-wrapper:last-child .waypoint::after {
4831
- bottom: 16px;
4832
- }
4833
4834
  .menu {
4834
4835
  --tw-bg-opacity: 1;
4835
4836
  background-color: rgba(245, 245, 245, 1);