@osrd-project/ui-charts 0.0.80 → 0.0.82

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.
Files changed (70) hide show
  1. package/dist/chronogram/components/Chronogram.d.ts +3 -0
  2. package/dist/chronogram/index.d.ts +4 -0
  3. package/dist/chronogram/lib/context.d.ts +6 -0
  4. package/dist/chronogram/lib/types.d.ts +21 -0
  5. package/dist/common/consts.d.ts +5 -0
  6. package/dist/common/context.d.ts +2 -0
  7. package/dist/{spaceTimeChart/utils → common/helpers}/colors.d.ts +1 -1
  8. package/dist/common/helpers/time.d.ts +31 -0
  9. package/dist/common/helpers/utils.d.ts +8 -0
  10. package/dist/common/hooks/useCanvas.d.ts +16 -0
  11. package/dist/{spaceTimeChart → common}/hooks/useSize.d.ts +0 -1
  12. package/dist/common/index.d.ts +5 -0
  13. package/dist/common/types.d.ts +104 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.esm.js +1893 -1442
  16. package/dist/index.esm.js.map +1 -1
  17. package/dist/manchette/assets/sampleData.d.ts +2 -0
  18. package/dist/manchette/components/Manchette.d.ts +6 -1
  19. package/dist/manchette/components/ManchetteWithSpaceTimeChart.d.ts +3 -3
  20. package/dist/manchette/components/Waypoint.d.ts +2 -1
  21. package/dist/manchette/hooks/useManchetteWithSpaceTimeChart.d.ts +3 -36
  22. package/dist/manchette/hooks/useSyncManchette.d.ts +94 -0
  23. package/dist/manchette/index.d.ts +1 -2
  24. package/dist/manchette/types.d.ts +13 -0
  25. package/dist/spaceTimeChart/components/ConflictLayer.d.ts +1 -1
  26. package/dist/spaceTimeChart/components/ConflictTooltip.d.ts +1 -1
  27. package/dist/spaceTimeChart/components/PathLayer.d.ts +2 -1
  28. package/dist/spaceTimeChart/components/Quadrilateral.d.ts +2 -1
  29. package/dist/spaceTimeChart/components/Tooltip.d.ts +1 -1
  30. package/dist/spaceTimeChart/hooks/useMouseInteractions.d.ts +36 -3
  31. package/dist/spaceTimeChart/index.d.ts +2 -5
  32. package/dist/spaceTimeChart/lib/consts.d.ts +0 -3
  33. package/dist/spaceTimeChart/lib/context.d.ts +3 -6
  34. package/dist/spaceTimeChart/lib/types.d.ts +4 -91
  35. package/dist/spaceTimeChart/utils/canvas.d.ts +2 -37
  36. package/dist/spaceTimeChart/utils/events.d.ts +1 -1
  37. package/dist/spaceTimeChart/utils/geometry.d.ts +1 -1
  38. package/dist/spaceTimeChart/utils/scales.d.ts +2 -3
  39. package/dist/spaceTimeChart/utils/snapping.d.ts +1 -1
  40. package/dist/spaceTimeChart/utils/vectors.d.ts +1 -1
  41. package/dist/speedSpaceChart/components/SpeedSpaceChart.d.ts +21 -2
  42. package/dist/speedSpaceChart/components/common/DetailsBox.d.ts +5 -2
  43. package/dist/speedSpaceChart/components/common/SettingsPanel.d.ts +2 -1
  44. package/dist/speedSpaceChart/components/const.d.ts +22 -6
  45. package/dist/speedSpaceChart/components/helpers/drawElements/reticle.d.ts +2 -1
  46. package/dist/speedSpaceChart/components/layers/ReticleLayer.d.ts +3 -1
  47. package/dist/speedSpaceChart/components/utils.d.ts +7 -3
  48. package/dist/speedSpaceChart/index.d.ts +2 -1
  49. package/dist/speedSpaceChart/types.d.ts +40 -0
  50. package/dist/theme.css +410 -195
  51. package/dist/theme.css.map +1 -1
  52. package/dist/trackOccupancyDiagram/components/TrackOccupancyCanvas.d.ts +1 -1
  53. package/dist/trackOccupancyDiagram/components/TrackOccupancyManchette.d.ts +1 -1
  54. package/dist/trackOccupancyDiagram/components/TrackOccupancyStandalone.d.ts +1 -1
  55. package/dist/trackOccupancyDiagram/components/helpers/drawElements/drawOccupancyZones.d.ts +8 -2
  56. package/dist/trackOccupancyDiagram/components/helpers/drawElements/drawOccupancyZonesTexts.d.ts +1 -1
  57. package/dist/trackOccupancyDiagram/components/helpers/drawElements/drawTracks.d.ts +1 -1
  58. package/dist/trackOccupancyDiagram/components/layers/OccupancyZonesLayer.d.ts +2 -2
  59. package/dist/trackOccupancyDiagram/components/layers/TracksLayer.d.ts +1 -1
  60. package/dist/trackOccupancyDiagram/components/utils.d.ts +1 -1
  61. package/dist/trackOccupancyDiagram/index.d.ts +2 -2
  62. package/dist/trackOccupancyDiagram/{components → lib}/types.d.ts +2 -1
  63. package/package.json +6 -6
  64. package/dist/manchette/hooks/usePaths.d.ts +0 -11
  65. package/dist/spaceTimeChart/hooks/useCanvas.d.ts +0 -19
  66. /package/dist/{spaceTimeChart/utils → common/helpers}/png.d.ts +0 -0
  67. /package/dist/{spaceTimeChart → common}/hooks/useDevicePixelRatio.d.ts +0 -0
  68. /package/dist/{spaceTimeChart/components → common/layers}/TimeCaptions.d.ts +0 -0
  69. /package/dist/{spaceTimeChart/components → common/layers}/TimeGraduations.d.ts +0 -0
  70. /package/dist/trackOccupancyDiagram/{components → lib}/consts.d.ts +0 -0
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { ChronogramProps } from '../lib/types';
3
+ export declare const Chronogram: (props: ChronogramProps) => React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import '../spaceTimeChart/styles/main.css';
2
+ export * from './components/Chronogram';
3
+ export type { ChronogramProps, ChronogramContextType } from './lib/types';
4
+ export { ChronogramContext } from './lib/context';
@@ -0,0 +1,6 @@
1
+ import { type ChronogramContextType } from './types';
2
+ /**
3
+ * This context exports everything necessary to draw the chart.
4
+ * It is updated anytime the scales are updated.
5
+ */
6
+ export declare const ChronogramContext: import("react").Context<ChronogramContextType>;
@@ -0,0 +1,21 @@
1
+ import { type HTMLProps } from 'react';
2
+ import type { TimeChartContextType } from '../../common/types';
3
+ import type { SpaceTimeChartTheme } from '../../spaceTimeChart';
4
+ export type OccupancyBlock = {
5
+ startTime: number;
6
+ endTime: number;
7
+ };
8
+ export type LevelCrossingOccupancies = OccupancyBlock[][];
9
+ export type ChronogramContextType = TimeChartContextType & {
10
+ levelCrossingsNames: string[];
11
+ levelCrossingsOccupancies: LevelCrossingOccupancies[];
12
+ };
13
+ export type ChronogramProps = {
14
+ levelCrossingsNames: string[];
15
+ levelCrossingsOccupancies: LevelCrossingOccupancies[];
16
+ timeOrigin: number;
17
+ timeScale: number;
18
+ xOffset?: number;
19
+ yOffset?: number;
20
+ theme?: Partial<SpaceTimeChartTheme>;
21
+ } & HTMLProps<HTMLDivElement>;
@@ -0,0 +1,5 @@
1
+ export declare const PICKING_LAYERS: readonly ["paths", "overlay"];
2
+ export declare const LAYERS: readonly ["background", "graduations", "paths", "overlay", "captions"];
3
+ export declare const SECOND = 1000;
4
+ export declare const MINUTE: number;
5
+ export declare const HOUR: number;
@@ -0,0 +1,2 @@
1
+ import type { CanvasContextType, TimeChartContextType } from './types';
2
+ export declare const TimeChartCanvasContext: import("react").Context<CanvasContextType<TimeChartContextType>>;
@@ -1,4 +1,4 @@
1
- import { type RGBAColor } from '../lib/types';
1
+ import type { RGBAColor } from '../types';
2
2
  export declare const WHITE_ALPHA_75 = "#ffffffbf";
