Skip to content

Commit 54e521d

Browse files
committed
ui-spacetimechart: fix blank stories
The space time chart stories were sometimes not loading properly, showing a blank page. Two issues: - All stories were passing className='absolute inset-0' to SpaceTimeChart. However, SpaceTimeChart was combining these classes with 'relative'. As a result, the browser would roll a dice and pick either 'absolute' or 'relative'. When 'relative' is picked first, 'inset-0' has no effect because… - All stories except one were using a wrapper div with className="inset-0". This had no effect because this div is neither absolute nor relative. As a result, half the time the chart would have a zero height. Fix this by: - Adding absolute positioning to the wrapper div. - Setting the height of the SpaceTimeChart instead of mixing up conflicting positioning classes. Signed-off-by: Simon Ser <[email protected]>
1 parent f67a5af commit 54e521d

12 files changed

+37
-40
lines changed

ui-spacetimechart/src/stories/additional-data.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ const Wrapper = ({ swapAxis, spaceScaleType }: WrapperProps) => {
188188
});
189189

190190
return (
191-
<div className="inset-0">
191+
<div className="absolute inset-0">
192192
<SpaceTimeChart
193-
className={cx('inset-0 absolute p-0 m-0', state.panning && 'cursor-grabbing')}
193+
className={cx('h-full p-0 m-0', state.panning && 'cursor-grabbing')}
194194
operationalPoints={OPERATIONAL_POINTS}
195195
swapAxis={swapAxis}
196196
spaceOrigin={0}

ui-spacetimechart/src/stories/base-rendering.stories.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,22 @@ const Wrapper = ({
5050
: PATHS;
5151

5252
return (
53-
<SpaceTimeChart
54-
className="inset-0 absolute"
55-
operationalPoints={operationalPoints}
56-
spaceOrigin={0}
57-
spaceScales={spaceScales}
58-
timeOrigin={+new Date('2024/04/02')}
59-
timeScale={60000 / xZoomLevel}
60-
xOffset={xOffset}
61-
yOffset={yOffset}
62-
>
63-
{paths.map((path) => (
64-
<PathLayer key={path.id} path={path} color={path.color} />
65-
))}
66-
</SpaceTimeChart>
53+
<div className="absolute inset-0">
54+
<SpaceTimeChart
55+
className="h-full"
56+
operationalPoints={operationalPoints}
57+
spaceOrigin={0}
58+
spaceScales={spaceScales}
59+
timeOrigin={+new Date('2024/04/02')}
60+
timeScale={60000 / xZoomLevel}
61+
xOffset={xOffset}
62+
yOffset={yOffset}
63+
>
64+
{paths.map((path) => (
65+
<PathLayer key={path.id} path={path} color={path.color} />
66+
))}
67+
</SpaceTimeChart>
68+
</div>
6769
);
6870
};
6971

ui-spacetimechart/src/stories/custom-styles.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const Wrapper = ({ color1, color2, color3, spaceScaleType }: WrapperProps) => {
4848
});
4949

5050
return (
51-
<div className="inset-0">
51+
<div className="absolute inset-0">
5252
<SpaceTimeChart
53-
className={cx('inset-0 absolute p-0 m-0', state.panning && 'cursor-grabbing')}
53+
className={cx('h-full p-0 m-0', state.panning && 'cursor-grabbing')}
5454
operationalPoints={OPERATIONAL_POINTS}
5555
spaceOrigin={0}
5656
spaceScales={OPERATIONAL_POINTS.slice(0, -1).map((point, i) => ({

ui-spacetimechart/src/stories/horizontal-zoom.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Meta } from '@storybook/react';
55
import { clamp } from 'lodash';
66

77
import '@osrd-project/ui-core/dist/theme.css';
8+
import '@osrd-project/ui-spacetimechart/dist/theme.css';
89

910
import { OPERATIONAL_POINTS, PATHS } from './lib/paths';
1011
import { PathLayer } from '../components/PathLayer';
@@ -80,7 +81,7 @@ const SpaceTimeHorizontalZoomWrapper = ({
8081
}}
8182
>
8283
<SpaceTimeChart
83-
className="inset-0 absolute h-full"
84+
className="h-full"
8485
spaceOrigin={0}
8586
xOffset={state.xOffset}
8687
yOffset={state.yOffset}

ui-spacetimechart/src/stories/layers.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ const Wrapper = () => {
107107
const [cursorTime, setCursorTime] = useState<number>(0);
108108

109109
return (
110-
<div className="inset-0">
110+
<div className="absolute inset-0">
111111
<SpaceTimeChart
112-
className="inset-0 absolute overflow-hidden p-0 m-0"
112+
className="h-full overflow-hidden p-0 m-0"
113113
operationalPoints={OPERATIONAL_POINTS}
114114
spaceOrigin={0}
115115
spaceScales={OPERATIONAL_POINTS.slice(0, -1).map((point, i) => ({

ui-spacetimechart/src/stories/measuring.stories.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ const Wrapper = ({ spaceScaleType, enableSnapping }: WrapperProps) => {
3838
});
3939

4040
return (
41-
<div className="inset-0">
41+
<div className="absolute inset-0">
4242
<SpaceTimeChart
43-
className={cx(
44-
'inset-0 absolute overflow-hidden p-0 m-0',
45-
state.panTarget && 'cursor-grabbing'
46-
)}
43+
className={cx('h-full overflow-hidden p-0 m-0', state.panTarget && 'cursor-grabbing')}
4744
enableSnapping={enableSnapping}
4845
operationalPoints={OPERATIONAL_POINTS}
4946
spaceOrigin={0}

ui-spacetimechart/src/stories/options.stories.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,9 @@ const Wrapper = ({
7676
});
7777

7878
return (
79-
<div className="inset-0">
79+
<div className="absolute inset-0">
8080
<SpaceTimeChart
81-
className={cx(
82-
'inset-0 absolute overflow-hidden p-0 m-0',
83-
state.panning && 'cursor-grabbing'
84-
)}
81+
className={cx('h-full overflow-hidden p-0 m-0', state.panning && 'cursor-grabbing')}
8582
enableSnapping={enableSnapping}
8683
hideGrid={hideGrid}
8784
hidePathsLabels={hidePathsLabels}

ui-spacetimechart/src/stories/paths-interactions.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ const Wrapper = ({
5959
});
6060

6161
return (
62-
<div className="inset-0">
62+
<div className="absolute inset-0">
6363
<SpaceTimeChart
6464
className={cx(
65-
'inset-0 absolute p-0 m-0',
65+
'h-full p-0 m-0',
6666
state.panTarget && 'cursor-grabbing',
6767
state.hoveredPathId && 'cursor-pointer'
6868
)}

ui-spacetimechart/src/stories/performances.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ const Wrapper = ({
9494
});
9595

9696
return (
97-
<div className="inset-0">
97+
<div className="absolute inset-0">
9898
<SpaceTimeChart
99-
className={cx('inset-0 absolute p-0 m-0', state.panning && 'cursor-grabbing')}
99+
className={cx('h-full p-0 m-0', state.panning && 'cursor-grabbing')}
100100
operationalPoints={operationalPoints}
101101
spaceOrigin={0}
102102
spaceScales={operationalPoints.slice(0, -1).map((point, i) => ({

ui-spacetimechart/src/stories/scroll-navigation.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const Wrapper = ({ spaceScaleType }: WrapperProps) => {
4747
});
4848

4949
return (
50-
<div className="inset-0">
50+
<div className="absolute inset-0">
5151
<SpaceTimeChart
5252
className={cx(
53-
'inset-0 absolute p-0 m-0',
53+
'h-full p-0 m-0',
5454
state.panTarget && 'cursor-grabbing',
5555
state.hoveredPathId && 'cursor-pointer'
5656
)}

0 commit comments

Comments
 (0)