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

Commit 0d2c156

Browse files
committed
front: fix exported function, no longer divided between two components
Signed-off-by: Theo Macron <[email protected]>
1 parent f74d1fb commit 0d2c156

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

ui-manchette-with-spacetimechart/src/helpers.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { InteractiveWaypoint, Waypoint } from '@osrd-project/ui-manchette/dist/types';
22
import type { OperationalPoint } from '@osrd-project/ui-spacetimechart/dist/lib/types';
3-
import { filterVisibleElements } from '@osrd-project/ui-speedspacechart/src/components/utils';
43
import { clamp } from 'lodash';
54

65
import {
@@ -14,6 +13,39 @@ import { calcTotalDistance, getHeightWithoutLastWaypoint } from './utils';
1413

1514
type WaypointsOptions = { isProportional: boolean; yZoom: number; height: number };
1615

16+
type VisibilityFilterOptions<T> = {
17+
elements: T[];
18+
getPosition: (element: T) => number;
19+
getWeight: (element: T) => number | undefined;
20+
minSpace: number;
21+
};
22+
23+
export const filterVisibleElements = <T>({
24+
elements,
25+
getPosition,
26+
getWeight,
27+
minSpace,
28+
}: VisibilityFilterOptions<T>): T[] => {
29+
const sortedElements = [...elements].sort((a, b) => (getWeight(b) ?? 0) - (getWeight(a) ?? 0));
30+
const displayedElements: { element: T; position: number }[] = [];
31+
32+
for (const element of sortedElements) {
33+
const position = getPosition(element);
34+
35+
const hasSpace = !displayedElements.some(
36+
(displayed) => Math.abs(position - displayed.position) < minSpace
37+
);
38+
39+
if (hasSpace) {
40+
displayedElements.push({ element, position });
41+
}
42+
}
43+
44+
return displayedElements
45+
.sort((a, b) => getPosition(a.element) - getPosition(b.element))
46+
.map(({ element }) => element);
47+
};
48+
1749
export const getDisplayedWaypoints = (
1850
waypoints: Waypoint[],
1951
{ height, isProportional, yZoom }: WaypointsOptions

ui-speedspacechart/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
],
2222
"exports": {
2323
"./dist/theme.css": "./dist/theme.css",
24-
"./src/components/utils": "./src/components/utils",
2524
".": {
2625
"types": "./dist/index.d.ts",
2726
"default": "./dist/index.esm.js"

0 commit comments

Comments
 (0)