3
3
  export declare const BLACK_ALPHA_25 = "#00000025";
4
4
  export declare const GREY_50 = "#797671";
@@ -0,0 +1,31 @@
1
+ import type { TimeToPixel, PixelToTime } from '../types';
2
+ /**
3
+ * @param minT number timestamp
4
+ * @param maxT number timestamp
5
+ * @param timeRanges time frames (24h, 12h, 6h, …)
6
+ * @param gridlinesLevels width of the lines for each time frame
7
+ * @param formatter function to format de values inside the output object
8
+ * Keys are times in ms
9
+ * Values are the highest level on each time
10
+ */
11
+ export declare function computeVisibleTimeMarkers<T extends object = {
12
+ level: number;
13
+ }>(minT: number, maxT: number, timeRanges: number[], gridlinesLevels: number[], formatter?: (level: number, i: number) => T): (T & {
14
+ time: number;
15
+ })[];
16
+ /**
17
+ * To get crisp horizontal or vertical lines on a canvas, we must draw them as thin as possible, in
18
+ * terms of actual pixels on screen.
19
+ * The best way for this is:
20
+ * - To center lines 1, 3, 5... pixels wide in the middle of a pixel (0.5, 1.5, 2.5...)
21
+ * - To center lines 2, 4, 6... pixels wide between two pixels (0, 1, 2, 3...)
22
+ * Also, for HiDPi screens:
23
+ * - To center lines of "integer thicknesses" between two screen pixels (0, 0.5, 1, 1.5, 2...)
24
+ * - To center lines with `n + 0.5` thicknesses in the middle of a screen pixel (0.25, 0.75, 1.25, 1.75...)
25
+ * @param rawCoordinate Any input coordinate to fix
26
+ * @param lineWidth The width of the line to draw
27
+ * @param devicePixelRatio
28
+ */
29
+ export declare function getCrispLineCoordinate(rawCoordinate: number, lineWidth: number, devicePixelRatio?: number): number;
30
+ export declare function getTimeToPixel(timeOrigin: number, pixelOffset: number, timeScale: number): TimeToPixel;
31
+ export declare function getPixelToTime(timeOrigin: number, pixelOffset: number, timeScale: number): PixelToTime;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This function returns the picking layers scaling ratio. We basically take the min of the screen
3
+ * pixels and the "HTML pixels", and divide it by two.
4
+ *
5
+ * This allows having a smaller picking stage to fill (so it's faster), while keeping a "good enough
6
+ * precision".
7
+ */
8
+ export declare function getPickingScalingRatio(): number;
@@ -0,0 +1,16 @@
1
+ import type { BaseChartContextType, CanvasContextType, DrawingFunction, HoveredItem, LayerType, PickingDrawingFunction, PickingLayerType, Point } from '../types';
2
+ /**
3
+ * This hook handles the internal canvas drawing logic of a chart component.
4
+ */
5
+ export declare function useCanvas<T extends BaseChartContextType>(dom: HTMLElement | null, chartContext: T, position?: Point): {
6
+ canvasContext: CanvasContextType<T>;
7
+ hoveredItem: HoveredItem | null;
8
+ };
9
+ /**
10
+ * This hook helps to bind a picking function to a layer in a Chart.
11
+ */
12
+ export declare function usePicking<T>(contextKey: React.Context<CanvasContextType<T>>, layer: PickingLayerType, fn: PickingDrawingFunction<T>): void;
13
+ /**
14
+ * This hook helps to bind a drawing function to a layer in a chart.
15
+ */
16
+ export declare function useDraw<T>(contextKey: React.Context<CanvasContextType<T>>, layer: LayerType, fn: DrawingFunction<T>): void;
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * This hook takes a DOM element reference as input, and returns always updated width and height.
3
- * It is an internal hook, and should only be used inside SpaceTimeChart.
4
3
  */
5
4
  export declare function useSize(dom?: HTMLElement | null): {
6
5
  width: number;
@@ -0,0 +1,5 @@
1
+ export * from './layers/TimeCaptions';
2
+ export { default as TimeGraduations } from './layers/TimeGraduations';
3
+ export { usePicking, useDraw } from './hooks/useCanvas';
4
+ export { getCrispLineCoordinate } from './helpers/time';
5
+ export type { HoveredItem, DrawingFunction, PickingDrawingFunction, PickingElement, Point, } from './types';
@@ -0,0 +1,104 @@
1
+ import { type HTMLProps } from 'react';
2
+ import { type SpaceTimeChartTheme } from '../spaceTimeChart';
3
+ import type { LAYERS, PICKING_LAYERS } from './consts';
4
+ import type { DataPoint, Handler, PointToData, DataToPoint } from '../spaceTimeChart/lib/types';
5
+ export type BaseChartContextType = {
6
+ fingerprint: string;
7
+ pickingElements: PickingElement[];
8
+ resetPickingElements: () => void;
9
+ registerPickingElement: (element: PickingElement) => number;
10
+ theme: {
11
+ background: string;
12
+ };
13
+ };
14
+ export type Point = {
15
+ x: number;
16
+ y: number;
17
+ };
18
+ export type RGBAColor = [number, number, number, number];
19
+ export type PickingLayerType = (typeof PICKING_LAYERS)[number];
20
+ export type LayerType = (typeof LAYERS)[number];
21
+ export type PickingElement = {
22
+ type: string;
23
+ };
24
+ export type HoveredItem = {
25
+ layer: PickingLayerType;
26
+ element: PickingElement;
27
+ };
28
+ export type DrawingFunction<T> = (canvasContext: CanvasRenderingContext2D, stcContext: T) => void;
29
+ export type PickingDrawingFunction<T> = (imageData: ImageData, stcContext: T, scalingRatio: number) => void;
30
+ export type DrawingFunctionHandler<T> = (arg: {
31
+ type: 'picking';
32
+ layer: PickingLayerType;
33
+ fn: PickingDrawingFunction<T>;
34
+ } | {
35
+ type: 'rendering';
36
+ layer: LayerType;
37
+ fn: DrawingFunction<T>;
38
+ }) => void;
39
+ export type CanvasContextType<T> = {
40
+ register: DrawingFunctionHandler<T>;
41
+ unregister: DrawingFunctionHandler<T>;
42
+ captureCanvases: () => Promise<Blob>;
43
+ };
44
+ export type TimeToPixel = (time: number) => number;
45
+ export type PixelToTime = (x: number) => number;
46
+ type BaseTimeChartContextType = BaseChartContextType & {
47
+ width: number;
48
+ height: number;
49
+ timePixelOffset: number;
50
+ timeOrigin: number;
51
+ timeScale: number;
52
+ yPixelOffset: number;
53
+ getTimePixel: TimeToPixel;
54
+ getTime: PixelToTime;
55
+ getPoint: DataToPoint;
56
+ getData: PointToData;
57
+ theme: SpaceTimeChartTheme;
58
+ };
59
+ export type ChartOptions = {
60
+ captionSize?: number;
61
+ enableSnapping?: boolean;
62
+ hideDates?: boolean;
63
+ hideGrid?: boolean;
64
+ hidePathsLabels?: boolean;
65
+ hideTimeCaptions?: boolean;
66
+ showTicks?: boolean;
67
+ swapAxis?: boolean;
68
+ };
69
+ export type TimeChartContextType = BaseTimeChartContextType & ChartOptions;
70
+ export type ChartEventHandlers<T> = {
71
+ onPan?: Handler<{
72
+ isPanning: boolean;
73
+ initialPosition: Point;
74
+ position: Point;
75
+ initialData: DataPoint;
76
+ data: DataPoint;
77
+ context: T;
78
+ }>;
79
+ onZoom?: Handler<{
80
+ delta: number;
81
+ position: Point;
82
+ event: WheelEvent;
83
+ context: T;
84
+ }>;
85
+ onClick?: Handler<{
86
+ position: Point;
87
+ data: DataPoint;
88
+ event: MouseEvent;
89
+ hoveredItem: HoveredItem | null;
90
+ context: T;
91
+ }>;
92
+ onMouseMove?: Handler<{
93
+ position: Point;
94
+ data: DataPoint;
95
+ isHover: boolean;
96
+ hoveredItem: HoveredItem | null;
97
+ context: T;
98
+ }>;
99
+ onHoveredChildUpdate?: Handler<{
100
+ item: HoveredItem | null;
101
+ context: T;
102
+ }>;
103
+ } & Omit<HTMLProps<HTMLDivElement>, 'onClick' | 'onMouseMove'>;
104
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import '@osrd-project/ui-core/dist/theme.css';
2
+ export * from './chronogram';
3
+ export * from './common';
2
4
  export * from './spaceTimeChart';
3
5
  export * from './manchette';
4
6
  export * from './speedSpaceChart';