Skip to content

Commit eaecc6b

Browse files
committed
Prevent annotations and other Html elements from overflowing canvas
1 parent e78c50d commit eaecc6b

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

packages/lib/src/vis/shared/AxisSystem.module.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.axisSystem {
2+
position: absolute;
3+
pointer-events: none;
24
display: grid;
35
grid-template-areas:
46
'. top-axis .'

packages/lib/src/vis/shared/AxisSystem.tsx

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getVisibleDomains } from '../utils';
66
import Axis from './Axis';
77
import styles from './AxisSystem.module.css';
88
import { useAxisSystemContext } from './AxisSystemProvider';
9-
import Overlay from './Overlay';
9+
import Html from './Html';
1010

1111
interface Props {
1212
axisOffsets: AxisOffsets;
@@ -16,6 +16,7 @@ interface Props {
1616
function AxisSystem(props: Props) {
1717
const { axisOffsets, title } = props;
1818

19+
const gl = useThree((state) => state.gl);
1920
const canvasSize = useThree((state) => state.size);
2021
const { width, height } = canvasSize;
2122

@@ -26,35 +27,38 @@ function AxisSystem(props: Props) {
2627
);
2728

2829
return (
29-
<Overlay
30-
className={styles.axisSystem}
31-
style={{
32-
// Take over space reserved for axis by VisCanvas
33-
top: -axisOffsets.top,
34-
left: -axisOffsets.left,
35-
width: width + axisOffsets.left + axisOffsets.right,
36-
height: height + axisOffsets.bottom + axisOffsets.top,
37-
gridTemplateColumns: `${axisOffsets.left}px 1fr ${axisOffsets.right}px`,
38-
gridTemplateRows: `${axisOffsets.top}px 1fr ${axisOffsets.bottom}px`,
39-
}}
40-
>
41-
{title && <p className={styles.title}>{title}</p>}
42-
<Axis
43-
type="abscissa"
44-
config={abscissaConfig}
45-
domain={xVisibleDomain}
46-
canvasSize={canvasSize}
47-
svgSize={{ width, height: axisOffsets.bottom }}
48-
/>
49-
<Axis
50-
type="ordinate"
51-
config={ordinateConfig}
52-
domain={yVisibleDomain}
53-
canvasSize={canvasSize}
54-
svgSize={{ width: axisOffsets.left, height }}
55-
flipAxis
56-
/>
57-
</Overlay>
30+
// Append to `canvasWrapper` instead of default container `r3fRoot`, which hides overflow
31+
<Html container={gl.domElement.parentElement?.parentElement || undefined}>
32+
<div
33+
className={styles.axisSystem}
34+
style={{
35+
// Take over space reserved for axis by VisCanvas
36+
top: -axisOffsets.top,
37+
left: -axisOffsets.left,
38+
width: width + axisOffsets.left + axisOffsets.right,
39+
height: height + axisOffsets.bottom + axisOffsets.top,
40+
gridTemplateColumns: `${axisOffsets.left}px 1fr ${axisOffsets.right}px`,
41+
gridTemplateRows: `${axisOffsets.top}px 1fr ${axisOffsets.bottom}px`,
42+
}}
43+
>
44+
{title && <p className={styles.title}>{title}</p>}
45+
<Axis
46+
type="abscissa"
47+
config={abscissaConfig}
48+
domain={xVisibleDomain}
49+
canvasSize={canvasSize}
50+
svgSize={{ width, height: axisOffsets.bottom }}
51+
/>
52+
<Axis
53+
type="ordinate"
54+
config={ordinateConfig}
55+
domain={yVisibleDomain}
56+
canvasSize={canvasSize}
57+
svgSize={{ width: axisOffsets.left, height }}
58+
flipAxis
59+
/>
60+
</div>
61+
</Html>
5862
);
5963
}
6064

packages/lib/src/vis/shared/VisCanvas.module.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
}
66

77
.canvasWrapper {
8+
position: relative; /* for axis system */
89
width: 100%; /* fill container by default (unless size is passed in JSX) */
910
height: 100%;
1011
margin: 0 auto;
1112
}
1213

1314
.r3fRoot {
14-
overflow: visible !important; /* show child axis grid, which is bigger than canvas */
1515
background-color: var(--h5w-canvas--bgColor, transparent);
1616
}
1717

1818
.floatingToolbar {
1919
position: absolute;
20-
top: auto !important;
21-
left: auto !important;
2220
right: 0;
2321
bottom: 0;
2422
display: flex;

packages/lib/src/vis/shared/VisCanvas.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { AxisConfig } from '../models';
88
import { getSizeToFit, getAxisOffsets } from '../utils';
99
import AxisSystem from './AxisSystem';
1010
import AxisSystemProvider from './AxisSystemProvider';
11-
import Html from './Html';
1211
import RatioEnforcer from './RatioEnforcer';
1312
import ViewportCenterer from './ViewportCenterer';
1413
import styles from './VisCanvas.module.css';
@@ -81,15 +80,14 @@ function VisCanvas(props: PropsWithChildren<Props>) {
8180
{children}
8281
<ViewportCenterer />
8382
<RatioEnforcer visRatio={visRatio} />
84-
<Html>
85-
<div
86-
ref={(elem) => setFloatingToolbar(elem || undefined)}
87-
className={styles.floatingToolbar}
88-
/>
89-
</Html>
9083
</InteractionsProvider>
9184
</AxisSystemProvider>
9285
</Canvas>
86+
87+
<div
88+
ref={(elem) => setFloatingToolbar(elem || undefined)}
89+
className={styles.floatingToolbar}
90+
/>
9391
</div>
9492
)}
9593
</div>

0 commit comments

Comments
 (0)