Skip to content

Commit

Permalink
Merge pull request #924 from silx-kit/fix-dynamic-layout
Browse files Browse the repository at this point in the history
Support switching VisCanvas's sizing behaviour dynamically
  • Loading branch information
axelboc authored Jan 12, 2022
2 parents c411203 + a5ff684 commit 62e10cf
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@h5web/lib": "workspace:*",
"@h5web/shared": "workspace:*",
"@react-hookz/web": "12.0.0",
"@react-hookz/web": "12.1.1",
"@react-three/fiber": "7.0.24",
"ndarray": "1.0.19",
"normalize.css": "8.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@h5web/lib": "workspace:*",
"@react-hookz/web": "12.0.0",
"@react-hookz/web": "12.1.1",
"@react-three/fiber": "7.0.24",
"axios": "0.24.0",
"d3-format": "3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"three": ">=0.120"
},
"dependencies": {
"@react-hookz/web": "12.0.0",
"@react-hookz/web": "12.1.1",
"@visx/axis": "2.4.0",
"@visx/grid": "2.4.0",
"@visx/scale": "2.2.2",
Expand Down
9 changes: 6 additions & 3 deletions packages/lib/src/vis/shared/VisCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function VisCanvas(props: PropsWithChildren<Props>) {
} = props;

const shouldMeasure = !!canvasRatio;
const [areaSize, areaRef] = useMeasure<HTMLDivElement>();
const [areaSize, areaRef] = useMeasure<HTMLDivElement>(shouldMeasure);
const canvasSize = areaSize && getSizeToFit(areaSize, canvasRatio);

const axisOffsets = getAxisOffsets({
Expand All @@ -38,7 +38,7 @@ function VisCanvas(props: PropsWithChildren<Props>) {

return (
<div
ref={shouldMeasure ? areaRef : undefined} // unfortunately, this isn't enough to start/stop measuring dynamically https://github.com/react-hookz/web/issues/523
ref={areaRef}
className={styles.canvasArea}
style={{
paddingBottom: axisOffsets.bottom,
Expand All @@ -48,7 +48,10 @@ function VisCanvas(props: PropsWithChildren<Props>) {
}}
>
{(!shouldMeasure || canvasSize) && (
<div className={styles.canvasWrapper} style={canvasSize}>
<div
className={styles.canvasWrapper}
style={shouldMeasure ? canvasSize : undefined}
>
<Canvas
className={styles.r3fRoot}
orthographic
Expand Down
113 changes: 88 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62e10cf

Please sign in to comment.