@osrd-project/ui-charts 0.0.72 → 0.0.74

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
@@ -603,8 +603,8 @@ function useCanvas$1(dom, inputStcContext, position) {
603
603
  const ratio = isPicking ? pickingScalingRatio : devicePixelRatio;
604
604
  canvas.style.width = size.width + 'px';
605
605
  canvas.style.height = size.height + 'px';
606
- canvas.setAttribute('width', size.width * ratio + 'px');
607
- canvas.setAttribute('height', size.height * ratio + 'px');
606
+ canvas.setAttribute('width', Math.max(1, size.width * ratio) + 'px');
607
+ canvas.setAttribute('height', Math.max(1, size.height * ratio) + 'px');
608
608
  if (!isPicking) {
609
609
  // Reset the transform to identity, then apply the new scale
610
610
  ctx.setTransform(1, 0, 0, 1, 0, 0);
@@ -2571,14 +2571,18 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2571
2571
  const resetZoom = useCallback(() => {
2572
2572
  setState((prev) => ({ ...prev, yZoom: 1 }));
2573
2573
  }, []);
2574
- const handleScroll = useCallback(() => {
2574
+ const handleScroll = useCallback((e) => {
2575
+ if (rect) {
2576
+ e.preventDefault();
2577
+ return;
2578
+ }
2575
2579
  if (!isShiftPressed && manchetteWithSpaceTimeChartRef.current) {
2576
2580
  const { scrollTop } = manchetteWithSpaceTimeChartRef.current;
2577
2581
  if (scrollTop || scrollTop === 0) {
2578
2582
  setState((prev) => ({ ...prev, yOffset: scrollTop }));
2579
2583
  }
2580
2584
  }
2581
- }, [isShiftPressed, manchetteWithSpaceTimeChartRef]);
2585
+ }, [isShiftPressed, manchetteWithSpaceTimeChartRef, rect]);
2582
2586
  const handleKeyDown = useCallback((event) => {
2583
2587
  if (event.key === 'Shift') {
2584
2588
  setIsShiftPressed(true);
@@ -2683,7 +2687,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2683
2687
  const { manchetteContents, manchetteHeight } = useMemo(() => {
2684
2688
  const spaceScaleTree = spaceScalesToBinaryTree(spaceOrigin, spaceScales);
2685
2689
  const getSpacePixel = getSpaceToPixel(0, spaceScaleTree);
2686
- const totalManchetteHeight = getSpacePixel(spaceScales.at(-1).to, true) + BASE_WAYPOINT_HEIGHT;
2690
+ const totalManchetteHeight = Math.max(getSpacePixel(spaceScales.at(-1).to, true) + BASE_WAYPOINT_HEIGHT, height - FOOTER_HEIGHT);
2687
2691
  if (!splitPoints)
2688
2692
  return {
2689
2693
  manchetteHeight: totalManchetteHeight,
@@ -2702,6 +2706,10 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2702
2706
  })));
2703
2707
  // Sort all contents by position:
2704
2708
  const allSortedContents = sortBy(allContents, 'position');
2709
+ // In practice, waypoint lines are 0.5px wide only when devicePixelRatio is at least 2 (as it's
2710
+ // implemented at the end of waypoint.css). But to get the proper alignment, we always consider
2711
+ // it to be 0.5px wide here, because they always have this thickness SpaceTimeChart side:
2712
+ const waypointLinesThickness = 0.5;
2705
2713
  // Iterate over all contents, to set each split section's style, and correct waypoints styles
2706
2714
  // accordingly:
2707
2715
  const finalContents = [];
@@ -2712,7 +2720,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2712
2720
  ...content.waypoint,
2713
2721
  styles: {
2714
2722
  position: 'absolute',
2715
- top: `${getSpacePixel(content.position)}px`,
2723
+ top: `${getCrispLineCoordinate(getSpacePixel(content.position), waypointLinesThickness)}px`,
2716
2724
  height: `${BASE_WAYPOINT_HEIGHT}px`,
2717
2725
  },
2718
2726
  });
@@ -2740,7 +2748,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2740
2748
  manchetteHeight: totalManchetteHeight,
2741
2749
  manchetteContents: finalContents,
2742
2750
  };
2743
- }, [spaceOrigin, spaceScales, splitPoints, waypointsWithoutSplitPoints]);
2751
+ }, [spaceOrigin, spaceScales, splitPoints, waypointsWithoutSplitPoints, height]);
2744
2752
  return useMemo(() => ({
2745
2753
  manchetteProps: {
2746
2754
  contents: manchetteContents,
@@ -2766,7 +2774,7 @@ const useManchetteWithSpaceTimeChart = ({ waypoints, manchetteWithSpaceTimeChart
2766
2774
  spaceOrigin,
2767
2775
  spaceScales,
2768
2776
  onZoom: ({ delta, position, }) => {
2769
- if (isShiftPressed) {
2777
+ if (isShiftPressed && !rect) {
2770
2778
  handleXZoom(xZoom + delta, position.x);
2771
2779
  }
2772
2780
  },
@@ -5178,5 +5186,5 @@ React.createElement("div", { className: "track", key: track.id, style: { height:
5178
5186
  React.createElement("div", { className: "track-name" }, track.name),
5179
5187
  React.createElement("div", { className: "track-rail" }))))));
5180
5188
 
5181
- export { CanvasContext, ConflictLayer, ConflictTooltip, DEFAULT_LEVEL, DEFAULT_THEME, DEFAULT_ZOOM_MS_PER_PX, Manchette, ManchetteWithSpaceTimeChart, MouseContext, OccupancyBlockLayer, PathLayer, PatternRect, Quadrilateral, SpaceTimeChart, SpaceTimeChartContext, SpeedSpaceChart, TimeCaptions, Tooltip$1 as Tooltip, TrackOccupancyCanvas, TrackOccupancyManchette, WorkScheduleLayer, ZoomRect, getSpaceAtTime, isConflictPickingElement, isInteractiveWaypoint, isPathOnScreen, isPointPickingElement, isSegmentPickingElement, positionMmToKm, timeScaleToZoomValue, useDraw, useManchetteWithSpaceTimeChart, usePaths, usePicking };
5189
+ export { CanvasContext, ConflictLayer, ConflictTooltip, DEFAULT_LEVEL, DEFAULT_THEME, DEFAULT_ZOOM_MS_PER_PX, Manchette, ManchetteWithSpaceTimeChart, MouseContext, OccupancyBlockLayer, PathLayer, PatternRect, Quadrilateral, SpaceTimeChart, SpaceTimeChartContext, SpeedSpaceChart, TimeCaptions, Tooltip$1 as Tooltip, TrackOccupancyCanvas, TrackOccupancyManchette, WorkScheduleLayer, ZoomRect, getCrispLineCoordinate, getSpaceAtTime, isConflictPickingElement, isInteractiveWaypoint, isPathOnScreen, isPointPickingElement, isSegmentPickingElement, positionMmToKm, timeScaleToZoomValue, useDraw, useManchetteWithSpaceTimeChart, usePaths, usePicking };
5182
5190
  //# sourceMappingURL=index.esm.js.map