@osrd-project/ui-charts 0.0.78 → 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/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
- draw();
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.5, 1, 4, 16, 48, 72, Infinity],
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.6,
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.6,
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.6,
887
- dashArray: [2, 8],
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
- if (showTicks) {
977
- ctx.strokeStyle = timeCaptionsStyles[1].color;
978
- ctx.moveTo(timePixel, spaceAxisSize);
979
- ctx.lineTo(timePixel, time % 180000 === 0 ? 8 : 4);
980
- ctx.stroke();
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
- ctx.strokeText(text, timePixel, spaceAxisSize + (styles.topOffset || 0));
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 drawingFunction = useCallback((ctx, { timeScale, timeOrigin, timePixelOffset, spacePixelOffset, getTimePixel, swapAxis, width, height, theme: { breakpoints, timeRanges, timeGraduationsStyles, timeGraduationsPriorities }, }) => {
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 || 1;
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
  };
@@ -2061,6 +2173,21 @@ const SpaceTimeChart = (props) => {
2061
2173
  showTicks,
2062
2174
  hideDates,
2063
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
+ }, []);
2064
2191
  const contextState = useMemo(() => {
2065
2192
  const spaceScaleTree = spaceScalesToBinaryTree(spaceOrigin, spaceScales);
2066
2193
  const flatSteps = getFlatSteps(spaceScales);
@@ -2083,15 +2210,8 @@ const SpaceTimeChart = (props) => {
2083
2210
  const getTime = getPixelToTime(timeOrigin, timePixelOffset, timeScale);
2084
2211
  const getSpace = getPixelToSpace(spacePixelOffset, spaceScaleTree);
2085
2212
  const getData = getPointToData(getTime, getSpace, timeAxis, spaceAxis);
2086
- const pickingElements = [];
2087
- const resetPickingElements = () => {
2088
- pickingElements.length = 0;
2089
- };
2090
- const registerPickingElement = (element) => {
2091
- pickingElements.push(element);
2092
- return pickingElements.length - 1;
2093
- };
2094
2213
  return {
2214
+ ...pickingState,
2095
2215
  fingerprint,
2096
2216
  width,
2097
2217
  height,
@@ -2101,9 +2221,6 @@ const SpaceTimeChart = (props) => {
2101
2221
  getTime,
2102
2222
  getSpace,
2103
2223
  getData,
2104
- pickingElements,
2105
- resetPickingElements,
2106
- registerPickingElement,
2107
2224
  operationalPoints,
2108
2225
  spaceOrigin,
2109
2226
  spaceScaleTree,
@@ -2127,7 +2244,7 @@ const SpaceTimeChart = (props) => {
2127
2244
  : fullTheme.dateCaptionsSize + fullTheme.timeCaptionsSize,
2128
2245
  };
2129
2246
  // eslint-disable-next-line react-hooks/exhaustive-deps
2130
- }, [fingerprint]);
2247
+ }, [fingerprint, pickingState]);
2131
2248
  const mouseState = useMouseTracking(root);
2132
2249
  const { position, down, isHover } = mouseState;
2133
2250
  const { canvasContext, hoveredItem } = useCanvas$1(canvasesRoot, contextState, position);
@@ -2215,7 +2332,7 @@ const ConflictLayer = ({ conflicts }) => {
2215
2332
  return null;
2216
2333
  };
2217
2334
 
2218
- 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));
2219
2336
 
2220
2337
  const formatDistance = (meters) => {
2221
2338
  const km = meters / 1000;
@@ -2305,6 +2422,9 @@ const WorkScheduleLayer = ({ workSchedules, imageUrl }) => {
2305
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 }))));
2306
2423
  };
2307
2424
 
2425
+ function isQuadrilaterPickingElement(element) {
2426
+ return element.type === 'quadrilateral';
2427
+ }
2308
2428
  /**
2309
2429
  * Draws a quadrilateral in the space time chart
2310
2430
  * Position correspond to each point of the quadrilateral
@@ -2314,7 +2434,7 @@ const WorkScheduleLayer = ({ workSchedules, imageUrl }) => {
2314
2434
  * vertices[3] /________/ vertices[2]
2315
2435
  *
2316
2436
  */
