Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 8a83b00

Browse files
committed
ui-charts: adds top and bottom borders to gov
Details: - Adds top and bottom borders to TrackOccupancyCanvas - Adds top and bottom borders to TrackOccupancyManchette - Removes these borders when using TrackOccupancyStandalone Signed-off-by: Alexis Jacomy <[email protected]>
1 parent c14670f commit 8a83b00

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

ui-charts/src/trackOccupancyDiagram/components/TrackOccupancyCanvas.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@ const TrackOccupancyCanvas = ({
3232
selectedTrainId,
3333
onClose,
3434
topPadding = 0,
35+
hideBorders = false,
3536
}: {
3637
position: number;
3738
tracks: Track[];
3839
occupancyZones: OccupancyZone[];
3940
selectedTrainId?: string;
4041
onClose?: () => void;
4142
topPadding?: number;
43+
hideBorders?: boolean;
4244
}) => (
4345
<>
44-
<TracksLayer position={position} tracks={tracks} topPadding={topPadding} />
46+
<TracksLayer
47+
position={position}
48+
tracks={tracks}
49+
topPadding={topPadding}
50+
drawBorders={!hideBorders}
51+
/>
4552
<OccupancyZonesLayer
4653
tracks={tracks}
4754
position={position}

ui-charts/src/trackOccupancyDiagram/components/TrackOccupancyStandalone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const TrackOccupancyStandalone = ({
5353
tracks={tracks}
5454
occupancyZones={occupancyZones}
5555
selectedTrainId={selectedTrainId}
56+
hideBorders
5657
/>
5758
),
5859
manchetteNode: <TrackOccupancyManchette tracks={tracks} />,

ui-charts/src/trackOccupancyDiagram/components/helpers/drawElements/drawTracks.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { drawTrack } from './drawTrack';
22
import type { SpaceTimeChartContextType } from '../../../../spaceTimeChart';
3-
import { HOUR, MINUTE } from '../../../../spaceTimeChart/lib/consts';
3+
import { GREY_50, HOUR, MINUTE } from '../../../../spaceTimeChart/lib/consts';
44
import { TRACK_HEIGHT_CONTAINER, CANVAS_PADDING, COLORS, TICKS_PRIORITIES } from '../../consts';
55
import { type Track } from '../../types';
66
import { getLabelLevels, getLabelMarks } from '../../utils';
@@ -13,10 +13,12 @@ export const drawTracks = (
1313
{
1414
position,
1515
tracks,
16+
drawBorders,
1617
topPadding = 0,
1718
}: {
1819
position: number;
1920
tracks: Track[];
21+
drawBorders: boolean;
2022
topPadding: number;
2123
}
2224
) => {
@@ -38,6 +40,7 @@ export const drawTracks = (
3840
const labelLevels = getLabelLevels(breakpoints, pixelsPerMinute, TICKS_PRIORITIES);
3941
const labelMarks = getLabelMarks(timeRanges, timeStart, timeEnd, labelLevels);
4042

43+
// Draw backgrounds:
4144
let hours = Math.floor(timeStart / HOUR);
4245
const hourEnd = timeEnd / HOUR;
4346
while (hours < hourEnd) {
@@ -48,6 +51,7 @@ export const drawTracks = (
4851
hours++;
4952
}
5053

54+
// Draw actual tracks:
5155
ctx.save();
5256
ctx.translate(0, yStart + topPadding);
5357
tracks?.forEach((_, index) => {
@@ -61,4 +65,22 @@ export const drawTracks = (
6165
});
6266
});
6367
ctx.restore();
68+
69+
// Draw borders:
70+
if (drawBorders) {
71+
const externalBorderWidth = 1;
72+
const internalBorderWidth = 2;
73+
const fullBorderWidth = externalBorderWidth + internalBorderWidth;
74+
const yStartCrisp = Math.round(yStart);
75+
const yEndCrisp = Math.round(yEnd);
76+
ctx.fillStyle = GREY_50;
77+
ctx.fillRect(0, yStartCrisp, width, externalBorderWidth);
78+
ctx.fillRect(0, yEndCrisp - externalBorderWidth, width, externalBorderWidth);
79+
80+
ctx.fillStyle = GREY_50;
81+
ctx.globalAlpha = 0.15;
82+
ctx.fillRect(0, yStartCrisp + externalBorderWidth, width, internalBorderWidth);
83+
ctx.fillRect(0, yEndCrisp - fullBorderWidth, width, internalBorderWidth);
84+
ctx.globalAlpha = 1;
85+
}
6486
};

ui-charts/src/trackOccupancyDiagram/components/layers/TracksLayer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ const TracksLayer = ({
88
tracks,
99
position,
1010
topPadding,
11+
drawBorders,
1112
}: {
1213
tracks: Track[];
1314
position: number;
1415
topPadding: number;
16+
drawBorders: boolean;
1517
}) => {
1618
const drawingFunction = useCallback<DrawingFunction>(
1719
(ctx, stcContext) => {
18-
drawTracks(ctx, stcContext, { position, topPadding, tracks });
20+
drawTracks(ctx, stcContext, { position, topPadding, tracks, drawBorders });
1921
},
2022
[position, topPadding, tracks]
2123
);

ui-charts/src/trackOccupancyDiagram/styles/main.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
border-radius: inherit;
99
padding-top: 10px;
1010

11+
position: relative;
12+
&::before,
13+
&::after {
14+
content: '';
15+
position: absolute;
16+
width: 100%;
17+
left: 0;
18+
height: 3px;
19+
box-sizing: border-box;
20+
background-color: color-mix(in oklab, theme('colors.grey.50') 15%, transparent);
21+
border-color: theme('colors.grey.50');
22+
border-style: solid;
23+
}
24+
&::before {
25+
top: 0;
26+
border-top-width: 1px;
27+
}
28+
&::after {
29+
bottom: 0;
30+
border-bottom-width: 1px;
31+
}
32+
1133
> canvas {
1234
border-radius: inherit;
1335
}
@@ -81,6 +103,11 @@
81103
inset 0 1px 0 0 rgb(255, 255, 255);
82104
border-radius: 10px;
83105

106+
.track-occupancy-manchette::before,
107+
.track-occupancy-manchette::after {
108+
display: none;
109+
}
110+
84111
.manchette-space-time-chart-wrapper {
85112
overflow: auto;
86113
flex: 1;

0 commit comments

Comments
 (0)