Skip to content

Commit

Permalink
ui-manchette: integration manchette + spacetimechart done
Browse files Browse the repository at this point in the history
  • Loading branch information
Math-R committed Jul 5, 2024
1 parent 102e682 commit 28fa47c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
69 changes: 48 additions & 21 deletions ui-manchette/src/components/Manchette.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import OperationalPointList from './OperationalPointList';
import { OperationalPointType, ProjectPathTrainResult, StyledOperationalPointType } from '../types';
import { ZoomIn, ZoomOut } from '@osrd-project/ui-icons';
import { SpaceTimeChart, PathLayer } from '@osrd-project/ui-spacetimechart';
import { calcOperationalPointsToDisplay, operationalPointsHeight } from './helpers';
import { OperationalPoint, PathData } from 'ui-spacetimechart/dist/lib/types';
import { BASE_KM_HEIGHT } from './consts';
import { BASE_KM_HEIGHT, BASE_OP_HEIGHT } from './consts';
import { SpaceScale } from 'ui-spacetimechart/dist/lib/types';

type ManchetteProps = {
Expand All @@ -19,6 +19,8 @@ const Manchette: React.FC<ManchetteProps> = ({
projectPathTrainResult,
isProportionnal = false,
}) => {
const manchette = useRef(null);

const [zoomY, setZoomY] = React.useState(1);

const xZoomLevel = 1;
Expand All @@ -27,6 +29,8 @@ const Manchette: React.FC<ManchetteProps> = ({

const [yOffset, setYOffset] = React.useState(0);

Check warning on line 30 in ui-manchette/src/components/Manchette.tsx

View workflow job for this annotation

GitHub Actions / build

'yOffset' is assigned a value but never used

Check warning on line 30 in ui-manchette/src/components/Manchette.tsx

View workflow job for this annotation

GitHub Actions / build

'setYOffset' is assigned a value but never used

const [scrollPosition, setScrollPosition] = React.useState(0);

const [operationalPointsToDisplay, setOperationalPointsToDisplay] = React.useState<
StyledOperationalPointType[]
>([]);
Expand Down Expand Up @@ -80,13 +84,21 @@ const Manchette: React.FC<ManchetteProps> = ({
from: point.position,
to: ops[i + 1].position,
...(!isProportionnal
? { size: 50 * zoomY }
? { size: BASE_OP_HEIGHT * zoomY }
: { coefficient: ((1000 / BASE_KM_HEIGHT) * 1000) / zoomY }),
};
});
return scales;
};

useEffect(() => {
window.addEventListener('scroll', handleScroll, { passive: true });

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

useEffect(() => {
const computedOperationalPoints = calcOperationalPointsToDisplay(
operationalPoints,
Expand All @@ -104,10 +116,19 @@ const Manchette: React.FC<ManchetteProps> = ({
setScales(getScales(operationalPointsChart));
}, [operationalPointsChart]);

Check warning on line 117 in ui-manchette/src/components/Manchette.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has a missing dependency: 'getScales'. Either include it or remove the dependency array

const handleScroll = () => {
if (manchette.current) {
const { scrollTop } = manchette.current;
if (scrollTop || scrollTop === 0) setScrollPosition(scrollTop);
}
};

return (
<div className="manchette flex">
<div ref={manchette} className="manchette flex" onScroll={handleScroll}>
<div className="manchette-container">
<OperationalPointList operationalPoints={operationalPointsToDisplay} />
<div className=" bg-ambientB-10" style={{ minHeight: '521px' }}>
<OperationalPointList operationalPoints={operationalPointsToDisplay} />
</div>
<div className="manchette-actions flex items-center">
<div className=" flex items-center ">
<button className="h-full px-3 w-full" onClick={zoomYOut} disabled={zoomY === 1}>
Expand All @@ -121,22 +142,28 @@ const Manchette: React.FC<ManchetteProps> = ({
</div>
</div>
</div>
{scales.length > 0 && (
<SpaceTimeChart
className="inset-0 absolute"
operationalPoints={operationalPointsChart}
spaceOrigin={0}
spaceScales={scales}
timeOrigin={Math.min(...projectPathTrainResult.map((p) => +new Date(p.departure_time)))}
timeScale={60000 / xZoomLevel}
xOffset={xOffset}
yOffset={yOffset}
>
{paths.map((path, i) => (
<PathLayer key={path.id} index={i} path={path} color={path.color} />
))}
</SpaceTimeChart>
)}
<div
className="space-time-chart-container w-full sticky"
style={{ bottom: 0, left: 0, top: 0, height: '561px' }}
>
{scales.length > 0 && (
<SpaceTimeChart
className="inset-0 absolute h-full"
style={{ top: 0, height: 'calc(100% - 6px)' }}
operationalPoints={operationalPointsChart}
spaceOrigin={0}
spaceScales={scales}
timeOrigin={Math.min(...projectPathTrainResult.map((p) => +new Date(p.departure_time)))}
timeScale={60000 / xZoomLevel}
xOffset={xOffset}
yOffset={-scrollPosition + 14}
>
{paths.map((path, i) => (
<PathLayer key={path.id} index={i} path={path} color={path.color} />
))}
</SpaceTimeChart>
)}
</div>
</div>
);
};
Expand Down
6 changes: 6 additions & 0 deletions ui-manchette/src/styles/manchette.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
border: solid 1px;
@apply border-black-25
}

.space-time-chart-container {
height: 561px;
width: 100%;
bottom:0;
}
}

0 comments on commit 28fa47c

Please sign in to comment.