2317
- const Quadrilateral = ({ vertices, style }) => {
2437
+ const Quadrilateral = ({ id, vertices, style }) => {
2318
2438
  const drawRegion = useCallback((ctx, { getSpacePixel, getTimePixel }) => {
2319
2439
  ctx.save();
2320
2440
  ctx.fillStyle = style.backgroundColor ?? 'lightblue';
@@ -2330,6 +2450,17 @@ const Quadrilateral = ({ vertices, style }) => {
2330
2450
  ctx.restore();
2331
2451
  }, [vertices, style]);
2332
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);
2333
2464
  return null;
2334
2465
  };
2335
2466
 
@@ -2429,6 +2560,7 @@ function isPathOnScreen(width, height, points) {
2429
2560
 
2430
2561
  const INITIAL_OP_LIST_HEIGHT = 521;
2431
2562
  const BASE_WAYPOINT_HEIGHT = 32;
2563
+ const INITIAL_SPACE_TIME_CHART_HEIGHT = INITIAL_OP_LIST_HEIGHT + 40;
2432
2564
  const MIN_ZOOM_MS_PER_PX = 600_000;
2433
2565
  const MAX_ZOOM_MS_PER_PX = 625;
2434
2566
  const DEFAULT_ZOOM_MS_PER_PX = 7_500;
@@ -2458,17 +2590,17 @@ function getDistance(a, b) {
2458
2590
  };
2459
2591
  }
2460
2592
 
2461
- 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', {
2462
2594
  'waypoint-active': isActive,
2463
2595
  'menu-active': isMenuActive,
2464
2596
  }), id: id, ref: waypointRef, onClick: () => {
2465
2597
  if (onClick && !isMenuActive)
2466
2598
  onClick(id);
2467
2599
  } },
2468
- React.createElement("div", { className: "waypoint-position justify-self-start text-end" }, positionMmToKm(position)),
2469
- 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),
2470
2602
  React.createElement("div", { className: "waypoint-separator" }),
2471
- 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),
2472
2604
  React.createElement("div", { className: "waypoint-separator" }),
2473
2605
  React.createElement("div", { className: "waypoint-type" }),
2474
2606
  React.createElement("div", { className: "waypoint-separator" })));
@@ -2571,24 +2703,24 @@ const getScales = (waypoints, { isProportional, yZoom, height }, minZoomMillimet
2571
2703
  };
2572
2704
  const isInteractiveWaypoint = (item) => item != null && typeof item === 'object' && 'id' in item && 'position' in item;
2573
2705
 
2574
- 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" },
2575
2707
  React.createElement("div", { className: "bg-white-100 border-r border-grey-30 relative", style: { minHeight: `${height}px` } },
2576
2708
  React.createElement("div", { className: "waypoints-list" },
2577
2709
  contents.map((content, index) => isInteractiveWaypoint(content) ? (React.createElement("div", { key: index, className: "waypoint-wrapper flex justify-start", style: content.styles },
2578
- 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))),
2579
2711
  children)),
2580
- React.createElement("div", { className: "manchette-actions" },
2712
+ React.createElement("div", { "data-testid": "manchette-actions", className: "manchette-actions" },
2581
2713
  React.createElement("div", { className: "zoom-buttons" },
2582
- 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 },
2583
2715
  React.createElement(ZoomOut, null)),
2584
- 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 },
2585
2717
  React.createElement(ZoomIn, null)),
