@osrd-project/ui-charts 0.0.76 → 0.0.79
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.
- package/README.md +22 -19
- package/dist/index.esm.js +507 -258
- package/dist/index.esm.js.map +1 -1
- package/dist/manchette/components/Manchette.d.ts +2 -1
- package/dist/manchette/components/Waypoint.d.ts +7 -4
- package/dist/manchette/consts.d.ts +0 -1
- package/dist/manchette/hooks/useManchetteWithSpaceTimeChart.d.ts +2 -2
- package/dist/manchette/index.d.ts +2 -2
- package/dist/spaceTimeChart/components/Quadrilateral.d.ts +8 -2
- package/dist/spaceTimeChart/index.d.ts +1 -0
- package/dist/spaceTimeChart/utils/__tests__/scales.spec.d.ts +1 -0
- package/dist/spaceTimeChart/utils/canvas.d.ts +14 -2
- package/dist/spaceTimeChart/utils/colors.d.ts +3 -0
- package/dist/spaceTimeChart/utils/scales.d.ts +24 -0
- package/dist/speedSpaceChart/components/common/InteractionButtons.d.ts +2 -1
- package/dist/speedSpaceChart/components/common/SettingsPanel.d.ts +3 -2
- package/dist/speedSpaceChart/components/const.d.ts +5 -0
- package/dist/speedSpaceChart/components/helpers/layersManager.d.ts +1 -0
- package/dist/speedSpaceChart/components/hooks.d.ts +1 -1
- package/dist/speedSpaceChart/components/layers/ReticleLayer.d.ts +2 -3
- package/dist/speedSpaceChart/components/utils.d.ts +0 -13
- package/dist/theme.css +4165 -4228
- package/dist/theme.css.map +1 -1
- package/dist/trackOccupancyDiagram/components/layers/OccupancyZonesLayer.d.ts +3 -1
- package/dist/trackOccupancyDiagram/components/types.d.ts +12 -11
- package/dist/trackOccupancyDiagram/index.d.ts +1 -0
- package/package.json +11 -12
package/dist/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import cx from 'classnames';
|
|
|
3
3
|
import { clamp as clamp$1, isEqual, inRange, last, flatten, sortBy, sum } from 'lodash';
|
|
4
4
|
import chroma from 'chroma-js';
|
|
5
5
|
import { ZoomOut, ZoomIn, Iterations, Plus, Dash, KebabHorizontal, X } from '@osrd-project/ui-icons';
|
|
6
|
-
import { Checkbox } from '@osrd-project/ui-core';
|
|
6
|
+
import { Checkbox, Slider } from '@osrd-project/ui-core';
|
|
7
7
|
import * as d3selection from 'd3-selection';
|
|
8
8
|
import * as d3zoom from 'd3-zoom';
|
|
9
9
|
|
|
@@ -239,6 +239,63 @@ function drawAliasedDisc(imageData, { x: centerX, y: centerY }, radius, [r, g, b
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Draws an aliased quadrilateral
|
|
244
|
+
*
|
|
245
|
+
* vertices[0] ________ vertices[1]
|
|
246
|
+
* / /
|
|
247
|
+
* vertices[3] /________/ vertices[2]
|
|
248
|
+
*
|
|
249
|
+
*/
|
|
250
|
+
function drawAliasedQuadrilateral(imageData, points, [r, g, b], scalingRatio = 1) {
|
|
251
|
+
const vertices = points.map((point) => ({
|
|
252
|
+
x: Math.round(point.x * scalingRatio),
|
|
253
|
+
y: Math.round(point.y * scalingRatio),
|
|
254
|
+
}));
|
|
255
|
+
let { x: xmin, x: xmax, y: ymin, y: ymax } = vertices[0];
|
|
256
|
+
for (let i = 1; i < vertices.length; i++) {
|
|
257
|
+
const { x, y } = vertices[i];
|
|
258
|
+
if (x < xmin)
|
|
259
|
+
xmin = x;
|
|
260
|
+
else if (x > xmax)
|
|
261
|
+
xmax = x;
|
|
262
|
+
if (y < ymin)
|
|
263
|
+
ymin = y;
|
|
264
|
+
else if (y > ymax)
|
|
265
|
+
ymax = y;
|
|
266
|
+
}
|
|
267
|
+
xmin = clamp$1(xmin, 0, imageData.width - 1);
|
|
268
|
+
ymin = clamp$1(ymin, 0, imageData.height - 1);
|
|
269
|
+
xmax = clamp$1(xmax, 0, imageData.width - 1);
|
|
270
|
+
ymax = clamp$1(ymax, 0, imageData.height - 1);
|
|
271
|
+
for (let y = ymin; y < ymax; y++) {
|
|
272
|
+
for (let x = xmin; x < xmax; x++) {
|
|
273
|
+
// Compute whether the point is inside the quadrilateral
|
|
274
|
+
// using the Ray casting algorithm (see https://en.wikipedia.org/wiki/Point_in_polygon)
|
|
275
|
+
let isInside = false;
|
|
276
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
277
|
+
const pointA = vertices[i];
|
|
278
|
+
const pointB = i === vertices.length - 1 ? vertices[0] : vertices[i + 1];
|
|
279
|
+
// Line equation from A to B: y(x) = m * x + c
|
|
280
|
+
const m = (pointB.y - pointA.y) / (pointB.x - pointA.x);
|
|
281
|
+
const c = pointB.y - m * pointB.x;
|
|
282
|
+
// Invert the equation: x(y) = (y - c) / m
|
|
283
|
+
// Look only for points that are on the left of the line, so for a given y, x < (y - c) / m
|
|
284
|
+
if (pointA.y > y != pointB.y > y && x < (y - c) / m) {
|
|
285
|
+
isInside = !isInside;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// If the point is inside the quadrilateral, allow interactions with it
|
|
289
|
+
if (isInside) {
|
|
290
|
+
const index = (y * imageData.width + x) * 4;
|
|
291
|
+
imageData.data[index] = r;
|
|
292
|
+
imageData.data[index + 1] = g;
|
|
293
|
+
imageData.data[index + 2] = b;
|
|
294
|
+
imageData.data[index + 3] = 255;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
242
299
|
function drawAliasedRect(imageData, { x, y }, width, height, [r, g, b], scalingRatio = 1) {
|
|
243
300
|
x = Math.round(x * scalingRatio);
|
|
244
301
|
y = Math.round(y * scalingRatio);
|
|
@@ -339,14 +396,17 @@ function computeVisibleTimeMarkers(minT, maxT, timeRanges, gridlinesLevels, form
|
|
|
339
396
|
* To get crisp horizontal or vertical lines on a canvas, we must draw them as thin as possible, in
|
|
340
397
|
* terms of actual pixels on screen.
|
|
341
398
|
* The best way for this is:
|
|
342
|
-
* - To center lines 1, 3, 5... pixels wide in the middle of a pixel
|
|
343
|
-
* - To center lines 2, 4, 6... pixels wide between two pixels
|
|
399
|
+
* - To center lines 1, 3, 5... pixels wide in the middle of a pixel (0.5, 1.5, 2.5...)
|
|
400
|
+
* - To center lines 2, 4, 6... pixels wide between two pixels (0, 1, 2, 3...)
|
|
401
|
+
* Also, for HiDPi screens:
|
|
402
|
+
* - To center lines of "integer thicknesses" between two screen pixels (0, 0.5, 1, 1.5, 2...)
|
|
403
|
+
* - To center lines with `n + 0.5` thicknesses in the middle of a screen pixel (0.25, 0.75, 1.25, 1.75...)
|
|
344
404
|
* @param rawCoordinate Any input coordinate to fix
|
|
345
405
|
* @param lineWidth The width of the line to draw
|
|
346
406
|
* @param devicePixelRatio
|
|
347
407
|
*/
|
|
348
408
|
function getCrispLineCoordinate(rawCoordinate, lineWidth, devicePixelRatio = window.devicePixelRatio || 1) {
|
|
349
|
-
const centerOffset = lineWidth / 2;
|
|
409
|
+
const centerOffset = Math.ceil(lineWidth * devicePixelRatio) / devicePixelRatio / 2;
|
|
350
410
|
return (Math.round((rawCoordinate - centerOffset) * devicePixelRatio) / devicePixelRatio + centerOffset);
|
|
351
411
|
}
|
|
352
412
|
/**
|
|
@@ -367,6 +427,9 @@ function fillRect(ctx, { timeStart, timeEnd, spaceStart, spaceEnd }, { getPoint
|
|
|
367
427
|
|
|
368
428
|
const COLORS_TO_INDICES = {};
|
|
369
429
|
const INDICES_TO_COLORS = {};
|
|
430
|
+
const WHITE_ALPHA_75 = '#ffffffbf';
|
|
431
|
+
const BLACK_ALPHA_25 = '#00000025';
|
|
432
|
+
const GREY_50$3 = '#797671';
|
|
370
433
|
/**
|
|
371
434
|
* This function returns a unique hex color corresponding to the given index. The colors are
|
|
372
435
|
* generated as #000001, #000002 ... #0000ff, #000100 etc.
|
|
@@ -589,7 +652,7 @@ function useCanvas$1(dom, inputStcContext, position) {
|
|
|
589
652
|
useEffect(() => {
|
|
590
653
|
// Cache latest context in ref:
|
|
591
654
|
stcContextRef.current = inputStcContext;
|
|
592
|
-
|
|
655
|
+
scheduleRendering();
|
|
593
656
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
594
657
|
}, [inputStcContext.fingerprint]);
|
|
595
658
|
// Handle resizing:
|
|
@@ -605,6 +668,8 @@ function useCanvas$1(dom, inputStcContext, position) {
|
|
|
605
668
|
canvas.style.height = size.height + 'px';
|
|
606
669
|
canvas.setAttribute('width', Math.max(1, size.width * ratio) + 'px');
|
|
607
670
|
canvas.setAttribute('height', Math.max(1, size.height * ratio) + 'px');
|
|
671
|
+
if (isPicking)
|
|
672
|
+
canvas.style.imageRendering = 'pixelated';
|
|
608
673
|
if (!isPicking) {
|
|
609
674
|
// Reset the transform to identity, then apply the new scale
|
|
610
675
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
@@ -764,7 +829,7 @@ const MINUTE = 60 * SECOND;
|
|
|
764
829
|
const HOUR = 60 * MINUTE;
|
|
765
830
|
const DEFAULT_THEME = {
|
|
766
831
|
background: 'white',
|
|
767
|
-
breakpoints: [0.2, 0.
|
|
832
|
+
breakpoints: [0.2, 0.4, 0.7, 2, 6, 20, 60, Infinity],
|
|
768
833
|
timeRanges: [
|
|
769
834
|
10 * SECOND,
|
|
770
835
|
30 * SECOND,
|
|
@@ -871,20 +936,20 @@ const DEFAULT_THEME = {
|
|
|
871
936
|
4: {
|
|
872
937
|
width: 0.5,
|
|
873
938
|
color: BLUE,
|
|
874
|
-
opacity: 0.
|
|
939
|
+
opacity: 0.7,
|
|
875
940
|
dashArray: [16, 4],
|
|
876
941
|
},
|
|
877
942
|
5: {
|
|
878
943
|
width: 0.5,
|
|
879
944
|
color: BLUE,
|
|
880
|
-
opacity: 0.
|
|
945
|
+
opacity: 0.7,
|
|
881
946
|
dashArray: [8, 8],
|
|
882
947
|
},
|
|
883
948
|
6: {
|
|
884
949
|
width: 0.75,
|
|
885
950
|
color: BLUE,
|
|
886
|
-
opacity: 0.
|
|
887
|
-
dashArray: [
|
|
951
|
+
opacity: 0.7,
|
|
952
|
+
dashArray: [3, 8],
|
|
888
953
|
},
|
|
889
954
|
},
|
|
890
955
|
};
|
|
@@ -956,9 +1021,13 @@ const TimeCaptions = () => {
|
|
|
956
1021
|
// Render caption background:
|
|
957
1022
|
ctx.fillStyle = background;
|
|
958
1023
|
if (!swapAxis) {
|
|
1024
|
+
ctx.fillStyle = WHITE_ALPHA_75;
|
|
1025
|
+
ctx.fillRect(0, 0, width, 24);
|
|
1026
|
+
ctx.fillStyle = background;
|
|
959
1027
|
ctx.fillRect(0, spaceAxisSize, timeAxisSize, captionSize);
|
|
960
1028
|
}
|
|
961
1029
|
else {
|
|
1030
|
+
ctx.fillStyle = background;
|
|
962
1031
|
ctx.fillRect(0, 0, captionSize, timeAxisSize);
|
|
963
1032
|
}
|
|
964
1033
|
// Render time captions:
|
|
@@ -973,13 +1042,24 @@ const TimeCaptions = () => {
|
|
|
973
1042
|
ctx.font = `${styles.fontWeight || 'normal'} ${styles.font}`;
|
|
974
1043
|
const timePixel = getCrispLineCoordinate(getTimePixel(time), ctx.lineWidth);
|
|
975
1044
|
if (!swapAxis) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1045
|
+
ctx.beginPath();
|
|
1046
|
+
ctx.strokeStyle = timeCaptionsStyles[1].color;
|
|
1047
|
+
ctx.lineWidth = 1;
|
|
1048
|
+
let tickHeight = 4;
|
|
1049
|
+
const mod = time % (60 * 60 * 1000);
|
|
1050
|
+
if (mod === 0) {
|
|
1051
|
+
tickHeight = 8;
|
|
981
1052
|
}
|
|
982
|
-
|
|
1053
|
+
else if (mod % (30 * 60 * 1000) === 0) {
|
|
1054
|
+
tickHeight = 6;
|
|
1055
|
+
}
|
|
1056
|
+
ctx.moveTo(timePixel, spaceAxisSize);
|
|
1057
|
+
ctx.lineTo(timePixel, spaceAxisSize + tickHeight);
|
|
1058
|
+
ctx.moveTo(timePixel, 0);
|
|
1059
|
+
ctx.lineTo(timePixel, tickHeight);
|
|
1060
|
+
ctx.stroke();
|
|
1061
|
+
ctx.fillStyle = timeCaptionsStyles[1].color;
|
|
1062
|
+
ctx.fillText(text, timePixel, styles.topOffset || 0);
|
|
983
1063
|
ctx.fillText(text, timePixel, spaceAxisSize + (styles.topOffset || 0));
|
|
984
1064
|
}
|
|
985
1065
|
else {
|
|
@@ -1014,7 +1094,9 @@ const TimeCaptions = () => {
|
|
|
1014
1094
|
};
|
|
1015
1095
|
|
|
1016
1096
|
const TimeGraduations = () => {
|
|
1017
|
-
const
|
|
1097
|
+
const { position, isHover } = useContext(MouseContext);
|
|
1098
|
+
const mouseX = position.x;
|
|
1099
|
+
const drawingFunction = useCallback((ctx, { timeScale, timeOrigin, timePixelOffset, spacePixelOffset, getTimePixel, getTime, swapAxis, width, height, theme: { breakpoints, timeRanges, timeGraduationsStyles, timeGraduationsPriorities }, }) => {
|
|
1018
1100
|
const timeAxisSize = !swapAxis ? width : height;
|
|
1019
1101
|
const spaceAxisSize = !swapAxis ? height : width;
|
|
1020
1102
|
const minT = timeOrigin - timeScale * timePixelOffset;
|
|
@@ -1035,8 +1117,8 @@ const TimeGraduations = () => {
|
|
|
1035
1117
|
const styles = timeGraduationsStyles[level];
|
|
1036
1118
|
ctx.strokeStyle = styles.color;
|
|
1037
1119
|
ctx.lineWidth = styles.width;
|
|
1038
|
-
ctx.globalAlpha = styles.opacity
|
|
1039
|
-
ctx.setLineDash(styles.dashArray
|
|
1120
|
+
ctx.globalAlpha = styles.opacity ?? 1;
|
|
1121
|
+
ctx.setLineDash(styles.dashArray ?? []);
|
|
1040
1122
|
if (styles.dashArray) {
|
|
1041
1123
|
ctx.lineDashOffset = -spacePixelOffset;
|
|
1042
1124
|
}
|
|
@@ -1052,10 +1134,40 @@ const TimeGraduations = () => {
|
|
|
1052
1134
|
}
|
|
1053
1135
|
ctx.stroke();
|
|
1054
1136
|
});
|
|
1137
|
+
if (!swapAxis && isHover && mouseX != null && !isNaN(mouseX)) {
|
|
1138
|
+
const crispX = getCrispLineCoordinate(mouseX, 1);
|
|
1139
|
+
const timeValue = getTime(crispX);
|
|
1140
|
+
const timeLabel = new Date(timeValue).toLocaleTimeString();
|
|
1141
|
+
ctx.globalAlpha = 1;
|
|
1142
|
+
// Vertical line:
|
|
1143
|
+
ctx.strokeStyle = BLACK_ALPHA_25;
|
|
1144
|
+
ctx.lineWidth = 1;
|
|
1145
|
+
ctx.setLineDash([]);
|
|
1146
|
+
ctx.beginPath();
|
|
1147
|
+
ctx.moveTo(crispX, 0);
|
|
1148
|
+
ctx.lineTo(crispX, spaceAxisSize);
|
|
1149
|
+
ctx.stroke();
|
|
1150
|
+
// Label
|
|
1151
|
+
const padding = 4;
|
|
1152
|
+
const fontSize = 12;
|
|
1153
|
+
const fontWeight = '400';
|
|
1154
|
+
const fontFamily = 'IBM Plex Sans, sans-regular';
|
|
1155
|
+
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
1156
|
+
const textWidth = ctx.measureText(timeLabel).width;
|
|
1157
|
+
const labelX = Math.min(Math.max(crispX - textWidth / 2 - padding, 0), width - textWidth - padding * 2);
|
|
1158
|
+
const labelY = spaceAxisSize - 50;
|
|
1159
|
+
// Label background
|
|
1160
|
+
ctx.fillStyle = '#FFFFFF';
|
|
1161
|
+
ctx.fillRect(labelX, labelY - fontSize - 2, textWidth + padding * 2, fontSize + 4);
|
|
1162
|
+
// Text
|
|
1163
|
+
ctx.fillStyle = GREY_50$3;
|
|
1164
|
+
ctx.fillText(timeLabel, labelX + padding, labelY);
|
|
1165
|
+
}
|
|
1166
|
+
// Reset
|
|
1055
1167
|
ctx.setLineDash([]);
|
|
1056
1168
|
ctx.lineDashOffset = 0;
|
|
1057
1169
|
ctx.globalAlpha = 1;
|
|
1058
|
-
}, []);
|
|
1170
|
+
}, [mouseX, isHover]);
|
|
1059
1171
|
useDraw('graduations', drawingFunction);
|
|
1060
1172
|
return null;
|
|
1061
1173
|
};
|
|
@@ -1279,6 +1391,7 @@ function validateTheme({ breakpoints, timeRanges, timeCaptionsStyles, timeCaptio
|
|
|
1279
1391
|
throw new Error(`${PREFIX}: there should be a timeGraduationsStyles for value 1.`);
|
|
1280
1392
|
}
|
|
1281
1393
|
|
|
1394
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
1282
1395
|
/**
|
|
1283
1396
|
* This function helps to index a sequence of consecutive scales into a binary tree, to make it
|
|
1284
1397
|
* faster to find which scale contains any given position.
|
|
@@ -1493,10 +1606,37 @@ function getSpaceBreakpoints(from, to, tree) {
|
|
|
1493
1606
|
}
|
|
1494
1607
|
return res;
|
|
1495
1608
|
}
|
|
1609
|
+
/**
|
|
1610
|
+
* in most cases, after the rectangle zoom, the screen will be centered
|
|
1611
|
+
* on the center of the rectangle the user drew.
|
|
1612
|
+
* In case we reach max zoom, not to break this expectation we need a different offset calculation
|
|
1613
|
+
*/
|
|
1614
|
+
function computeRectZoomOffsets({ rect, timeOrigin, spaceOrigin, newTimeScale, newSpaceScale, swapAxes, chartWidth, chartHeight, }) {
|
|
1615
|
+
const chartTimeSizePx = !swapAxes ? chartWidth : chartHeight;
|
|
1616
|
+
const chartSpaceSizePx = !swapAxes ? chartHeight : chartWidth;
|
|
1617
|
+
const timeOffset = sideOffset(timeOrigin, newTimeScale, rect.timeStart, rect.timeEnd, chartTimeSizePx);
|
|
1618
|
+
const spaceOffset = sideOffset(spaceOrigin, newSpaceScale, rect.spaceStart, rect.spaceEnd, chartSpaceSizePx);
|
|
1619
|
+
return !swapAxes
|
|
1620
|
+
? { xOffset: timeOffset, yOffset: spaceOffset }
|
|
1621
|
+
: { xOffset: spaceOffset, yOffset: timeOffset };
|
|
1622
|
+
}
|
|
1623
|
+
function sideOffset(origin, newScale, rectStart, rectEnd, chartSideSizePx, axisPadding = 0) {
|
|
1624
|
+
const rectCenter = (Number(rectStart) + Number(rectEnd)) / 2;
|
|
1625
|
+
const newChartSize = chartSideSizePx * newScale;
|
|
1626
|
+
// newChartBorder is the x or y origin after zoom
|
|
1627
|
+
// it’s normally the same as rectStart (the left or top most part of the rectangle)
|
|
1628
|
+
// but if we reach max zoom we can’t use rectStart as the chart displayed origin
|
|
1629
|
+
// because it doesn’t garentees that the zoom rectangle stays exactly at the center of the chart after the zoom
|
|
1630
|
+
const newChartBorder = rectCenter - newChartSize / 2;
|
|
1631
|
+
return (origin - newChartBorder) / newScale - axisPadding * 2;
|
|
1632
|
+
}
|
|
1496
1633
|
|
|
1497
1634
|
const DEFAULT_PICKING_TOLERANCE = 5;
|
|
1498
1635
|
const PAUSE_THICKNESS = 7;
|
|
1499
1636
|
const PAUSE_OPACITY = 0.2;
|
|
1637
|
+
const CIRCLE_RADIUS = 4;
|
|
1638
|
+
const VERTICAL_LINE_HEIGHT = 18;
|
|
1639
|
+
const TEXT_PADDING = 3;
|
|
1500
1640
|
function isPointPickingElement(element) {
|
|
1501
1641
|
return element.type === 'point';
|
|
1502
1642
|
}
|
|
@@ -1536,8 +1676,8 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1536
1676
|
/**
|
|
1537
1677
|
* This function returns the list of points to join to draw the path. As it can be discontinuous,
|
|
1538
1678
|
* it is returned as a Point[][]. For now, the only case for discontinuous paths is when the path
|
|
1539
|
-
* stops on a flat step (in which case, we assume the path will be drawn differently
|
|
1540
|
-
* step layer).
|
|
1679
|
+
* stops on or crosses a flat step (in which case, we assume the path will be drawn differently
|
|
1680
|
+
* in the flat step layer).
|
|
1541
1681
|
*
|
|
1542
1682
|
* It will be both used to render the visible path, and the segments on the picking layer.
|
|
1543
1683
|
*/
|
|
@@ -1651,6 +1791,32 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1651
1791
|
}
|
|
1652
1792
|
});
|
|
1653
1793
|
}, [path]);
|
|
1794
|
+
/**
|
|
1795
|
+
* This function draws the label with a background.
|
|
1796
|
+
* It is used to draw the label of the path or single point, with a background to make it more readable.
|
|
1797
|
+
*/
|
|
1798
|
+
const drawLabelWithBackground = useCallback((ctx, text, x, y, { textColor, background, fontSize, fontFamily, padding = TEXT_PADDING, alpha = 0.75, }) => {
|
|
1799
|
+
ctx.save();
|
|
1800
|
+
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
1801
|
+
const measure = ctx.measureText(text);
|
|
1802
|
+
const left = measure.actualBoundingBoxLeft;
|
|
1803
|
+
const right = measure.actualBoundingBoxRight;
|
|
1804
|
+
const ascent = measure.actualBoundingBoxAscent;
|
|
1805
|
+
const descent = measure.actualBoundingBoxDescent;
|
|
1806
|
+
const w = left + right + 2 * padding;
|
|
1807
|
+
const h = ascent + descent + 2 * padding;
|
|
1808
|
+
const rx = x - left - padding;
|
|
1809
|
+
const ry = y - ascent - padding;
|
|
1810
|
+
// BACKGROUND
|
|
1811
|
+
ctx.globalAlpha = alpha;
|
|
1812
|
+
ctx.fillStyle = background;
|
|
1813
|
+
ctx.fillRect(rx, ry, w, h);
|
|
1814
|
+
// TEXT
|
|
1815
|
+
ctx.globalAlpha = 1;
|
|
1816
|
+
ctx.fillStyle = textColor;
|
|
1817
|
+
ctx.fillText(text, x, y);
|
|
1818
|
+
ctx.restore();
|
|
1819
|
+
}, []);
|
|
1654
1820
|
/**
|
|
1655
1821
|
* This function draws the label of the path.
|
|
1656
1822
|
*/
|
|
@@ -1694,23 +1860,21 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1694
1860
|
ctx.save();
|
|
1695
1861
|
ctx.translate(position.x, position.y);
|
|
1696
1862
|
ctx.rotate(angle);
|
|
1697
|
-
ctx.font = `${fontSize}px ${fontFamily}`;
|
|
1698
1863
|
ctx.textAlign = 'start';
|
|
1699
1864
|
const padding = 2;
|
|
1700
1865
|
const measure = ctx.measureText(label);
|
|
1701
1866
|
const w = measure.width + 2 * padding;
|
|
1702
|
-
const actualBoundingBoxHeight = measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent;
|
|
1703
|
-
const h = actualBoundingBoxHeight + 2 * padding;
|
|
1704
1867
|
const dx = w < pathLength ? 5 : (pathLength - w) / 2; // Progressively center the label if the path is shorter than the label
|
|
1705
1868
|
const dy = angle >= 0 ? -5 : 15;
|
|
1706
|
-
ctx
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1869
|
+
drawLabelWithBackground(ctx, label, dx, dy, {
|
|
1870
|
+
fontSize,
|
|
1871
|
+
fontFamily,
|
|
1872
|
+
textColor: labelColor,
|
|
1873
|
+
background,
|
|
1874
|
+
padding,
|
|
1875
|
+
});
|
|
1712
1876
|
ctx.restore();
|
|
1713
|
-
}, []);
|
|
1877
|
+
}, [drawLabelWithBackground]);
|
|
1714
1878
|
/**
|
|
1715
1879
|
* This function draws the extremities of the path.
|
|
1716
1880
|
*/
|
|
@@ -1779,7 +1943,41 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1779
1943
|
drawLines(totalPathWidth, backgroundColor);
|
|
1780
1944
|
ctx.restore();
|
|
1781
1945
|
}, [border, getPathLines, level]);
|
|
1946
|
+
const drawSinglePoint = useCallback((ctx, stcContext, point) => {
|
|
1947
|
+
const { getPoint, hidePathsLabels, theme: { background, pathsStyles: { fontSize, fontFamily }, }, } = stcContext;
|
|
1948
|
+
const { x, y } = getPoint(point);
|
|
1949
|
+
const style = STYLES[level];
|
|
1950
|
+
ctx.save();
|
|
1951
|
+
ctx.strokeStyle = color;
|
|
1952
|
+
ctx.lineWidth = style.width;
|
|
1953
|
+
ctx.setLineDash((style.dashArray || []).map((v) => v / 2));
|
|
1954
|
+
// Draw the vertical lines above and below the circle
|
|
1955
|
+
ctx.beginPath();
|
|
1956
|
+
ctx.moveTo(x, y - VERTICAL_LINE_HEIGHT / 2);
|
|
1957
|
+
ctx.lineTo(x, y + VERTICAL_LINE_HEIGHT / 2);
|
|
1958
|
+
ctx.stroke();
|
|
1959
|
+
// Draw the circle
|
|
1960
|
+
ctx.beginPath();
|
|
1961
|
+
ctx.arc(x, y, CIRCLE_RADIUS, 0, Math.PI * 2);
|
|
1962
|
+
ctx.stroke();
|
|
1963
|
+
// Draw the label
|
|
1964
|
+
if (!hidePathsLabels) {
|
|
1965
|
+
ctx.textAlign = 'center';
|
|
1966
|
+
const labelY = y - CIRCLE_RADIUS - VERTICAL_LINE_HEIGHT - TEXT_PADDING;
|
|
1967
|
+
drawLabelWithBackground(ctx, path.label, x, labelY, {
|
|
1968
|
+
fontFamily,
|
|
1969
|
+
fontSize,
|
|
1970
|
+
textColor: color,
|
|
1971
|
+
background,
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
ctx.restore();
|
|
1975
|
+
}, [level, color, drawLabelWithBackground, path.label]);
|
|
1782
1976
|
const drawAll = useCallback((ctx, stcContext) => {
|
|
1977
|
+
if (path.points.length === 1) {
|
|
1978
|
+
drawSinglePoint(ctx, stcContext, path.points[0]);
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1783
1981
|
drawBorder(ctx, stcContext);
|
|
1784
1982
|
// Draw stops:
|
|
1785
1983
|
ctx.strokeStyle = color;
|
|
@@ -1820,19 +2018,32 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1820
2018
|
drawLabel(ctx, stcContext, path.label, color, flatten(lines), pathLength);
|
|
1821
2019
|
}
|
|
1822
2020
|
}, [
|
|
2021
|
+
path.points,
|
|
2022
|
+
path.label,
|
|
2023
|
+
drawBorder,
|
|
1823
2024
|
color,
|
|
1824
2025
|
drawPauses,
|
|
1825
2026
|
level,
|
|
1826
2027
|
getPathLines,
|
|
1827
2028
|
drawExtremities,
|
|
2029
|
+
drawSinglePoint,
|
|
1828
2030
|
computePathLength,
|
|
1829
2031
|
drawLabel,
|
|
1830
|
-
drawBorder,
|
|
1831
|
-
path.label,
|
|
1832
2032
|
]);
|
|
1833
2033
|
useDraw('paths', drawAll);
|
|
1834
2034
|
const drawPicking = useCallback((imageData, stcContext, scalingRatio) => {
|
|
1835
2035
|
const { registerPickingElement } = stcContext;
|
|
2036
|
+
// Draw single point:
|
|
2037
|
+
if (path.points.length === 1) {
|
|
2038
|
+
const pickingElement = {
|
|
2039
|
+
type: 'point',
|
|
2040
|
+
pathId: path.id,
|
|
2041
|
+
point: stcContext.getPoint(path.points[0]),
|
|
2042
|
+
};
|
|
2043
|
+
const index = registerPickingElement(pickingElement);
|
|
2044
|
+
const pointColor = hexToRgb(indexToColor(index));
|
|
2045
|
+
drawAliasedDisc(imageData, pickingElement.point, VERTICAL_LINE_HEIGHT / 2, pointColor, false, scalingRatio);
|
|
2046
|
+
}
|
|
1836
2047
|
// Draw segments:
|
|
1837
2048
|
getPathLines(stcContext).forEach((line) => line.forEach((point, i, a) => {
|
|
1838
2049
|
if (i) {
|
|
@@ -1845,6 +2056,10 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1845
2056
|
};
|
|
1846
2057
|
const index = registerPickingElement(pickingElement);
|
|
1847
2058
|
const lineColor = hexToRgb(indexToColor(index));
|
|
2059
|
+
// Skip segments linking two points on the same time value (these are flat steps, and paths shouldn't be
|
|
2060
|
+
// actionable on these steps):
|
|
2061
|
+
if (previousPoint[stcContext.timeAxis] === point[stcContext.timeAxis])
|
|
2062
|
+
return;
|
|
1848
2063
|
drawAliasedLine(imageData, previousPoint, point, lineColor, STYLES[level].width + pickingTolerance, true, scalingRatio);
|
|
1849
2064
|
}
|
|
1850
2065
|
}));
|
|
@@ -1859,7 +2074,7 @@ const PathLayer = ({ path, color, level = DEFAULT_LEVEL, pickingTolerance = DEFA
|
|
|
1859
2074
|
const lineColor = hexToRgb(indexToColor(index));
|
|
1860
2075
|
drawAliasedDisc(imageData, point, (STYLES[level].width + pickingTolerance) * 2, lineColor, false, scalingRatio);
|
|
1861
2076
|
});
|
|
1862
|
-
}, [getPathLines, getSnapPoints, level, path.id, pickingTolerance]);
|
|
2077
|
+
}, [getPathLines, getSnapPoints, level, path.id, path.points, pickingTolerance]);
|
|
1863
2078
|
usePicking('paths', drawPicking);
|
|
1864
2079
|
return null;
|
|
1865
2080
|
};
|
|
@@ -1958,6 +2173,21 @@ const SpaceTimeChart = (props) => {
|
|
|
1958
2173
|
showTicks,
|
|
1959
2174
|
hideDates,
|
|
1960
2175
|
]);
|
|
2176
|
+
const pickingState = useMemo(() => {
|
|
2177
|
+
const pickingElements = [];
|
|
2178
|
+
const resetPickingElements = () => {
|
|
2179
|
+
pickingElements.length = 0;
|
|
2180
|
+
};
|
|
2181
|
+
const registerPickingElement = (element) => {
|
|
2182
|
+
pickingElements.push(element);
|
|
2183
|
+
return pickingElements.length - 1;
|
|
2184
|
+
};
|
|
2185
|
+
return {
|
|
2186
|
+
pickingElements,
|
|
2187
|
+
resetPickingElements,
|
|
2188
|
+
registerPickingElement,
|
|
2189
|
+
};
|
|
2190
|
+
}, []);
|
|
1961
2191
|
const contextState = useMemo(() => {
|
|
1962
2192
|
const spaceScaleTree = spaceScalesToBinaryTree(spaceOrigin, spaceScales);
|
|
1963
2193
|
const flatSteps = getFlatSteps(spaceScales);
|
|
@@ -1980,15 +2210,8 @@ const SpaceTimeChart = (props) => {
|
|
|
1980
2210
|
const getTime = getPixelToTime(timeOrigin, timePixelOffset, timeScale);
|
|
1981
2211
|
const getSpace = getPixelToSpace(spacePixelOffset, spaceScaleTree);
|
|
1982
2212
|
const getData = getPointToData(getTime, getSpace, timeAxis, spaceAxis);
|
|
1983
|
-
const pickingElements = [];
|
|
1984
|
-
const resetPickingElements = () => {
|
|
1985
|
-
pickingElements.length = 0;
|
|
1986
|
-
};
|
|
1987
|
-
const registerPickingElement = (element) => {
|
|
1988
|
-
pickingElements.push(element);
|
|
1989
|
-
return pickingElements.length - 1;
|
|
1990
|
-
};
|
|
1991
2213
|
return {
|
|
2214
|
+
...pickingState,
|
|
1992
2215
|
fingerprint,
|
|
1993
2216
|
width,
|
|
1994
2217
|
height,
|
|
@@ -1998,9 +2221,6 @@ const SpaceTimeChart = (props) => {
|
|
|
1998
2221
|
getTime,
|
|
1999
2222
|
getSpace,
|
|
2000
2223
|
getData,
|
|
2001
|
-
pickingElements,
|
|
2002
|
-
resetPickingElements,
|
|
2003
|
-
registerPickingElement,
|
|
2004
2224
|
operationalPoints,
|
|
2005
2225
|
spaceOrigin,
|
|
2006
2226
|
spaceScaleTree,
|
|
@@ -2024,7 +2244,7 @@ const SpaceTimeChart = (props) => {
|
|
|
2024
2244
|
: fullTheme.dateCaptionsSize + fullTheme.timeCaptionsSize,
|
|
2025
2245
|
};
|
|
2026
2246
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2027
|
-
}, [fingerprint]);
|
|
2247
|
+
}, [fingerprint, pickingState]);
|
|
2028
2248
|
const mouseState = useMouseTracking(root);
|
|
2029
2249
|
const { position, down, isHover } = mouseState;
|
|
2030
2250
|
const { canvasContext, hoveredItem } = useCanvas$1(canvasesRoot, contextState, position);
|
|
@@ -2112,7 +2332,7 @@ const ConflictLayer = ({ conflicts }) => {
|
|
|
2112
2332
|
return null;
|
|
2113
2333
|
};
|
|
2114
2334
|
|
|
2115
|
-
const Tooltip$1 = ({ position, children }) => (React.createElement("div", { className: "spacetimechart-tooltip", style: { left: position.x, top: position.y } }, children));
|
|
2335
|
+
const Tooltip$1 = ({ position, children }) => (React.createElement("div", { className: "ui-spacetimechart-tooltip", style: { left: position.x, top: position.y } }, children));
|
|
2116
2336
|
|
|
2117
2337
|
const formatDistance = (meters) => {
|
|
2118
2338
|
const km = meters / 1000;
|
|
@@ -2202,6 +2422,9 @@ const WorkScheduleLayer = ({ workSchedules, imageUrl }) => {
|
|
|
2202
2422
|
return workSchedules.flatMap((ws) => ws.spaceRanges.map(([spaceStart, spaceEnd]) => (React.createElement(PatternRect, { key: `${ws.type}-${ws.timeStart}-${ws.timeEnd}-${spaceStart}-${spaceEnd}`, timeStart: ws.timeStart, timeEnd: ws.timeEnd, spaceStart: spaceStart, spaceEnd: spaceEnd, imageElement: imageElement }))));
|
|
2203
2423
|
};
|
|
2204
2424
|
|
|
2425
|
+
function isQuadrilaterPickingElement(element) {
|
|
2426
|
+
return element.type === 'quadrilateral';
|
|
2427
|
+
}
|
|
2205
2428
|
/**
|
|
2206
2429
|
* Draws a quadrilateral in the space time chart
|
|
2207
2430
|
* Position correspond to each point of the quadrilateral
|
|
@@ -2211,7 +2434,7 @@ const WorkScheduleLayer = ({ workSchedules, imageUrl }) => {
|
|
|
2211
2434
|
* vertices[3] /________/ vertices[2]
|
|
2212
2435
|
*
|
|
2213
2436
|
*/
|
|
2214
|
-
const Quadrilateral = ({ vertices, style }) => {
|
|
2437
|
+
const Quadrilateral = ({ id, vertices, style }) => {
|
|
2215
2438
|
const drawRegion = useCallback((ctx, { getSpacePixel, getTimePixel }) => {
|
|
2216
2439
|
ctx.save();
|
|
2217
2440
|
ctx.fillStyle = style.backgroundColor ?? 'lightblue';
|
|
@@ -2227,6 +2450,17 @@ const Quadrilateral = ({ vertices, style }) => {
|
|
|
2227
2450
|
ctx.restore();
|
|
2228
2451
|
}, [vertices, style]);
|
|
2229
2452
|
useDraw('background', drawRegion);
|
|
2453
|
+
const drawPicking = useCallback((imageData, { registerPickingElement, getTimePixel, getSpacePixel }, scalingRatio) => {
|
|
2454
|
+
const points = vertices.map((vertice) => ({
|
|
2455
|
+
x: getTimePixel(vertice.time),
|
|
2456
|
+
y: getSpacePixel(vertice.position),
|
|
2457
|
+
}));
|
|
2458
|
+
const pickingElement = { type: 'quadrilateral', id };
|
|
2459
|
+
const index = registerPickingElement(pickingElement);
|
|
2460
|
+
const color = hexToRgb(indexToColor(index));
|
|
2461
|
+
drawAliasedQuadrilateral(imageData, points, color, scalingRatio);
|
|
2462
|
+
}, [id, vertices]);
|
|
2463
|
+
usePicking('paths', drawPicking);
|
|
2230
2464
|
return null;
|
|
2231
2465
|
};
|
|
2232
2466
|
|
|
@@ -2326,6 +2560,7 @@ function isPathOnScreen(width, height, points) {
|
|
|
2326
2560
|
|
|
2327
2561
|
const INITIAL_OP_LIST_HEIGHT = 521;
|
|
2328
2562
|
const BASE_WAYPOINT_HEIGHT = 32;
|
|
2563
|
+
const INITIAL_SPACE_TIME_CHART_HEIGHT = INITIAL_OP_LIST_HEIGHT + 40;
|
|
2329
2564
|
const MIN_ZOOM_MS_PER_PX = 600_000;
|
|
2330
2565
|
const MAX_ZOOM_MS_PER_PX = 625;
|
|
2331
2566
|
const DEFAULT_ZOOM_MS_PER_PX = 7_500;
|
|
@@ -2355,17 +2590,17 @@ function getDistance(a, b) {
|
|
|
2355
2590
|
};
|
|
2356
2591
|
}
|
|
2357
2592
|
|
|
2358
|
-
const Waypoint = ({ waypoint: { name, secondaryCode, id, position, onClick }, waypointRef, isActive, isMenuActive, }) => (React.createElement("div", { className: cx('flex waypoint items-baseline', {
|
|
2593
|
+
const Waypoint = ({ waypoint: { name, secondaryCode, id, position, onClick }, waypointRef, isActive, isMenuActive, testIdPrefix, }) => (React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}-base-info` : undefined, className: cx('flex waypoint items-baseline', {
|
|
2359
2594
|
'waypoint-active': isActive,
|
|
2360
2595
|
'menu-active': isMenuActive,
|
|
2361
2596
|
}), id: id, ref: waypointRef, onClick: () => {
|
|
2362
2597
|
if (onClick && !isMenuActive)
|
|
2363
2598
|
onClick(id);
|
|
2364
2599
|
} },
|
|
2365
|
-
React.createElement("div", { className: "waypoint-position justify-self-start text-end" }, positionMmToKm(position)),
|
|
2366
|
-
React.createElement("div", { className: "waypoint-name mx-2 justify-self-start" }, name),
|
|
2600
|
+
React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}-position` : undefined, className: "waypoint-position justify-self-start text-end" }, positionMmToKm(position)),
|
|
2601
|
+
React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}-name` : undefined, className: "waypoint-name mx-2 justify-self-start" }, name),
|
|
2367
2602
|
React.createElement("div", { className: "waypoint-separator" }),
|
|
2368
|
-
React.createElement("div", { className: "waypoint-ch font-mono justify-self-end" }, secondaryCode),
|
|
2603
|
+
React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}-ch` : undefined, className: "waypoint-ch font-mono justify-self-end" }, secondaryCode),
|
|
2369
2604
|
React.createElement("div", { className: "waypoint-separator" }),
|
|
2370
2605
|
React.createElement("div", { className: "waypoint-type" }),
|
|
2371
2606
|
React.createElement("div", { className: "waypoint-separator" })));
|
|
@@ -2468,24 +2703,24 @@ const getScales = (waypoints, { isProportional, yZoom, height }, minZoomMillimet
|
|
|
2468
2703
|
};
|
|
2469
2704
|
const isInteractiveWaypoint = (item) => item != null && typeof item === 'object' && 'id' in item && 'position' in item;
|
|
2470
2705
|
|
|
2471
|
-
const Manchette = ({ zoomYIn, zoomYOut, resetZoom, yZoom = 1, contents, activeWaypointId, activeWaypointRef, isProportional = true, toggleMode, children, height = INITIAL_OP_LIST_HEIGHT, }) => (React.createElement("div", { className: "manchette-container" },
|
|
2706
|
+
const Manchette = ({ zoomYIn, zoomYOut, resetZoom, yZoom = 1, contents, activeWaypointId, activeWaypointRef, isProportional = true, toggleMode, children, height = INITIAL_OP_LIST_HEIGHT, }) => (React.createElement("div", { className: "ui-manchette-container" },
|
|
2472
2707
|
React.createElement("div", { className: "bg-white-100 border-r border-grey-30 relative", style: { minHeight: `${height}px` } },
|
|
2473
2708
|
React.createElement("div", { className: "waypoints-list" },
|
|
2474
2709
|
contents.map((content, index) => isInteractiveWaypoint(content) ? (React.createElement("div", { key: index, className: "waypoint-wrapper flex justify-start", style: content.styles },
|
|
2475
|
-
React.createElement(Waypoint, { waypoint: content, waypointRef: activeWaypointId === content.id ? activeWaypointRef : undefined, isActive: activeWaypointId === content.id, isMenuActive: !!activeWaypointId }))) : (React.createElement(Fragment, { key: index }, content))),
|
|
2710
|
+
React.createElement(Waypoint, { waypoint: content, waypointRef: activeWaypointId === content.id ? activeWaypointRef : undefined, isActive: activeWaypointId === content.id, isMenuActive: !!activeWaypointId, testIdPrefix: "waypoint" }))) : (React.createElement(Fragment, { key: index }, content))),
|
|
2476
2711
|
children)),
|
|
2477
|
-
React.createElement("div", { className: "manchette-actions" },
|
|
2712
|
+
React.createElement("div", { "data-testid": "manchette-actions", className: "manchette-actions" },
|
|
2478
2713
|
React.createElement("div", { className: "zoom-buttons" },
|
|
2479
|
-
React.createElement("button", { className: "zoom-out", onClick: zoomYOut, disabled: yZoom <= MIN_ZOOM_Y || !!activeWaypointId },
|
|
2714
|
+
React.createElement("button", { "data-testid": "zoom-out-button", className: "zoom-out", onClick: zoomYOut, disabled: yZoom <= MIN_ZOOM_Y || !!activeWaypointId },
|
|
2480
2715
|
React.createElement(ZoomOut, null)),
|
|
2481
|
-
React.createElement("button", { className: "zoom-in", onClick: zoomYIn, disabled: yZoom >= MAX_ZOOM_Y || !!activeWaypointId },
|
|
2716
|
+
React.createElement("button", { "data-testid": "zoom-in-button", className: "zoom-in", onClick: zoomYIn, disabled: yZoom >= MAX_ZOOM_Y || !!activeWaypointId },
|
|
2482
2717
|
React.createElement(ZoomIn, null)),
|
|
2483
|
-
React.createElement("button", { disabled: !!activeWaypointId, className: "zoom-reset", onClick: resetZoom }, "Fit")),
|
|
2718
|
+
React.createElement("button", { "data-testid": "reset-zoom-button", disabled: !!activeWaypointId, className: "zoom-reset", onClick: resetZoom }, "Fit")),
|
|
2484
2719
|
React.createElement("div", { className: "flex items-center ml-auto text-sans font-semibold" },
|
|
2485
2720
|
React.createElement("button", { disabled: !!activeWaypointId, className: "toggle-mode", onClick: toggleMode },
|
|
2486
2721
|
React.createElement("div", { className: "flex flex-col items-end pr-2" },
|
|
2487
|
-
React.createElement("span", { className: cx({ 'text-grey-30': !isProportional }) }, "Km"),
|
|
2488
|
-
React.createElement("span", { className: cx({ 'text-grey-30': isProportional }) }, "Lin\u00E9aire")))))));
|
|
2722
|
+
React.createElement("span", { className: cx({ 'text-grey-30': !isProportional }), "data-testid": "km-mode-button" }, "Km"),
|
|
2723
|
+
React.createElement("span", { className: cx({ 'text-grey-30': isProportional }), "data-testid": "linear-mode-button" }, "Lin\u00E9aire")))))));
|
|
2489
2724
|
|
|
2490
2725
|
const DEFAULT_MANCHETTE_WITH_SPACE_TIME_CHART_OPTIONS = {
|
|
2491
2726
|
displayTimeCaptions: true,
|
|
@@ -2493,7 +2728,7 @@ const DEFAULT_MANCHETTE_WITH_SPACE_TIME_CHART_OPTIONS = {
|
|
|
2493
2728
|
enableSpacePan: true,
|
|
2494
2729
|
enableTimeZoom: true,
|
|
2495
2730
|
};
|
|
2496
|
-
const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChartRef, height =
|
|
2731
|
+
const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChartRef, height = INITIAL_SPACE_TIME_CHART_HEIGHT, spaceTimeChartRef, defaultTimeOrigin = 0, defaultSpaceOrigin = 0, defaultXOffset = 0, verticalPadding = BASE_WAYPOINT_HEIGHT / 2, splitPoints = [], options = {}, }) => {
|
|
2497
2732
|
const { displayTimeCaptions, enableTimePan, enableSpacePan, enableTimeZoom } = useMemo(() => ({
|
|
2498
2733
|
...DEFAULT_MANCHETTE_WITH_SPACE_TIME_CHART_OPTIONS,
|
|
2499
2734
|
...options,
|
|
@@ -2515,7 +2750,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
|
|
|
2515
2750
|
waypointsChart: [],
|
|
2516
2751
|
scales: [],
|
|
2517
2752
|
});
|
|
2518
|
-
const { xZoom, yZoom, timeOrigin, spaceOrigin, xOffset, yOffset, scrollTo, panning, zoomMode, rect,
|
|
2753
|
+
const { xZoom, yZoom, timeOrigin, spaceOrigin, xOffset, yOffset, scrollTo, panning, zoomMode, rect, isProportional, } = state;
|
|
2519
2754
|
/** used when we change the train dataset for example to center the chart on the new data */
|
|
2520
2755
|
const setTimeOrigin = useCallback((newTimeOrigin) => {
|
|
2521
2756
|
setState((prev) => ({ ...prev, timeOrigin: newTimeOrigin }));
|
|
@@ -2525,91 +2760,60 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
|
|
|
2525
2760
|
const drawingHeightWithoutBothPadding = canvasDrawingHeight - BASE_WAYPOINT_HEIGHT; // 489
|
|
2526
2761
|
const totalDistance = calcTotalDistance(waypoints);
|
|
2527
2762
|
const { minZoomMillimeterPerPx, maxZoomMillimeterPerPx } = getExtremaScales(drawingHeightWithoutTopPadding, drawingHeightWithoutBothPadding, totalDistance);
|
|
2528
|
-
const
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
return {
|
|
2552
|
-
...prev,
|
|
2553
|
-
xZoom: timeZoomValue,
|
|
2554
|
-
yZoom: newYZoom,
|
|
2555
|
-
xOffset: newXOffset,
|
|
2556
|
-
yOffset: newYOffset,
|
|
2557
|
-
scrollTo: newYOffset,
|
|
2558
|
-
...overrideState,
|
|
2559
|
-
};
|
|
2560
|
-
});
|
|
2561
|
-
}, [timeOrigin, spaceOrigin, minZoomMillimeterPerPx, maxZoomMillimeterPerPx, yOffset, yZoom]);
|
|
2562
|
-
useEffect(() => {
|
|
2563
|
-
if (rect && !zoomMode && spaceTimeChartRef?.current) {
|
|
2564
|
-
const { timeStart, timeEnd, spaceStart, spaceEnd } = rect;
|
|
2565
|
-
const timeRange = Math.abs(Number(timeEnd) - Number(timeStart)); // width of rect in ms
|
|
2566
|
-
const spaceRange = Math.abs(spaceEnd - spaceStart); // height of rect in mm
|
|
2567
|
-
const chosenTimeScale = timeRange / spaceTimeChartRef.current.clientWidth;
|
|
2568
|
-
if (isProportional) {
|
|
2569
|
-
const chosenSpaceScale = spaceRange / drawingHeightWithoutTopPadding;
|
|
2570
|
-
handleRectangleZoom({
|
|
2571
|
-
scales: { chosenTimeScale, chosenSpaceScale },
|
|
2572
|
-
overrideState: { rect: null },
|
|
2573
|
-
});
|
|
2574
|
-
}
|
|
2575
|
-
else if (pixelRect) {
|
|
2576
|
-
const currentStopHeight = BASE_WAYPOINT_HEIGHT * yZoom;
|
|
2577
|
-
const { yStart, yEnd } = pixelRect;
|
|
2578
|
-
const numberOfStopsInRect = Math.abs(yEnd - yStart) / currentStopHeight;
|
|
2579
|
-
let newStopHeight = drawingHeightWithoutTopPadding / numberOfStopsInRect;
|
|
2580
|
-
// at maximum zoom, we want 3 stops displayed
|
|
2581
|
-
const maxStopHeight = drawingHeightWithoutTopPadding / (2 + BASE_WAYPOINT_HEIGHT / newStopHeight);
|
|
2582
|
-
newStopHeight = Math.min(newStopHeight, maxStopHeight);
|
|
2583
|
-
const newYZoom = newStopHeight / BASE_WAYPOINT_HEIGHT;
|
|
2584
|
-
const rectTop = yOffset + Math.min(yStart, yEnd) - WAYPOINT_LINE_HEIGHT;
|
|
2585
|
-
const numberOfStopsBeforeRectTop = rectTop / currentStopHeight;
|
|
2586
|
-
const newYOffset = numberOfStopsBeforeRectTop * newStopHeight;
|
|
2587
|
-
handleRectangleZoom({
|
|
2588
|
-
scales: {
|
|
2589
|
-
chosenTimeScale,
|
|
2590
|
-
},
|
|
2591
|
-
overrideState: {
|
|
2592
|
-
rect: null,
|
|
2593
|
-
pixelRect: null,
|
|
2594
|
-
yZoom: newYZoom,
|
|
2595
|
-
yOffset: newYOffset,
|
|
2596
|
-
scrollTo: newYOffset,
|
|
2597
|
-
},
|
|
2598
|
-
});
|
|
2763
|
+
const handleRectZoomEnd = useCallback((prev) => {
|
|
2764
|
+
if (!prev.rect || !spaceTimeChartRef?.current) {
|
|
2765
|
+
return {};
|
|
2766
|
+
}
|
|
2767
|
+
const { timeStart, timeEnd, spaceStart, spaceEnd } = prev.rect;
|
|
2768
|
+
const timeRange = Math.abs(Number(timeEnd) - Number(timeStart)); // width of rect in ms
|
|
2769
|
+
const spaceRange = Math.abs(spaceEnd - spaceStart); // height of rect in mm
|
|
2770
|
+
const chosenTimeScale = timeRange / spaceTimeChartRef.current.clientWidth;
|
|
2771
|
+
const newTimeScale = clamp$1(chosenTimeScale, MAX_ZOOM_MS_PER_PX, MIN_ZOOM_MS_PER_PX);
|
|
2772
|
+
const newXZoom = timeScaleToZoomValue(newTimeScale);
|
|
2773
|
+
const newXOffset = sideOffset(prev.timeOrigin, newTimeScale, prev.rect.timeStart, prev.rect.timeEnd, spaceTimeChartRef.current.clientWidth);
|
|
2774
|
+
let newYZoom = prev.yZoom;
|
|
2775
|
+
let newYOffset = prev.yOffset;
|
|
2776
|
+
if (prev.isProportional) {
|
|
2777
|
+
const chosenSpaceScale = spaceRange / drawingHeightWithoutTopPadding;
|
|
2778
|
+
const newSpaceScale = clamp$1(chosenSpaceScale, maxZoomMillimeterPerPx, minZoomMillimeterPerPx);
|
|
2779
|
+
// we don’t need to handle this case and compute an offset
|
|
2780
|
+
// this condition happens when we draw a rectangle
|
|
2781
|
+
// larger than the entire chart (minus padding)
|
|
2782
|
+
// that would actually zoom OUT if it wasn’t clamped.
|
|
2783
|
+
if (newSpaceScale !== minZoomMillimeterPerPx) {
|
|
2784
|
+
newYZoom = spaceScaleToZoomValue(minZoomMillimeterPerPx, maxZoomMillimeterPerPx, newSpaceScale);
|
|
2785
|
+
newYOffset = Math.abs(sideOffset(prev.spaceOrigin, newSpaceScale, prev.rect.spaceStart, prev.rect.spaceEnd, height, verticalPadding));
|
|
2599
2786
|
}
|
|
2600
2787
|
}
|
|
2788
|
+
else if (prev.pixelRect) {
|
|
2789
|
+
const currentStopHeight = BASE_WAYPOINT_HEIGHT * prev.yZoom;
|
|
2790
|
+
const { yStart, yEnd } = prev.pixelRect;
|
|
2791
|
+
const numberOfStopsInRect = Math.abs(yEnd - yStart) / currentStopHeight;
|
|
2792
|
+
let newStopHeight = drawingHeightWithoutTopPadding / numberOfStopsInRect;
|
|
2793
|
+
// at maximum zoom, we want 3 stops displayed
|
|
2794
|
+
const maxStopHeight = drawingHeightWithoutTopPadding / (2 + BASE_WAYPOINT_HEIGHT / newStopHeight);
|
|
2795
|
+
newStopHeight = Math.min(newStopHeight, maxStopHeight);
|
|
2796
|
+
newYZoom = newStopHeight / BASE_WAYPOINT_HEIGHT;
|
|
2797
|
+
const rectTop = prev.yOffset + Math.min(yStart, yEnd) - WAYPOINT_LINE_HEIGHT;
|
|
2798
|
+
const numberOfStopsBeforeRectTop = rectTop / currentStopHeight;
|
|
2799
|
+
newYOffset = numberOfStopsBeforeRectTop * newStopHeight;
|
|
2800
|
+
}
|
|
2801
|
+
return {
|
|
2802
|
+
xZoom: newXZoom,
|
|
2803
|
+
yZoom: newYZoom,
|
|
2804
|
+
xOffset: newXOffset,
|
|
2805
|
+
yOffset: newYOffset,
|
|
2806
|
+
scrollTo: newYOffset,
|
|
2807
|
+
rect: null,
|
|
2808
|
+
pixelRect: null,
|
|
2809
|
+
};
|
|
2601
2810
|
}, [
|
|
2602
|
-
state.rect,
|
|
2603
|
-
state.zoomMode,
|
|
2604
|
-
handleRectangleZoom,
|
|
2605
|
-
drawingHeightWithoutTopPadding,
|
|
2606
|
-
isProportional,
|
|
2607
|
-
pixelRect,
|
|
2608
|
-
rect,
|
|
2609
2811
|
spaceTimeChartRef,
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2812
|
+
drawingHeightWithoutTopPadding,
|
|
2813
|
+
maxZoomMillimeterPerPx,
|
|
2814
|
+
minZoomMillimeterPerPx,
|
|
2815
|
+
height,
|
|
2816
|
+
verticalPadding,
|
|
2613
2817
|
]);
|
|
2614
2818
|
const zoomYIn = useCallback(() => {
|
|
2615
2819
|
const maxZoom = isProportional
|
|
@@ -2872,6 +3076,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
|
|
|
2872
3076
|
if (!isPanning) {
|
|
2873
3077
|
return {
|
|
2874
3078
|
...prev,
|
|
3079
|
+
...(prev.zoomMode && prev.rect ? handleRectZoomEnd(prev) : {}),
|
|
2875
3080
|
panning: null,
|
|
2876
3081
|
zoomMode: false,
|
|
2877
3082
|
};
|
|
@@ -2949,6 +3154,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
|
|
|
2949
3154
|
yOffset,
|
|
2950
3155
|
waypointsToDisplay,
|
|
2951
3156
|
splitPoints,
|
|
3157
|
+
displayTimeCaptions,
|
|
2952
3158
|
xZoom,
|
|
2953
3159
|
xOffset,
|
|
2954
3160
|
verticalPadding,
|
|
@@ -2963,13 +3169,13 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
|
|
|
2963
3169
|
minZoomMillimeterPerPx,
|
|
2964
3170
|
maxZoomMillimeterPerPx,
|
|
2965
3171
|
setTimeOrigin,
|
|
2966
|
-
displayTimeCaptions,
|
|
2967
3172
|
isShiftPressed,
|
|
2968
3173
|
panning,
|
|
3174
|
+
manchetteWithSpaceTimeChartRef,
|
|
2969
3175
|
enableTimePan,
|
|
2970
3176
|
enableSpacePan,
|
|
3177
|
+
handleRectZoomEnd,
|
|
2971
3178
|
canvasDrawingHeight,
|
|
2972
|
-
manchetteWithSpaceTimeChartRef,
|
|
2973
3179
|
]);
|
|
2974
3180
|
};
|
|
2975
3181
|
|
|
@@ -2990,7 +3196,7 @@ const usePaths = (projectPathTrainResult) => useMemo(() => projectPathTrainResul
|
|
|
2990
3196
|
* This only covers basic usage. For more advanced control over the manchette
|
|
2991
3197
|
* and space time chart, the useManchetteWithSpaceTimeChart() hook can be used.
|
|
2992
3198
|
*/
|
|
2993
|
-
const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height =
|
|
3199
|
+
const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height = INITIAL_SPACE_TIME_CHART_HEIGHT, children, header, manchetteProps: additionalManchetteProps, spaceTimeChartProps: additionalSpaceTimeChartProps, splitPoints, }) => {
|
|
2994
3200
|
const manchetteWithSpaceTimeChartRef = useRef(null);
|
|
2995
3201
|
const spaceTimeChartRef = useRef(null);
|
|
2996
3202
|
const paths = usePaths(projectPathTrainResult);
|
|
@@ -3002,9 +3208,9 @@ const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height
|
|
|
3002
3208
|
splitPoints,
|
|
3003
3209
|
defaultTimeOrigin: Math.min(...projectPathTrainResult.map((p) => +p.departureTime)),
|
|
3004
3210
|
});
|
|
3005
|
-
return (React.createElement("div", { className: "manchette-space-time-chart-wrapper" },
|
|
3211
|
+
return (React.createElement("div", { className: "ui-manchette-space-time-chart-wrapper" },
|
|
3006
3212
|
React.createElement("div", { className: "header bg-ambientB-5 w-full border-b border-grey-30", style: { height: '40px' } }, header),
|
|
3007
|
-
React.createElement("div", { ref: manchetteWithSpaceTimeChartRef, className: "manchette flex",
|
|
3213
|
+
React.createElement("div", { ref: manchetteWithSpaceTimeChartRef, className: "manchette flex", onScroll: handleScroll },
|
|
3008
3214
|
React.createElement(Manchette, { ...manchetteProps, ...additionalManchetteProps }),
|
|
3009
3215
|
React.createElement("div", { className: "space-time-chart-container w-full sticky", ref: spaceTimeChartRef },
|
|
3010
3216
|
React.createElement(SpaceTimeChart, { className: "inset-0 absolute h-full", ...spaceTimeChartProps, ...additionalSpaceTimeChartProps },
|
|
@@ -3012,17 +3218,17 @@ const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height
|
|
|
3012
3218
|
children)))));
|
|
3013
3219
|
};
|
|
3014
3220
|
|
|
3015
|
-
const InteractionButtons = ({ reset, openSettingsPanel, store }) => (React.createElement("div", { id: "interaction-button-container", className: "z-10" },
|
|
3221
|
+
const InteractionButtons = ({ reset, openSettingsPanel, store, testIdPrefix, }) => (React.createElement("div", { id: "interaction-button-container", className: "z-10" },
|
|
3016
3222
|
React.createElement("div", { className: "zoom-buttons" },
|
|
3017
3223
|
React.createElement("button", { className: cx('interaction-button reset-button', {
|
|
3018
3224
|
inactive: store.ratioX == 1 && store.leftOffset == 0,
|
|
3019
|
-
}), onClick: () => reset() },
|
|
3225
|
+
}), onClick: () => reset(), "data-testid": testIdPrefix ? `${testIdPrefix}-reset` : undefined },
|
|
3020
3226
|
React.createElement(Iterations, null)),
|
|
3021
|
-
React.createElement("button", { className: "interaction-button plus-button inactive" },
|
|
3227
|
+
React.createElement("button", { className: "interaction-button plus-button inactive", "data-testid": testIdPrefix ? `${testIdPrefix}-zoom-in` : undefined },
|
|
3022
3228
|
React.createElement(Plus, null)),
|
|
3023
|
-
React.createElement("button", { className: "interaction-button inactive" },
|
|
3229
|
+
React.createElement("button", { className: "interaction-button inactive", "data-testid": testIdPrefix ? `${testIdPrefix}-zoom-out` : undefined },
|
|
3024
3230
|
React.createElement(Dash, null))),
|
|
3025
|
-
React.createElement("button", { className: "interaction-button elipsis-button", onClick: () => openSettingsPanel() },
|
|
3231
|
+
React.createElement("button", { className: "interaction-button elipsis-button", "data-testid": testIdPrefix ? `${testIdPrefix}-settings` : undefined, onClick: () => openSettingsPanel() },
|
|
3026
3232
|
React.createElement(KebabHorizontal, null))));
|
|
3027
3233
|
|
|
3028
3234
|
const SLOPE_FILL_COLOR = '#CFDDCE';
|
|
@@ -3050,9 +3256,6 @@ const LINEAR_LAYERS_HEIGHTS = {
|
|
|
3050
3256
|
POWER_RESTRICTIONS_HEIGHT: 40,
|
|
3051
3257
|
SPEED_LIMIT_TAGS_HEIGHT: 40,
|
|
3052
3258
|
};
|
|
3053
|
-
const LINEAR_LAYERS_HEIGHTS_BY_NAME = {
|
|
3054
|
-
electricalProfiles: LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT,
|
|
3055
|
-
powerRestrictions: LINEAR_LAYERS_HEIGHTS.POWER_RESTRICTIONS_HEIGHT};
|
|
3056
3259
|
const LINEAR_LAYER_SEPARATOR_HEIGHT = 1;
|
|
3057
3260
|
const LINEAR_LAYERS_BACKGROUND_COLOR = {
|
|
3058
3261
|
FIRST: 'rgb(250, 249, 245)',
|
|
@@ -3094,6 +3297,11 @@ const COLOR_DICTIONARY = {
|
|
|
3094
3297
|
'#EAA72B': '#EAA72B',
|
|
3095
3298
|
'#94918E': '#94918E',
|
|
3096
3299
|
};
|
|
3300
|
+
const ZOOM_CONFIG = {
|
|
3301
|
+
MIN_RATIO: 1,
|
|
3302
|
+
MAX_RATIO: 50,
|
|
3303
|
+
SLIDER_WIDTH: 100,
|
|
3304
|
+
};
|
|
3097
3305
|
|
|
3098
3306
|
const getGraphOffsets = (width, height, declivities) => {
|
|
3099
3307
|
const WIDTH_OFFSET = declivities ? width - 102 : width - 60; // +2px so that the tick appears on the right of the chart
|
|
@@ -3125,34 +3333,6 @@ const maxPositionValue = (speeds) => {
|
|
|
3125
3333
|
const clearCanvas = (ctx, width, height) => {
|
|
3126
3334
|
ctx.clearRect(0, 0, width, height);
|
|
3127
3335
|
};
|
|
3128
|
-
/**
|
|
3129
|
-
* Calculates the adaptive height based on the height supplied and the lineaires displayed.
|
|
3130
|
-
* @param height - The initial height value.
|
|
3131
|
-
* @param layersDisplay - The linear display options.
|
|
3132
|
-
* @param isIncludingLinearLayers - A flag to add or remove layers. Default is true.
|
|
3133
|
-
* @returns The calculated adaptive height.
|
|
3134
|
-
*/
|
|
3135
|
-
const getAdaptiveHeight = (height, layersDisplay, isIncludingLinearLayers = true) => {
|
|
3136
|
-
const adjustment = [
|
|
3137
|
-
layersDisplay.electricalProfiles ? LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT : 0,
|
|
3138
|
-
layersDisplay.powerRestrictions ? LINEAR_LAYERS_HEIGHTS.POWER_RESTRICTIONS_HEIGHT : 0,
|
|
3139
|
-
layersDisplay.speedLimitTags ? LINEAR_LAYERS_HEIGHTS.SPEED_LIMIT_TAGS_HEIGHT : 0,
|
|
3140
|
-
].reduce((acc, curr) => acc + curr, 0);
|
|
3141
|
-
return (height += isIncludingLinearLayers ? adjustment : -adjustment);
|
|
3142
|
-
};
|
|
3143
|
-
/**
|
|
3144
|
-
* Calculates the top position for the linear layers based on the height and the layers displayed.
|
|
3145
|
-
* The speed limit tags linear layer needs to call this function with the isSpeedLimitByTag flag set to true.
|
|
3146
|
-
*/
|
|
3147
|
-
const getLinearLayerMarginTop = (height, layersDisplay, isSpeedLimitByTag = false) => {
|
|
3148
|
-
let adjustment = 0;
|
|
3149
|
-
const { electricalProfiles, powerRestrictions } = layersDisplay;
|
|
3150
|
-
if (electricalProfiles)
|
|
3151
|
-
adjustment = LINEAR_LAYERS_HEIGHTS_BY_NAME.electricalProfiles;
|
|
3152
|
-
if (powerRestrictions && isSpeedLimitByTag)
|
|
3153
|
-
adjustment += LINEAR_LAYERS_HEIGHTS_BY_NAME.powerRestrictions;
|
|
3154
|
-
return height + adjustment - MARGINS.MARGIN_BOTTOM;
|
|
3155
|
-
};
|
|
3156
3336
|
/**
|
|
3157
3337
|
* Calculates the position on the graph scale based on the given parameters.
|
|
3158
3338
|
* @param position - The current position.
|
|
@@ -3385,9 +3565,7 @@ const getSnappedStop = (cursorX, width, store) => {
|
|
|
3385
3565
|
};
|
|
3386
3566
|
|
|
3387
3567
|
const SETTINGS_PANEL_BASE_HEIGHT = 442;
|
|
3388
|
-
const
|
|
3389
|
-
const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoveringSettingsPanel, translations, }) => {
|
|
3390
|
-
const [height, setHeight] = useState(`${SETTINGS_PANEL_BASE_HEIGHT}px`);
|
|
3568
|
+
const SettingsPanel = ({ color, store, setStore, setIsMouseHoveringSettingsPanel, adjustHeightOnLayerChange, translations, testIdPrefix, }) => {
|
|
3391
3569
|
const closeSettingsPanel = () => {
|
|
3392
3570
|
setIsMouseHoveringSettingsPanel(false);
|
|
3393
3571
|
setStore((prev) => ({
|
|
@@ -3395,18 +3573,15 @@ const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoverin
|
|
|
3395
3573
|
isSettingsPanelOpened: false,
|
|
3396
3574
|
}));
|
|
3397
3575
|
};
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
}
|
|
3403
|
-
}, [globalHeight, store.layersDisplay]);
|
|
3404
|
-
return (React.createElement("div", { id: "settings-panel", style: { background: `rgba(${color.substring(4, color.length - 1)}, 0.4)`, height }, className: "font-sans", onMouseEnter: () => setIsMouseHoveringSettingsPanel(true), onMouseLeave: () => setIsMouseHoveringSettingsPanel(false) },
|
|
3576
|
+
return (React.createElement("div", { id: "settings-panel", style: {
|
|
3577
|
+
background: `rgba(${color.substring(4, color.length - 1)}, 0.4)`,
|
|
3578
|
+
height: `${SETTINGS_PANEL_BASE_HEIGHT}px`,
|
|
3579
|
+
}, className: "font-sans", onMouseEnter: () => setIsMouseHoveringSettingsPanel(true), onMouseLeave: () => setIsMouseHoveringSettingsPanel(false) },
|
|
3405
3580
|
React.createElement("div", { className: "settings-panel-section" },
|
|
3406
3581
|
React.createElement("div", { className: "settings-panel-section-title" },
|
|
3407
3582
|
React.createElement("span", null, translations?.layersDisplay.context || 'Context')),
|
|
3408
3583
|
LAYERS_SELECTION.map((selection) => (React.createElement("div", { key: selection, className: "selection" },
|
|
3409
|
-
React.createElement(Checkbox, { label: translations?.layersDisplay[selection] || selection, checked: store.layersDisplay[selection], disabled: !isLayerActive(store, selection), onChange: () => {
|
|
3584
|
+
React.createElement(Checkbox, { "data-testid": testIdPrefix ? `${testIdPrefix}-layer-${selection}` : undefined, label: translations?.layersDisplay[selection] || selection, checked: store.layersDisplay[selection], disabled: !isLayerActive(store, selection), onChange: () => {
|
|
3410
3585
|
setStore((prev) => ({
|
|
3411
3586
|
...prev,
|
|
3412
3587
|
layersDisplay: {
|
|
@@ -3414,6 +3589,11 @@ const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoverin
|
|
|
3414
3589
|
[selection]: !prev.layersDisplay[selection],
|
|
3415
3590
|
},
|
|
3416
3591
|
}));
|
|
3592
|
+
if (selection === 'electricalProfiles' ||
|
|
3593
|
+
selection === 'powerRestrictions' ||
|
|
3594
|
+
selection === 'speedLimitTags') {
|
|
3595
|
+
adjustHeightOnLayerChange(selection, store.layersDisplay[selection]);
|
|
3596
|
+
}
|
|
3417
3597
|
} }))))),
|
|
3418
3598
|
React.createElement("div", { className: "settings-panel-section right" },
|
|
3419
3599
|
React.createElement("div", { className: "settings-panel-section-title" },
|
|
@@ -3428,7 +3608,7 @@ const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoverin
|
|
|
3428
3608
|
},
|
|
3429
3609
|
}));
|
|
3430
3610
|
} }))))),
|
|
3431
|
-
React.createElement("button", { id: "close-settings-panel", onClick: () => closeSettingsPanel() },
|
|
3611
|
+
React.createElement("button", { id: "close-settings-panel", "data-testid": testIdPrefix ? `${testIdPrefix}-close` : undefined, onClick: () => closeSettingsPanel() },
|
|
3432
3612
|
React.createElement("span", null,
|
|
3433
3613
|
React.createElement(X, null)))));
|
|
3434
3614
|
};
|
|
@@ -3456,6 +3636,12 @@ const zoom = (setStore) => d3zoom
|
|
|
3456
3636
|
canvas.call(resetZoom);
|
|
3457
3637
|
}
|
|
3458
3638
|
});
|
|
3639
|
+
const computeLeftOffsetOnZoom = (value) => {
|
|
3640
|
+
const canvas = d3selection.select(FRONT_INTERACTIVITY_LAYER_ID);
|
|
3641
|
+
const transform = d3zoom.zoomIdentity.scale(value);
|
|
3642
|
+
d3zoom.zoom().transform(canvas, transform);
|
|
3643
|
+
return transform.x;
|
|
3644
|
+
};
|
|
3459
3645
|
|
|
3460
3646
|
const { MARGIN_LEFT: MARGIN_LEFT$6, MARGIN_RIGHT: MARGIN_RIGHT$5, MARGIN_TOP: MARGIN_TOP$5, MARGIN_BOTTOM: MARGIN_BOTTOM$6 } = MARGINS;
|
|
3461
3647
|
const STEP_HEIGHT = 6;
|
|
@@ -4051,8 +4237,7 @@ const drawCursor = ({ ctx, width, height, store }) => {
|
|
|
4051
4237
|
let reticleY = 0;
|
|
4052
4238
|
const maxSpeed = maxSpeedValue(store);
|
|
4053
4239
|
const maxPosition = maxPositionValue(store.speeds);
|
|
4054
|
-
const
|
|
4055
|
-
const cursorBoxHeight = heightWithoutLayers - MARGIN_BOTTOM$3 - MARGIN_TOP$2;
|
|
4240
|
+
const cursorBoxHeight = height - MARGIN_BOTTOM$3 - MARGIN_TOP$2;
|
|
4056
4241
|
const cursorBoxWidth = width - MARGIN_LEFT$3 - MARGIN_RIGHT$2;
|
|
4057
4242
|
const xPositionReference = (ref) => ref * ((cursorBoxWidth - CURVE_MARGIN_SIDES$1) / maxPosition) * ratioX +
|
|
4058
4243
|
leftOffset +
|
|
@@ -4210,15 +4395,14 @@ const drawCursor = ({ ctx, width, height, store }) => {
|
|
|
4210
4395
|
};
|
|
4211
4396
|
};
|
|
4212
4397
|
|
|
4213
|
-
const ReticleLayer = ({ width, height,
|
|
4398
|
+
const ReticleLayer = ({ width, internalHeight: height, store }) => {
|
|
4214
4399
|
const canvas = useRef(null);
|
|
4215
4400
|
const [trainDetails, setTrainDetails] = useState(null);
|
|
4216
|
-
const maxCursorHeight = getAdaptiveHeight(heightOffset, store.layersDisplay, false);
|
|
4217
4401
|
useEffect(() => {
|
|
4218
4402
|
const currentCanvas = canvas.current;
|
|
4219
4403
|
const ctx = currentCanvas.getContext('2d');
|
|
4220
4404
|
// The tooltip shouldn't be displayed when hovering on the linear layers
|
|
4221
|
-
if (store.cursor.y && store.cursor.y <
|
|
4405
|
+
if (store.cursor.y && store.cursor.y < height - MARGINS.MARGIN_TOP - MARGINS.MARGIN_BOTTOM) {
|
|
4222
4406
|
const detailsBox = drawCursor({ ctx, width, height, store });
|
|
4223
4407
|
setTrainDetails(detailsBox || null);
|
|
4224
4408
|
}
|
|
@@ -4226,7 +4410,7 @@ const ReticleLayer = ({ width, height, heightOffset, store }) => {
|
|
|
4226
4410
|
clearCanvas(ctx, width, height);
|
|
4227
4411
|
setTrainDetails(null);
|
|
4228
4412
|
}
|
|
4229
|
-
}, [width, height, store
|
|
4413
|
+
}, [width, height, store]);
|
|
4230
4414
|
return (React.createElement(React.Fragment, null,
|
|
4231
4415
|
React.createElement("canvas", { id: "cursor-layer", className: "absolute", ref: canvas, width: width, height: height }),
|
|
4232
4416
|
trainDetails && React.createElement(DetailsBox, { width: width, height: height, store: store, ...trainDetails })));
|
|
@@ -4361,7 +4545,7 @@ const TOOLTIP_HEIGHT = 40;
|
|
|
4361
4545
|
const MARGIN_ADJUSTMENT = 2;
|
|
4362
4546
|
const SpeedLimitTagsLayer = ({ width, marginTop, store }) => {
|
|
4363
4547
|
const canvas = useRef(null);
|
|
4364
|
-
const tooltip = useRef();
|
|
4548
|
+
const tooltip = useRef(null);
|
|
4365
4549
|
const [images, setImages] = useState({ questionImage: null, alertFillImage: null });
|
|
4366
4550
|
useEffect(() => {
|
|
4367
4551
|
const fetchImages = async () => {
|
|
@@ -4677,9 +4861,37 @@ const SpeedSpaceChart = ({ width, height, backgroundColor, data, setHeight, tran
|
|
|
4677
4861
|
},
|
|
4678
4862
|
isSettingsPanelOpened: false,
|
|
4679
4863
|
});
|
|
4680
|
-
const {
|
|
4681
|
-
|
|
4682
|
-
|
|
4864
|
+
const { mainChartHeight, powerRestrictionsTop, speedLimitTagsTop, electricalProfileLayerHeight, interactivityLayerHeight, } = useMemo(() => {
|
|
4865
|
+
const _electricalProfilesOffset = store.layersDisplay.electricalProfiles
|
|
4866
|
+
? LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT
|
|
4867
|
+
: 0;
|
|
4868
|
+
const _powerRestrictionsOffset = store.layersDisplay.powerRestrictions
|
|
4869
|
+
? LINEAR_LAYERS_HEIGHTS.POWER_RESTRICTIONS_HEIGHT
|
|
4870
|
+
: 0;
|
|
4871
|
+
const _speedLimitTagsOffset = store.layersDisplay.speedLimitTags
|
|
4872
|
+
? LINEAR_LAYERS_HEIGHTS.SPEED_LIMIT_TAGS_HEIGHT
|
|
4873
|
+
: 0;
|
|
4874
|
+
// Height of the speedSpaceChart only (without the linear layers below) + top and bottom margins
|
|
4875
|
+
// TODO: remove the top and bottom margins from _mainChartHeight
|
|
4876
|
+
const _mainChartHeight = height - (_electricalProfilesOffset + _powerRestrictionsOffset + _speedLimitTagsOffset);
|
|
4877
|
+
const _baseLayerPosition = _mainChartHeight - MARGINS.MARGIN_BOTTOM;
|
|
4878
|
+
const _powerRestrictionsTop = _baseLayerPosition + _electricalProfilesOffset;
|
|
4879
|
+
const _speedLimitTagsTop = _powerRestrictionsTop + _powerRestrictionsOffset;
|
|
4880
|
+
const _interactivityLayerHeight = _mainChartHeight -
|
|
4881
|
+
MARGINS.MARGIN_BOTTOM -
|
|
4882
|
+
MARGINS.MARGIN_TOP +
|
|
4883
|
+
_electricalProfilesOffset +
|
|
4884
|
+
_powerRestrictionsOffset +
|
|
4885
|
+
_speedLimitTagsOffset;
|
|
4886
|
+
return {
|
|
4887
|
+
mainChartHeight: _mainChartHeight,
|
|
4888
|
+
powerRestrictionsTop: _powerRestrictionsTop,
|
|
4889
|
+
speedLimitTagsTop: _speedLimitTagsTop,
|
|
4890
|
+
electricalProfileLayerHeight: _mainChartHeight + LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT,
|
|
4891
|
+
interactivityLayerHeight: _interactivityLayerHeight,
|
|
4892
|
+
};
|
|
4893
|
+
}, [height, store.layersDisplay]);
|
|
4894
|
+
const { WIDTH_OFFSET, HEIGHT_OFFSET } = getGraphOffsets(width, mainChartHeight, store.layersDisplay.declivities);
|
|
4683
4895
|
const { OFFSET_RIGHT_AXIS } = MARGINS;
|
|
4684
4896
|
const adjustedWidthRightAxis = store.layersDisplay.declivities
|
|
4685
4897
|
? width - OFFSET_RIGHT_AXIS
|
|
@@ -4699,36 +4911,56 @@ const SpeedSpaceChart = ({ width, height, backgroundColor, data, setHeight, tran
|
|
|
4699
4911
|
isSettingsPanelOpened: true,
|
|
4700
4912
|
}));
|
|
4701
4913
|
};
|
|
4914
|
+
const adjustHeightOnLayerChange = useCallback((layerName, isCurrentlyActive) => {
|
|
4915
|
+
let adjustment;
|
|
4916
|
+
if (layerName === 'electricalProfiles') {
|
|
4917
|
+
adjustment = LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT;
|
|
4918
|
+
}
|
|
4919
|
+
else if (layerName === 'powerRestrictions') {
|
|
4920
|
+
adjustment = LINEAR_LAYERS_HEIGHTS.POWER_RESTRICTIONS_HEIGHT;
|
|
4921
|
+
}
|
|
4922
|
+
else {
|
|
4923
|
+
adjustment = LINEAR_LAYERS_HEIGHTS.SPEED_LIMIT_TAGS_HEIGHT;
|
|
4924
|
+
}
|
|
4925
|
+
setHeight((prevHeight) => prevHeight + (isCurrentlyActive ? -adjustment : adjustment));
|
|
4926
|
+
}, [setHeight]);
|
|
4702
4927
|
useEffect(() => {
|
|
4703
4928
|
setStore((prev) => ({
|
|
4704
4929
|
...prev,
|
|
4705
4930
|
...data,
|
|
4706
4931
|
}));
|
|
4707
4932
|
}, [data]);
|
|
4708
|
-
useEffect(() => {
|
|
4709
|
-
setHeight(dynamicHeight);
|
|
4710
|
-
}, [setHeight, dynamicHeight]);
|
|
4711
4933
|
return (React.createElement("div", { style: {
|
|
4712
4934
|
width: `${width}px`,
|
|
4713
|
-
height: `${
|
|
4935
|
+
height: `${height}px`,
|
|
4714
4936
|
backgroundColor: `${backgroundColor}`,
|
|
4937
|
+
position: 'relative',
|
|
4715
4938
|
}, tabIndex: 0 },
|
|
4939
|
+
React.createElement("div", { className: "speed-space-slider-container" },
|
|
4940
|
+
React.createElement(Slider, { className: "speed-space-slider", width: ZOOM_CONFIG.SLIDER_WIDTH, min: Math.log(ZOOM_CONFIG.MIN_RATIO) / Math.log(1.1), max: Math.log(ZOOM_CONFIG.MAX_RATIO) / Math.log(1.1), value: Math.log(store.ratioX) / Math.log(1.1), onChange: (e) => {
|
|
4941
|
+
const value = clamp(Math.pow(1.1, Number(e.target.value)), ZOOM_CONFIG.MIN_RATIO, ZOOM_CONFIG.MAX_RATIO);
|
|
4942
|
+
setStore((prev) => ({
|
|
4943
|
+
...prev,
|
|
4944
|
+
ratioX: value,
|
|
4945
|
+
leftOffset: computeLeftOffsetOnZoom(value),
|
|
4946
|
+
}));
|
|
4947
|
+
} })),
|
|
4716
4948
|
React.createElement("div", { className: "flex justify-end absolute base-margin-top", style: { width: adjustedWidthRightAxis } },
|
|
4717
|
-
React.createElement(InteractionButtons, { reset: reset, openSettingsPanel: openSettingsPanel, store: store })),
|
|
4949
|
+
React.createElement(InteractionButtons, { reset: reset, openSettingsPanel: openSettingsPanel, store: store, testIdPrefix: "interaction" })),
|
|
4718
4950
|
store.isSettingsPanelOpened && (React.createElement("div", { className: "flex justify-end absolute ml-2 base-margin-top", style: { width: adjustedWidthRightAxis } },
|
|
4719
|
-
React.createElement(SettingsPanel, {
|
|
4951
|
+
React.createElement(SettingsPanel, { color: backgroundColor, store: store, setStore: setStore, setIsMouseHoveringSettingsPanel: setIsMouseHoveringSettingsPanel, translations: translations, testIdPrefix: "settings-panel", adjustHeightOnLayerChange: adjustHeightOnLayerChange }))),
|
|
4720
4952
|
store.layersDisplay.declivities && (React.createElement(DeclivityLayer, { width: WIDTH_OFFSET, height: HEIGHT_OFFSET, store: store })),
|
|
4721
4953
|
React.createElement(CurveLayer, { width: WIDTH_OFFSET, height: HEIGHT_OFFSET, store: store }),
|
|
4722
|
-
store.layersDisplay.speedLimits && (React.createElement(SpeedLimitsLayer, { width: adjustedWidthRightAxis, height:
|
|
4723
|
-
store.layersDisplay.steps && (React.createElement(StepsLayer, { width: adjustedWidthRightAxis, height:
|
|
4724
|
-
React.createElement(AxisLayerY, { width: width, height:
|
|
4725
|
-
store.layersDisplay.electricalProfiles && (React.createElement(ElectricalProfileLayer, { width: adjustedWidthRightAxis, height:
|
|
4726
|
-
store.layersDisplay.powerRestrictions && (React.createElement(PowerRestrictionsLayer, { width: adjustedWidthRightAxis, marginTop:
|
|
4727
|
-
store.layersDisplay.speedLimitTags && (React.createElement(SpeedLimitTagsLayer, { width: adjustedWidthRightAxis, marginTop:
|
|
4728
|
-
React.createElement(TickLayerX, { width: adjustedWidthRightAxis, height:
|
|
4729
|
-
store.layersDisplay.declivities && (React.createElement(TickLayerYRight, { width: width, height:
|
|
4730
|
-
!isMouseHoveringSettingsPanel && (React.createElement(ReticleLayer, { width: adjustedWidthRightAxis,
|
|
4731
|
-
React.createElement(FrontInteractivityLayer, { width: WIDTH_OFFSET, height:
|
|
4954
|
+
store.layersDisplay.speedLimits && (React.createElement(SpeedLimitsLayer, { width: adjustedWidthRightAxis, height: mainChartHeight, store: store })),
|
|
4955
|
+
store.layersDisplay.steps && (React.createElement(StepsLayer, { width: adjustedWidthRightAxis, height: mainChartHeight, store: store })),
|
|
4956
|
+
React.createElement(AxisLayerY, { width: width, height: mainChartHeight, store: store }),
|
|
4957
|
+
store.layersDisplay.electricalProfiles && (React.createElement(ElectricalProfileLayer, { width: adjustedWidthRightAxis, height: electricalProfileLayerHeight, store: store })),
|
|
4958
|
+
store.layersDisplay.powerRestrictions && (React.createElement(PowerRestrictionsLayer, { width: adjustedWidthRightAxis, marginTop: powerRestrictionsTop, store: store })),
|
|
4959
|
+
store.layersDisplay.speedLimitTags && (React.createElement(SpeedLimitTagsLayer, { width: adjustedWidthRightAxis, marginTop: speedLimitTagsTop, store: store })),
|
|
4960
|
+
React.createElement(TickLayerX, { width: adjustedWidthRightAxis, height: height, store: store }),
|
|
4961
|
+
store.layersDisplay.declivities && (React.createElement(TickLayerYRight, { width: width, height: mainChartHeight, store: store })),
|
|
4962
|
+
!isMouseHoveringSettingsPanel && (React.createElement(ReticleLayer, { width: adjustedWidthRightAxis, internalHeight: mainChartHeight, store: store })),
|
|
4963
|
+
React.createElement(FrontInteractivityLayer, { width: WIDTH_OFFSET, height: interactivityLayerHeight, store: store, setStore: setStore })));
|
|
4732
4964
|
};
|
|
4733
4965
|
|
|
4734
4966
|
const TRACK_HEIGHT_CONTAINER = 100;
|
|
@@ -4846,7 +5078,7 @@ const drawOccupancyZonesTexts = ({ ctx, zone, arrivalTimePixel, departureTimePix
|
|
|
4846
5078
|
ctx.font = '400 10px IBM Plex Mono';
|
|
4847
5079
|
const originTextLength = ctx.measureText(zone.originStation || '--').width;
|
|
4848
5080
|
ctx.font = '400 12px IBM Plex Mono';
|
|
4849
|
-
const nameTextLength = ctx.measureText(zone.
|
|
5081
|
+
const nameTextLength = ctx.measureText(zone.trainName).width;
|
|
4850
5082
|
const { xOriginTrainName, yOriginTrainName } = isBelowBreakpoint('medium')
|
|
4851
5083
|
? {
|
|
4852
5084
|
xOriginTrainName: arrivalTimePixel -
|
|
@@ -4887,7 +5119,7 @@ const drawOccupancyZonesTexts = ({ ctx, zone, arrivalTimePixel, departureTimePix
|
|
|
4887
5119
|
}
|
|
4888
5120
|
drawText({
|
|
4889
5121
|
ctx,
|
|
4890
|
-
text: zone.
|
|
5122
|
+
text: zone.trainName,
|
|
4891
5123
|
x: xOriginTrainName,
|
|
4892
5124
|
y: yOriginTrainName,
|
|
4893
5125
|
color: GREY_50,
|
|
@@ -4900,7 +5132,7 @@ const drawOccupancyZonesTexts = ({ ctx, zone, arrivalTimePixel, departureTimePix
|
|
|
4900
5132
|
// arrival minutes & departure minutes
|
|
4901
5133
|
drawText({
|
|
4902
5134
|
ctx,
|
|
4903
|
-
text: new Date(zone.
|
|
5135
|
+
text: new Date(zone.startTime)
|
|
4904
5136
|
.getMinutes()
|
|
4905
5137
|
.toLocaleString('fr-FR', { minimumIntegerDigits: 2 }),
|
|
4906
5138
|
x: isThroughTrain ? arrivalTimePixel - X_THROUGHTRAIN_OFFSET : arrivalTimePixel,
|
|
@@ -4914,7 +5146,7 @@ const drawOccupancyZonesTexts = ({ ctx, zone, arrivalTimePixel, departureTimePix
|
|
|
4914
5146
|
if (!isThroughTrain)
|
|
4915
5147
|
drawText({
|
|
4916
5148
|
ctx,
|
|
4917
|
-
text: new Date(zone.
|
|
5149
|
+
text: new Date(zone.endTime)
|
|
4918
5150
|
.getMinutes()
|
|
4919
5151
|
.toLocaleString('fr-FR', { minimumIntegerDigits: 2 }),
|
|
4920
5152
|
x: departureTimePixel,
|
|
@@ -4959,6 +5191,7 @@ const X_BACKGROUND_PADDING = 4;
|
|
|
4959
5191
|
const X_TROUGHTRAIN_BACKGROUND_PADDING = 8;
|
|
4960
5192
|
const BACKGROUND_HEIGHT = 40;
|
|
4961
5193
|
const SELECTED_TRAIN_ID_GRADIANT = 2;
|
|
5194
|
+
const PATH_SIZE_DEFAULT = 1;
|
|
4962
5195
|
const drawDefaultZone = (ctx, { x, y, width }) => {
|
|
4963
5196
|
ctx.beginPath();
|
|
4964
5197
|
ctx.rect(x, y, width, OCCUPANCY_ZONE_HEIGHT);
|
|
@@ -5008,8 +5241,10 @@ const drawRemainingTrainsBox = (ctx, { getTimePixel, getSpacePixel }, { time, po
|
|
|
5008
5241
|
ctx.fillText(`+${remainingTrainsNb} trains`, x, textY + REMAINING_TRAINS_HEIGHT / 2);
|
|
5009
5242
|
};
|
|
5010
5243
|
const drawOccupationZone = (ctx, stcContext, { zone, yOffset, position, isSelected, }) => {
|
|
5011
|
-
const
|
|
5012
|
-
|
|
5244
|
+
const size = zone.size || PATH_SIZE_DEFAULT;
|
|
5245
|
+
const color = zone.color || PATH_COLOR_DEFAULT;
|
|
5246
|
+
const isThroughTrain = zone.startTime === zone.endTime;
|
|
5247
|
+
ctx.fillStyle = color;
|
|
5013
5248
|
ctx.strokeStyle = WHITE_100$1;
|
|
5014
5249
|
ctx.lineJoin = 'round';
|
|
5015
5250
|
ctx.lineCap = 'round';
|
|
@@ -5018,8 +5253,8 @@ const drawOccupationZone = (ctx, stcContext, { zone, yOffset, position, isSelect
|
|
|
5018
5253
|
const yStart = getCrispLineCoordinate(getSpacePixel(position), BACKGROUND_HEIGHT);
|
|
5019
5254
|
const y = yStart + yOffset;
|
|
5020
5255
|
const yEnd = getSpacePixel(position, true);
|
|
5021
|
-
const arrivalTimePixel = getTimePixel(zone.
|
|
5022
|
-
const departureTimePixel = getTimePixel(zone.
|
|
5256
|
+
const arrivalTimePixel = getTimePixel(zone.startTime);
|
|
5257
|
+
const departureTimePixel = getTimePixel(zone.endTime);
|
|
5023
5258
|
if (isSelected) {
|
|
5024
5259
|
const extraWidth = isThroughTrain ? X_TROUGHTRAIN_BACKGROUND_PADDING : X_BACKGROUND_PADDING;
|
|
5025
5260
|
const originTextLength = ctx.measureText(zone.originStation || '--').width;
|
|
@@ -5033,7 +5268,7 @@ const drawOccupationZone = (ctx, stcContext, { zone, yOffset, position, isSelect
|
|
|
5033
5268
|
extraWidth * 2, BACKGROUND_HEIGHT, SELECTED_TRAIN_ID_GRADIANT);
|
|
5034
5269
|
ctx.fill();
|
|
5035
5270
|
}
|
|
5036
|
-
ctx.fillStyle =
|
|
5271
|
+
ctx.fillStyle = color;
|
|
5037
5272
|
if (isThroughTrain) {
|
|
5038
5273
|
drawThroughTrain(ctx, arrivalTimePixel, y);
|
|
5039
5274
|
}
|
|
@@ -5045,19 +5280,19 @@ const drawOccupationZone = (ctx, stcContext, { zone, yOffset, position, isSelect
|
|
|
5045
5280
|
});
|
|
5046
5281
|
}
|
|
5047
5282
|
// Draw dashed lines linking trains tracks occupancy to their paths on the SpaceTimeChart (when relevant):
|
|
5048
|
-
ctx.strokeStyle =
|
|
5049
|
-
ctx.lineWidth =
|
|
5283
|
+
ctx.strokeStyle = color;
|
|
5284
|
+
ctx.lineWidth = size;
|
|
5050
5285
|
ctx.setLineDash([1, 4]);
|
|
5051
|
-
if (zone.
|
|
5286
|
+
if (zone.startDirection) {
|
|
5052
5287
|
ctx.beginPath();
|
|
5053
5288
|
ctx.moveTo(arrivalTimePixel, y);
|
|
5054
|
-
ctx.lineTo(arrivalTimePixel, zone.
|
|
5289
|
+
ctx.lineTo(arrivalTimePixel, zone.startDirection === 'up' ? yStart : yEnd);
|
|
5055
5290
|
ctx.stroke();
|
|
5056
5291
|
}
|
|
5057
|
-
if (zone.
|
|
5292
|
+
if (zone.endDirection) {
|
|
5058
5293
|
ctx.beginPath();
|
|
5059
5294
|
ctx.moveTo(departureTimePixel, y);
|
|
5060
|
-
ctx.lineTo(departureTimePixel, zone.
|
|
5295
|
+
ctx.lineTo(departureTimePixel, zone.endDirection === 'up' ? yStart : yEnd);
|
|
5061
5296
|
ctx.stroke();
|
|
5062
5297
|
}
|
|
5063
5298
|
ctx.setLineDash([]);
|
|
@@ -5075,24 +5310,27 @@ const drawOccupationZone = (ctx, stcContext, { zone, yOffset, position, isSelect
|
|
|
5075
5310
|
|
|
5076
5311
|
const Y_OFFSET_INCREMENT = 4;
|
|
5077
5312
|
const MAX_ZONES = 9;
|
|
5313
|
+
function isOccupancyPickingElement(element) {
|
|
5314
|
+
return element.type === 'occupancyZone';
|
|
5315
|
+
}
|
|
5078
5316
|
const OccupancyZonesLayer = ({ tracks, occupancyZones, position, topPadding, selectedTrainId, }) => {
|
|
5079
5317
|
const instructionsToDraw = useMemo(() => {
|
|
5080
5318
|
const instructions = [];
|
|
5081
5319
|
if (!tracks || !occupancyZones || occupancyZones.length === 0)
|
|
5082
5320
|
return instructions;
|
|
5083
|
-
const sortedOccupancyZones = occupancyZones.sort((a, b) => a.
|
|
5321
|
+
const sortedOccupancyZones = occupancyZones.sort((a, b) => a.startTime - b.startTime);
|
|
5084
5322
|
tracks.forEach((track, index) => {
|
|
5085
5323
|
const trackY = topPadding + CANVAS_PADDING + index * TRACK_HEIGHT_CONTAINER;
|
|
5086
5324
|
const filteredOccupancyZones = sortedOccupancyZones.filter((zone) => zone.trackId === track.id);
|
|
5087
|
-
let
|
|
5088
|
-
let
|
|
5325
|
+
let primaryStartTime = 0;
|
|
5326
|
+
let lastEndTime = 0;
|
|
5089
5327
|
let yPosition = OCCUPANCY_ZONE_Y_START;
|
|
5090
5328
|
let yOffset = Y_OFFSET_INCREMENT;
|
|
5091
5329
|
let zoneCounter = 0;
|
|
5092
5330
|
let zoneIndex = 0;
|
|
5093
5331
|
while (zoneIndex < filteredOccupancyZones.length) {
|
|
5094
5332
|
const zone = filteredOccupancyZones[zoneIndex];
|
|
5095
|
-
const {
|
|
5333
|
+
const { startTime, endTime } = zone;
|
|
5096
5334
|
// * if the zone is not overlapping with any previous one, draw it in the center of the track
|
|
5097
5335
|
// * and reset the primary values
|
|
5098
5336
|
// *
|
|
@@ -5102,11 +5340,11 @@ const OccupancyZonesLayer = ({ tracks, occupancyZones, position, topPadding, sel
|
|
|
5102
5340
|
// * if the zone is overlapping with the previous one and the counter is higher than the max zones
|
|
5103
5341
|
// * draw the remaining trains box
|
|
5104
5342
|
// *
|
|
5105
|
-
if (
|
|
5343
|
+
if (startTime > lastEndTime) {
|
|
5106
5344
|
// reset to initial value if the zone is not overlapping
|
|
5107
5345
|
yPosition = OCCUPANCY_ZONE_Y_START;
|
|
5108
|
-
|
|
5109
|
-
|
|
5346
|
+
primaryStartTime = startTime;
|
|
5347
|
+
lastEndTime = endTime;
|
|
5110
5348
|
yOffset = Y_OFFSET_INCREMENT;
|
|
5111
5349
|
zoneCounter = 1;
|
|
5112
5350
|
instructions.push({
|
|
@@ -5119,7 +5357,7 @@ const OccupancyZonesLayer = ({ tracks, occupancyZones, position, topPadding, sel
|
|
|
5119
5357
|
}
|
|
5120
5358
|
// if so and it's an even index, move it to the bottom, if it's an odd index, move it to the top
|
|
5121
5359
|
else if (zoneCounter < MAX_ZONES) {
|
|
5122
|
-
if (
|
|
5360
|
+
if (startTime >= primaryStartTime) {
|
|
5123
5361
|
if (zoneCounter % 2 === 0) {
|
|
5124
5362
|
yPosition -= yOffset;
|
|
5125
5363
|
}
|
|
@@ -5128,8 +5366,8 @@ const OccupancyZonesLayer = ({ tracks, occupancyZones, position, topPadding, sel
|
|
|
5128
5366
|
}
|
|
5129
5367
|
}
|
|
5130
5368
|
// update the last departure time if the current zone is longer
|
|
5131
|
-
if (
|
|
5132
|
-
|
|
5369
|
+
if (endTime >= lastEndTime)
|
|
5370
|
+
lastEndTime = endTime;
|
|
5133
5371
|
instructions.push({
|
|
5134
5372
|
type: 'occupancyZone',
|
|
5135
5373
|
zone,
|
|
@@ -5142,12 +5380,12 @@ const OccupancyZonesLayer = ({ tracks, occupancyZones, position, topPadding, sel
|
|
|
5142
5380
|
}
|
|
5143
5381
|
// else, if there are too much trains:
|
|
5144
5382
|
else {
|
|
5145
|
-
const nextIndex = filteredOccupancyZones.findIndex((filteredZone, i) => i > zoneIndex && filteredZone.
|
|
5383
|
+
const nextIndex = filteredOccupancyZones.findIndex((filteredZone, i) => i > zoneIndex && filteredZone.startTime >= lastEndTime);
|
|
5146
5384
|
const remainingTrainsNb = nextIndex - zoneIndex;
|
|
5147
5385
|
instructions.push({
|
|
5148
5386
|
type: 'remainingTrains',
|
|
5149
5387
|
amount: remainingTrainsNb,
|
|
5150
|
-
time: (
|
|
5388
|
+
time: (startTime + endTime) / 2,
|
|
5151
5389
|
offsetY: trackY,
|
|
5152
5390
|
});
|
|
5153
5391
|
zoneIndex += remainingTrainsNb;
|
|
@@ -5180,20 +5418,31 @@ const OccupancyZonesLayer = ({ tracks, occupancyZones, position, topPadding, sel
|
|
|
5180
5418
|
}, [position, instructionsToDraw]);
|
|
5181
5419
|
const pickingFunction = useCallback((imageData, { registerPickingElement, getTimePixel, getSpacePixel }, scalingRatio) => {
|
|
5182
5420
|
const flatStepOffsetY = getSpacePixel(position);
|
|
5421
|
+
const flatStepEndY = getSpacePixel(position, true);
|
|
5183
5422
|
instructionsToDraw.forEach((instruction) => {
|
|
5184
5423
|
if (instruction.type === 'occupancyZone') {
|
|
5185
|
-
const x = getTimePixel(instruction.zone.
|
|
5424
|
+
const x = getTimePixel(instruction.zone.startTime);
|
|
5186
5425
|
const y = instruction.offsetY + flatStepOffsetY;
|
|
5187
|
-
const width = getTimePixel(instruction.zone.
|
|
5426
|
+
const width = getTimePixel(instruction.zone.endTime) - x;
|
|
5188
5427
|
const height = OCCUPANCY_ZONE_HEIGHT;
|
|
5189
5428
|
const margin = 6;
|
|
5190
5429
|
const pickingElement = {
|
|
5191
5430
|
type: 'occupancyZone',
|
|
5192
|
-
|
|
5431
|
+
pathId: instruction.zone.trainId,
|
|
5193
5432
|
};
|
|
5194
5433
|
const pickingIndex = registerPickingElement(pickingElement);
|
|
5195
5434
|
const color = hexToRgb(indexToColor(pickingIndex));
|
|
5196
5435
|
drawAliasedRect(imageData, { x: x - margin, y: y - margin }, width + 2 * margin, height + 2 * margin, color, scalingRatio);
|
|
5436
|
+
if (instruction.zone.startDirection) {
|
|
5437
|
+
const yStart = instruction.zone.startDirection === 'up' ? flatStepOffsetY : y;
|
|
5438
|
+
const yStop = instruction.zone.startDirection === 'up' ? y : flatStepEndY;
|
|
5439
|
+
drawAliasedRect(imageData, { x: x - margin, y: yStart - margin }, 2 * margin, yStop - yStart + 2 * margin, color, scalingRatio);
|
|
5440
|
+
}
|
|
5441
|
+
if (instruction.zone.endDirection) {
|
|
5442
|
+
const yStart = instruction.zone.endDirection === 'up' ? flatStepOffsetY : y;
|
|
5443
|
+
const yStop = instruction.zone.endDirection === 'up' ? y : flatStepEndY;
|
|
5444
|
+
drawAliasedRect(imageData, { x: x + width - margin, y: yStart - margin }, 2 * margin, yStop - yStart + 2 * margin, color, scalingRatio);
|
|
5445
|
+
}
|
|
5197
5446
|
}
|
|
5198
5447
|
});
|
|
5199
5448
|
}, [position, instructionsToDraw]);
|
|
@@ -5330,7 +5579,7 @@ const TrackOccupancyStandalone = ({ tracks, occupancyZones, selectedTrainId, onS
|
|
|
5330
5579
|
const manchetteWithSpaceTimeChartRef = useRef(null);
|
|
5331
5580
|
const spaceTimeChartRef = useRef(null);
|
|
5332
5581
|
const defaultTimeOrigin = useMemo(() => {
|
|
5333
|
-
const minTime = Math.min(...(occupancyZones.map((zone) => zone.
|
|
5582
|
+
const minTime = Math.min(...(occupancyZones.map((zone) => zone.startTime) || Date.now()));
|
|
5334
5583
|
// Take first round hour before minTime:
|
|
5335
5584
|
return Math.floor(minTime / HOUR) * HOUR;
|
|
5336
5585
|
}, [occupancyZones]);
|
|
@@ -5372,15 +5621,15 @@ const TrackOccupancyStandalone = ({ tracks, occupancyZones, selectedTrainId, onS
|
|
|
5372
5621
|
return (React.createElement("div", { className: "track-occupancy-standalone flex flex-col" },
|
|
5373
5622
|
React.createElement("div", { className: "bg-ambientB-5 flex flex-col justify-center main-container-header grow-0 shrink-0" },
|
|
5374
5623
|
React.createElement(KebabHorizontal, null)),
|
|
5375
|
-
React.createElement("div", { className: "manchette-space-time-chart-wrapper", style: { maxHeight: height } },
|
|
5624
|
+
React.createElement("div", { className: "ui-manchette-space-time-chart-wrapper", style: { maxHeight: height } },
|
|
5376
5625
|
React.createElement("div", { ref: manchetteWithSpaceTimeChartRef, className: "manchette flex h-100", onScroll: handleScroll, style: { height } },
|
|
5377
5626
|
React.createElement(Manchette, { ...manchetteProps }),
|
|
5378
5627
|
React.createElement("div", { className: "space-time-chart-container w-full sticky", ref: spaceTimeChartRef },
|
|
5379
5628
|
React.createElement(SpaceTimeChart, { className: "inset-0 absolute h-full", ...spaceTimeChartProps, onClick: onSelectedTrainIdChange &&
|
|
5380
5629
|
(({ hoveredItem }) => {
|
|
5381
5630
|
if (hoveredItem?.layer === 'overlay' &&
|
|
5382
|
-
hoveredItem.element
|
|
5383
|
-
const newId = hoveredItem.element.
|
|
5631
|
+
isOccupancyPickingElement(hoveredItem.element)) {
|
|
5632
|
+
const newId = hoveredItem.element.pathId;
|
|
5384
5633
|
onSelectedTrainIdChange(newId === selectedTrainId ? undefined : newId);
|
|
5385
5634
|
}
|
|
5386
5635
|
else {
|
|
@@ -5389,5 +5638,5 @@ const TrackOccupancyStandalone = ({ tracks, occupancyZones, selectedTrainId, onS
|
|
|
5389
5638
|
}) }))))));
|
|
5390
5639
|
};
|
|
5391
5640
|
|
|
5392
|
-
export { CANVAS_PADDING, COLORS, CanvasContext, ConflictLayer, ConflictTooltip, DEFAULT_LEVEL, DEFAULT_THEME, DEFAULT_ZOOM_MS_PER_PX, FONTS, MINUTES_TEXT_OFFSET, Manchette, ManchetteWithSpaceTimeChart, MouseContext, OCCUPANCY_ZONE_HEIGHT, OCCUPANCY_ZONE_Y_START, OccupancyBlockLayer, PathLayer, PatternRect, Quadrilateral, STATION_TEXT_OFFSET, SpaceTimeChart, SpaceTimeChartContext, SpeedSpaceChart, TICKS_PATTERN, TICKS_PRIORITIES, TRACK_HEIGHT_CONTAINER, TimeCaptions, Tooltip$1 as Tooltip, TrackOccupancyCanvas, TrackOccupancyManchette, TrackOccupancyStandalone, Waypoint as WaypointComponent, WorkScheduleLayer, ZoomRect, getCrispLineCoordinate, getSpaceAtTime, isConflictPickingElement, isInteractiveWaypoint, isPathOnScreen, isPointPickingElement, isSegmentPickingElement, positionKmToMm, positionMmToKm, timeScaleToZoomValue, useDraw, useManchetteWithSpaceTimeChart, usePaths, usePicking };
|
|
5641
|
+
export { BASE_WAYPOINT_HEIGHT, CANVAS_PADDING, COLORS, CanvasContext, ConflictLayer, ConflictTooltip, DEFAULT_LEVEL, DEFAULT_THEME, DEFAULT_ZOOM_MS_PER_PX, FONTS, MINUTES_TEXT_OFFSET, Manchette, ManchetteWithSpaceTimeChart, MouseContext, OCCUPANCY_ZONE_HEIGHT, OCCUPANCY_ZONE_Y_START, OccupancyBlockLayer, PathLayer, PatternRect, Quadrilateral, STATION_TEXT_OFFSET, SpaceTimeChart, SpaceTimeChartContext, SpeedSpaceChart, TICKS_PATTERN, TICKS_PRIORITIES, TRACK_HEIGHT_CONTAINER, TimeCaptions, Tooltip$1 as Tooltip, TrackOccupancyCanvas, TrackOccupancyManchette, TrackOccupancyStandalone, Waypoint as WaypointComponent, WorkScheduleLayer, ZoomRect, computeRectZoomOffsets, getCrispLineCoordinate, getSpaceAtTime, isConflictPickingElement, isInteractiveWaypoint, isOccupancyPickingElement, isPathOnScreen, isPointPickingElement, isQuadrilaterPickingElement, isSegmentPickingElement, positionKmToMm, positionMmToKm, timeScaleToZoomValue, useDraw, useManchetteWithSpaceTimeChart, usePaths, usePicking };
|
|
5393
5642
|
//# sourceMappingURL=index.esm.js.map
|