2586
- 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")),
2587
2719
  React.createElement("div", { className: "flex items-center ml-auto text-sans font-semibold" },
2588
2720
  React.createElement("button", { disabled: !!activeWaypointId, className: "toggle-mode", onClick: toggleMode },
2589
2721
  React.createElement("div", { className: "flex flex-col items-end pr-2" },
2590
- React.createElement("span", { className: cx({ 'text-grey-30': !isProportional }) }, "Km"),
2591
- 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")))))));
2592
2724
 
2593
2725
  const DEFAULT_MANCHETTE_WITH_SPACE_TIME_CHART_OPTIONS = {
2594
2726
  displayTimeCaptions: true,
@@ -2596,7 +2728,7 @@ const DEFAULT_MANCHETTE_WITH_SPACE_TIME_CHART_OPTIONS = {
2596
2728
  enableSpacePan: true,
2597
2729
  enableTimeZoom: true,
2598
2730
  };
2599
- const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChartRef, height = 561, spaceTimeChartRef, defaultTimeOrigin = 0, defaultSpaceOrigin = 0, defaultXOffset = 0, verticalPadding = BASE_WAYPOINT_HEIGHT / 2, splitPoints = [], options = {}, }) => {
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 = {}, }) => {
2600
2732
  const { displayTimeCaptions, enableTimePan, enableSpacePan, enableTimeZoom } = useMemo(() => ({
2601
2733
  ...DEFAULT_MANCHETTE_WITH_SPACE_TIME_CHART_OPTIONS,
2602
2734
  ...options,
@@ -2618,7 +2750,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2618
2750
  waypointsChart: [],
2619
2751
  scales: [],
2620
2752
  });
2621
- const { xZoom, yZoom, timeOrigin, spaceOrigin, xOffset, yOffset, scrollTo, panning, zoomMode, rect, pixelRect, isProportional, } = state;
2753
+ const { xZoom, yZoom, timeOrigin, spaceOrigin, xOffset, yOffset, scrollTo, panning, zoomMode, rect, isProportional, } = state;
2622
2754
  /** used when we change the train dataset for example to center the chart on the new data */
2623
2755
  const setTimeOrigin = useCallback((newTimeOrigin) => {
2624
2756
  setState((prev) => ({ ...prev, timeOrigin: newTimeOrigin }));
@@ -2628,100 +2760,61 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2628
2760
  const drawingHeightWithoutBothPadding = canvasDrawingHeight - BASE_WAYPOINT_HEIGHT; // 489
2629
2761
  const totalDistance = calcTotalDistance(waypoints);
2630
2762
  const { minZoomMillimeterPerPx, maxZoomMillimeterPerPx } = getExtremaScales(drawingHeightWithoutTopPadding, drawingHeightWithoutBothPadding, totalDistance);
2631
- const handleRectangleZoom = useCallback(({ scales: { chosenTimeScale, chosenSpaceScale }, overrideState, }) => {
2632
- setState((prev) => {
2633
- if (prev.zoomMode || !prev.rect || !spaceTimeChartRef?.current) {
2634
- return prev;
2635
- }
2636
- const newTimeScale = clamp$1(chosenTimeScale, MAX_ZOOM_MS_PER_PX, MIN_ZOOM_MS_PER_PX);
2637
- const timeZoomValue = timeScaleToZoomValue(newTimeScale);
2638
- const newXOffset = sideOffset(timeOrigin, newTimeScale, prev.rect.timeStart, prev.rect.timeEnd, spaceTimeChartRef.current.clientWidth);
2639
- let newYZoom = yZoom;
2640
- let newYOffset = yOffset;
2641
- if (chosenSpaceScale) {
2642
- const newSpaceScale = clamp$1(chosenSpaceScale, maxZoomMillimeterPerPx, minZoomMillimeterPerPx);
2643
- // we don’t need to handle this case and compute an offset
2644
- // this condition happens when we draw a rectangle
2645
- // larger than the entire chart (minus padding)
2646
- // that would actually zoom OUT if it wasn’t clamped.
2647
- if (newSpaceScale !== minZoomMillimeterPerPx) {
2648
- newYZoom = spaceScaleToZoomValue(minZoomMillimeterPerPx, maxZoomMillimeterPerPx, newSpaceScale);
2649
- newYOffset = Math.abs(sideOffset(spaceOrigin, newSpaceScale, prev.rect.spaceStart, prev.rect.spaceEnd, height, verticalPadding));
2650
- }
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));
2651
2786
  }
2652
- return {
2653
- ...prev,
2654
- xZoom: timeZoomValue,
2655
- yZoom: newYZoom,
2656
- xOffset: newXOffset,
2657
- yOffset: newYOffset,
2658
- scrollTo: newYOffset,
2659
- ...overrideState,
2660
- };
2661
- });
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
+ };
2662
2810
  }, [
2663
- timeOrigin,
2664
- spaceOrigin,
2665
- minZoomMillimeterPerPx,
2811
+ spaceTimeChartRef,
2812
+ drawingHeightWithoutTopPadding,
2666
2813
  maxZoomMillimeterPerPx,
2667
- yOffset,
2668
- yZoom,
2814
+ minZoomMillimeterPerPx,
2669
2815
  height,
2670
- spaceTimeChartRef,
2671
2816
  verticalPadding,
2672
2817
  ]);
2673
- useEffect(() => {
2674
- if (rect && !zoomMode && spaceTimeChartRef?.current) {
2675
- const { timeStart, timeEnd, spaceStart, spaceEnd } = rect;
2676
- const timeRange = Math.abs(Number(timeEnd) - Number(timeStart)); // width of rect in ms
2677
- const spaceRange = Math.abs(spaceEnd - spaceStart); // height of rect in mm
2678
- const chosenTimeScale = timeRange / spaceTimeChartRef.current.clientWidth;
2679
- if (isProportional) {
2680
- const chosenSpaceScale = spaceRange / drawingHeightWithoutTopPadding;
2681
- handleRectangleZoom({
2682
- scales: { chosenTimeScale, chosenSpaceScale },
2683
- overrideState: { rect: null },
2684
- });
2685
- }
2686
- else if (pixelRect) {
2687
- const currentStopHeight = BASE_WAYPOINT_HEIGHT * yZoom;
2688
- const { yStart, yEnd } = pixelRect;
2689
- const numberOfStopsInRect = Math.abs(yEnd - yStart) / currentStopHeight;
2690
- let newStopHeight = drawingHeightWithoutTopPadding / numberOfStopsInRect;
2691
- // at maximum zoom, we want 3 stops displayed
2692
- const maxStopHeight = drawingHeightWithoutTopPadding / (2 + BASE_WAYPOINT_HEIGHT / newStopHeight);
2693
- newStopHeight = Math.min(newStopHeight, maxStopHeight);
2694
- const newYZoom = newStopHeight / BASE_WAYPOINT_HEIGHT;
2695
- const rectTop = yOffset + Math.min(yStart, yEnd) - WAYPOINT_LINE_HEIGHT;
2696
- const numberOfStopsBeforeRectTop = rectTop / currentStopHeight;
2697
- const newYOffset = numberOfStopsBeforeRectTop * newStopHeight;
2698
- handleRectangleZoom({
2699
- scales: {
2700
- chosenTimeScale,
2701
- },
2702
- overrideState: {
2703
- rect: null,
2704
- pixelRect: null,
2705
- yZoom: newYZoom,
2706
- yOffset: newYOffset,
2707
- scrollTo: newYOffset,
2708
- },
2709
- });
2710
- }
2711
- }
2712
- }, [
2713
- state.rect,
2714
- state.zoomMode,
2715
- handleRectangleZoom,
2716
- drawingHeightWithoutTopPadding,
2717
- isProportional,
2718
- pixelRect,
2719
- rect,
2720
- spaceTimeChartRef,
2721
- yOffset,
2722
- yZoom,
2723
- zoomMode,
2724
- ]);
2725
2818
  const zoomYIn = useCallback(() => {
2726
2819
  const maxZoom = isProportional
2727
2820
  ? MAX_ZOOM_Y
@@ -2983,6 +3076,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2983
3076
  if (!isPanning) {
2984
3077
  return {
2985
3078
  ...prev,
3079
+ ...(prev.zoomMode && prev.rect ? handleRectZoomEnd(prev) : {}),
2986
3080
  panning: null,
2987
3081
  zoomMode: false,
2988
3082
  };
@@ -3060,6 +3154,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
3060
3154
  yOffset,
3061
3155
  waypointsToDisplay,
3062
3156
  splitPoints,
3157
+ displayTimeCaptions,
3063
3158
  xZoom,
3064
3159
  xOffset,
3065
3160
  verticalPadding,
@@ -3074,13 +3169,13 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
3074
3169
  minZoomMillimeterPerPx,
3075
3170
  maxZoomMillimeterPerPx,
3076
3171
  setTimeOrigin,
3077
- displayTimeCaptions,
3078
3172
  isShiftPressed,
3079
3173
  panning,
3174
+ manchetteWithSpaceTimeChartRef,
3080
3175
  enableTimePan,
3081
3176
  enableSpacePan,
3177
+ handleRectZoomEnd,
3082
3178
  canvasDrawingHeight,
3083
- manchetteWithSpaceTimeChartRef,
3084
3179
  ]);
3085
3180
  };
3086
3181
 
@@ -3101,7 +3196,7 @@ const usePaths = (projectPathTrainResult) => useMemo(() => projectPathTrainResul
3101
3196
  * This only covers basic usage. For more advanced control over the manchette
3102
3197
  * and space time chart, the useManchetteWithSpaceTimeChart() hook can be used.
3103
3198
  */
3104
- const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height = 561, children, header, manchetteProps: additionalManchetteProps, spaceTimeChartProps: additionalSpaceTimeChartProps, splitPoints, }) => {
3199
+ const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height = INITIAL_SPACE_TIME_CHART_HEIGHT, children, header, manchetteProps: additionalManchetteProps, spaceTimeChartProps: additionalSpaceTimeChartProps, splitPoints, }) => {
3105
3200
  const manchetteWithSpaceTimeChartRef = useRef(null);
3106
3201
  const spaceTimeChartRef = useRef(null);
3107
3202
  const paths = usePaths(projectPathTrainResult);
@@ -3113,9 +3208,9 @@ const ManchetteWithSpaceTimeChart = ({ waypoints, projectPathTrainResult, height
3113
3208
  splitPoints,
3114
3209
  defaultTimeOrigin: Math.min(...projectPathTrainResult.map((p) => +p.departureTime)),
3115
3210
  });
3116
- return (React.createElement("div", { className: "manchette-space-time-chart-wrapper" },
3211
+ return (React.createElement("div", { className: "ui-manchette-space-time-chart-wrapper" },
3117
3212
  React.createElement("div", { className: "header bg-ambientB-5 w-full border-b border-grey-30", style: { height: '40px' } }, header),
3118
- React.createElement("div", { ref: manchetteWithSpaceTimeChartRef, className: "manchette flex", style: { height: `${height}px` }, onScroll: handleScroll },
3213
+ React.createElement("div", { ref: manchetteWithSpaceTimeChartRef, className: "manchette flex", onScroll: handleScroll },
3119
3214
  React.createElement(Manchette, { ...manchetteProps, ...additionalManchetteProps }),
3120
3215
  React.createElement("div", { className: "space-time-chart-container w-full sticky", ref: spaceTimeChartRef },
3121
3216
  React.createElement(SpaceTimeChart, { className: "inset-0 absolute h-full", ...spaceTimeChartProps, ...additionalSpaceTimeChartProps },
@@ -3161,9 +3256,6 @@ const LINEAR_LAYERS_HEIGHTS = {
3161
3256
  POWER_RESTRICTIONS_HEIGHT: 40,
3162
3257
  SPEED_LIMIT_TAGS_HEIGHT: 40,
3163
3258
  };
3164
- const LINEAR_LAYERS_HEIGHTS_BY_NAME = {
3165
- electricalProfiles: LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT,
3166
- powerRestrictions: LINEAR_LAYERS_HEIGHTS.POWER_RESTRICTIONS_HEIGHT};
3167
3259
  const LINEAR_LAYER_SEPARATOR_HEIGHT = 1;
3168
3260
  const LINEAR_LAYERS_BACKGROUND_COLOR = {
3169
3261
  FIRST: 'rgb(250, 249, 245)',
@@ -3205,6 +3297,11 @@ const COLOR_DICTIONARY = {
3205
3297
  '#EAA72B': '#EAA72B',
3206
3298
  '#94918E': '#94918E',
3207
3299
  };
3300
+ const ZOOM_CONFIG = {
3301
+ MIN_RATIO: 1,
3302
+ MAX_RATIO: 50,
3303
+ SLIDER_WIDTH: 100,
3304
+ };
3208
3305
 
3209
3306
  const getGraphOffsets = (width, height, declivities) => {
3210
3307
  const WIDTH_OFFSET = declivities ? width - 102 : width - 60; // +2px so that the tick appears on the right of the chart
@@ -3236,34 +3333,6 @@ const maxPositionValue = (speeds) => {
3236
3333
  const clearCanvas = (ctx, width, height) => {
3237
3334
  ctx.clearRect(0, 0, width, height);
3238
3335
  };
3239
- /**
3240
- * Calculates the adaptive height based on the height supplied and the lineaires displayed.
3241
- * @param height - The initial height value.
3242
- * @param layersDisplay - The linear display options.
3243
- * @param isIncludingLinearLayers - A flag to add or remove layers. Default is true.
3244
- * @returns The calculated adaptive height.
3245
- */
3246
- const getAdaptiveHeight = (height, layersDisplay, isIncludingLinearLayers = true) => {
3247
- const adjustment = [
3248
- layersDisplay.electricalProfiles ? LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT : 0,
3249
- layersDisplay.powerRestrictions ? LINEAR_LAYERS_HEIGHTS.POWER_RESTRICTIONS_HEIGHT : 0,
3250
- layersDisplay.speedLimitTags ? LINEAR_LAYERS_HEIGHTS.SPEED_LIMIT_TAGS_HEIGHT : 0,
3251
- ].reduce((acc, curr) => acc + curr, 0);
3252
- return (height += isIncludingLinearLayers ? adjustment : -adjustment);
3253
- };
3254
- /**
3255
- * Calculates the top position for the linear layers based on the height and the layers displayed.
3256
- * The speed limit tags linear layer needs to call this function with the isSpeedLimitByTag flag set to true.
3257
- */
3258
- const getLinearLayerMarginTop = (height, layersDisplay, isSpeedLimitByTag = false) => {
3259
- let adjustment = 0;
3260
- const { electricalProfiles, powerRestrictions } = layersDisplay;
3261
- if (electricalProfiles)
3262
- adjustment = LINEAR_LAYERS_HEIGHTS_BY_NAME.electricalProfiles;
3263
- if (powerRestrictions && isSpeedLimitByTag)
3264
- adjustment += LINEAR_LAYERS_HEIGHTS_BY_NAME.powerRestrictions;
3265
- return height + adjustment - MARGINS.MARGIN_BOTTOM;
3266
- };
3267
3336
  /**
3268
3337
  * Calculates the position on the graph scale based on the given parameters.
3269
3338
  * @param position - The current position.
@@ -3496,9 +3565,7 @@ const getSnappedStop = (cursorX, width, store) => {
3496
3565
  };
3497
3566
 
3498
3567
  const SETTINGS_PANEL_BASE_HEIGHT = 442;
3499
- const SPEEDSPACECHART_BASE_HEIGHT = 521.5;
3500
- const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoveringSettingsPanel, translations, testIdPrefix, }) => {
3501
- const [height, setHeight] = useState(`${SETTINGS_PANEL_BASE_HEIGHT}px`);
3568
+ const SettingsPanel = ({ color, store, setStore, setIsMouseHoveringSettingsPanel, adjustHeightOnLayerChange, translations, testIdPrefix, }) => {
3502
3569
  const closeSettingsPanel = () => {
3503
3570
  setIsMouseHoveringSettingsPanel(false);
3504
3571
  setStore((prev) => ({
@@ -3506,13 +3573,10 @@ const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoverin
3506
3573
  isSettingsPanelOpened: false,
3507
3574
  }));
3508
3575
  };
3509
- useEffect(() => {
3510
- const linearLayersHeight = getAdaptiveHeight(0, store.layersDisplay);
3511
- if (globalHeight < SPEEDSPACECHART_BASE_HEIGHT + linearLayersHeight) {
3512
- setHeight(`${globalHeight - linearLayersHeight - (SPEEDSPACECHART_BASE_HEIGHT - SETTINGS_PANEL_BASE_HEIGHT)}px`);
3513
- }
3514
- }, [globalHeight, store.layersDisplay]);
3515
- 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) },
3516
3580
  React.createElement("div", { className: "settings-panel-section" },
3517
3581
  React.createElement("div", { className: "settings-panel-section-title" },
3518
3582
  React.createElement("span", null, translations?.layersDisplay.context || 'Context')),
@@ -3525,6 +3589,11 @@ const SettingsPanel = ({ globalHeight, color, store, setStore, setIsMouseHoverin
3525
3589
  [selection]: !prev.layersDisplay[selection],
3526
3590
  },
3527
3591
  }));
3592
+ if (selection === 'electricalProfiles' ||
3593
+ selection === 'powerRestrictions' ||
3594
+ selection === 'speedLimitTags') {
3595
+ adjustHeightOnLayerChange(selection, store.layersDisplay[selection]);
3596
+ }
3528
3597
  } }))))),
3529
3598
  React.createElement("div", { className: "settings-panel-section right" },
3530
3599
  React.createElement("div", { className: "settings-panel-section-title" },
@@ -3567,6 +3636,12 @@ const zoom = (setStore) => d3zoom
3567
3636
  canvas.call(resetZoom);
3568
3637
  }
3569
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
+ };
3570
3645
 
3571
3646
  const { MARGIN_LEFT: MARGIN_LEFT$6, MARGIN_RIGHT: MARGIN_RIGHT$5, MARGIN_TOP: MARGIN_TOP$5, MARGIN_BOTTOM: MARGIN_BOTTOM$6 } = MARGINS;
3572
3647
  const STEP_HEIGHT = 6;
@@ -4162,8 +4237,7 @@ const drawCursor = ({ ctx, width, height, store }) => {
4162
4237
  let reticleY = 0;
4163
4238
  const maxSpeed = maxSpeedValue(store);
4164
4239
  const maxPosition = maxPositionValue(store.speeds);
4165
- const heightWithoutLayers = getAdaptiveHeight(height, layersDisplay, false);
4166
- const cursorBoxHeight = heightWithoutLayers - MARGIN_BOTTOM$3 - MARGIN_TOP$2;
4240
+ const cursorBoxHeight = height - MARGIN_BOTTOM$3 - MARGIN_TOP$2;
4167
4241
  const cursorBoxWidth = width - MARGIN_LEFT$3 - MARGIN_RIGHT$2;
4168
4242
  const xPositionReference = (ref) => ref * ((cursorBoxWidth - CURVE_MARGIN_SIDES$1) / maxPosition) * ratioX +
4169
4243
  leftOffset +
@@ -4321,15 +4395,14 @@ const drawCursor = ({ ctx, width, height, store }) => {
4321
4395
  };
4322
4396
  };
4323
4397
 
4324
- const ReticleLayer = ({ width, height, heightOffset, store }) => {
4398
+ const ReticleLayer = ({ width, internalHeight: height, store }) => {
4325
4399
  const canvas = useRef(null);
4326
4400
  const [trainDetails, setTrainDetails] = useState(null);
4327
- const maxCursorHeight = getAdaptiveHeight(heightOffset, store.layersDisplay, false);
4328
4401
  useEffect(() => {
4329
4402
  const currentCanvas = canvas.current;
4330
4403
  const ctx = currentCanvas.getContext('2d');
4331
4404
  // The tooltip shouldn't be displayed when hovering on the linear layers
4332
- if (store.cursor.y && store.cursor.y < maxCursorHeight) {
4405
+ if (store.cursor.y && store.cursor.y < height - MARGINS.MARGIN_TOP - MARGINS.MARGIN_BOTTOM) {
4333
4406
  const detailsBox = drawCursor({ ctx, width, height, store });
4334
4407
  setTrainDetails(detailsBox || null);
4335
4408
  }
@@ -4337,7 +4410,7 @@ const ReticleLayer = ({ width, height, heightOffset, store }) => {
4337
4410
  clearCanvas(ctx, width, height);
4338
4411
  setTrainDetails(null);
4339
4412
  }
4340
- }, [width, height, store, maxCursorHeight]);
4413
+ }, [width, height, store]);
4341
4414
  return (React.createElement(React.Fragment, null,
4342
4415
  React.createElement("canvas", { id: "cursor-layer", className: "absolute", ref: canvas, width: width, height: height }),
4343
4416
  trainDetails && React.createElement(DetailsBox, { width: width, height: height, store: store, ...trainDetails })));
@@ -4788,9 +4861,37 @@ const SpeedSpaceChart = ({ width, height, backgroundColor, data, setHeight, tran
4788
4861
  },
4789
4862
  isSettingsPanelOpened: false,
4790
4863
  });
4791
- const { WIDTH_OFFSET, HEIGHT_OFFSET } = getGraphOffsets(width, height, store.layersDisplay.declivities);
4792
- const dynamicHeight = getAdaptiveHeight(height, store.layersDisplay);
4793
- const dynamicHeightOffset = getAdaptiveHeight(HEIGHT_OFFSET, store.layersDisplay);
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);
4794
4895
  const { OFFSET_RIGHT_AXIS } = MARGINS;
4795
4896
  const adjustedWidthRightAxis = store.layersDisplay.declivities
4796
4897
  ? width - OFFSET_RIGHT_AXIS
@@ -4810,36 +4911,56 @@ const SpeedSpaceChart = ({ width, height, backgroundColor, data, setHeight, tran
4810
4911
  isSettingsPanelOpened: true,
4811
4912
  }));
4812
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]);
4813
4927
  useEffect(() => {
4814
4928
  setStore((prev) => ({
4815
4929
  ...prev,
4816
4930
  ...data,
4817
4931
  }));
4818
4932
  }, [data]);
4819
- useEffect(() => {
4820
- setHeight(dynamicHeight);
4821
- }, [setHeight, dynamicHeight]);
4822
4933
  return (React.createElement("div", { style: {
4823
4934
  width: `${width}px`,
4824
- height: `${dynamicHeight}px`,
4935
+ height: `${height}px`,
4825
4936
  backgroundColor: `${backgroundColor}`,
4937
+ position: 'relative',
4826
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
+ } })),
4827
4948
  React.createElement("div", { className: "flex justify-end absolute base-margin-top", style: { width: adjustedWidthRightAxis } },
4828
4949
  React.createElement(InteractionButtons, { reset: reset, openSettingsPanel: openSettingsPanel, store: store, testIdPrefix: "interaction" })),
4829
4950
  store.isSettingsPanelOpened && (React.createElement("div", { className: "flex justify-end absolute ml-2 base-margin-top", style: { width: adjustedWidthRightAxis } },
4830
- React.createElement(SettingsPanel, { globalHeight: dynamicHeight, color: backgroundColor, store: store, setStore: setStore, setIsMouseHoveringSettingsPanel: setIsMouseHoveringSettingsPanel, translations: translations, testIdPrefix: "settings-panel" }))),
4951
+ React.createElement(SettingsPanel, { color: backgroundColor, store: store, setStore: setStore, setIsMouseHoveringSettingsPanel: setIsMouseHoveringSettingsPanel, translations: translations, testIdPrefix: "settings-panel", adjustHeightOnLayerChange: adjustHeightOnLayerChange }))),
4831
4952
  store.layersDisplay.declivities && (React.createElement(DeclivityLayer, { width: WIDTH_OFFSET, height: HEIGHT_OFFSET, store: store })),
4832
4953
  React.createElement(CurveLayer, { width: WIDTH_OFFSET, height: HEIGHT_OFFSET, store: store }),
4833
- store.layersDisplay.speedLimits && (React.createElement(SpeedLimitsLayer, { width: adjustedWidthRightAxis, height: height, store: store })),
4834
- store.layersDisplay.steps && (React.createElement(StepsLayer, { width: adjustedWidthRightAxis, height: height, store: store })),
4835
- React.createElement(AxisLayerY, { width: width, height: height, store: store }),
4836
- store.layersDisplay.electricalProfiles && (React.createElement(ElectricalProfileLayer, { width: adjustedWidthRightAxis, height: height + LINEAR_LAYERS_HEIGHTS.ELECTRICAL_PROFILES_HEIGHT, store: store })),
4837
- store.layersDisplay.powerRestrictions && (React.createElement(PowerRestrictionsLayer, { width: adjustedWidthRightAxis, marginTop: getLinearLayerMarginTop(height, store.layersDisplay), store: store })),
4838
- store.layersDisplay.speedLimitTags && (React.createElement(SpeedLimitTagsLayer, { width: adjustedWidthRightAxis, marginTop: getLinearLayerMarginTop(height, store.layersDisplay, store.layersDisplay.speedLimitTags), store: store })),
4839
- React.createElement(TickLayerX, { width: adjustedWidthRightAxis, height: dynamicHeight, store: store }),
4840
- store.layersDisplay.declivities && (React.createElement(TickLayerYRight, { width: width, height: height, store: store })),
4841
- !isMouseHoveringSettingsPanel && (React.createElement(ReticleLayer, { width: adjustedWidthRightAxis, height: dynamicHeight, heightOffset: dynamicHeightOffset, store: store })),
4842
- React.createElement(FrontInteractivityLayer, { width: WIDTH_OFFSET, height: dynamicHeightOffset, store: store, setStore: setStore })));
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 })));
4843
4964
  };
4844
4965
 
4845
4966
  const TRACK_HEIGHT_CONTAINER = 100;
@@ -5500,7 +5621,7 @@ const TrackOccupancyStandalone = ({ tracks, occupancyZones, selectedTrainId, onS
5500
5621
  return (React.createElement("div", { className: "track-occupancy-standalone flex flex-col" },
5501
5622
  React.createElement("div", { className: "bg-ambientB-5 flex flex-col justify-center main-container-header grow-0 shrink-0" },
5502
5623
  React.createElement(KebabHorizontal, null)),
5503
- 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 } },
5504
5625
  React.createElement("div", { ref: manchetteWithSpaceTimeChartRef, className: "manchette flex h-100", onScroll: handleScroll, style: { height } },
5505
5626
  React.createElement(Manchette, { ...manchetteProps }),
5506
5627
  React.createElement("div", { className: "space-time-chart-container w-full sticky", ref: spaceTimeChartRef },
@@ -5517,5 +5638,5 @@ const TrackOccupancyStandalone = ({ tracks, occupancyZones, selectedTrainId, onS
5517
5638
  }) }))))));
5518
5639
  };
5519
5640
 
5520
- 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, 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 };
5521
5642
  //# sourceMappingURL=index.esm.js.map