diff options
Diffstat (limited to 'subprojects/frontend/src/graph/ZoomCanvas.tsx')
-rw-r--r-- | subprojects/frontend/src/graph/ZoomCanvas.tsx | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/subprojects/frontend/src/graph/ZoomCanvas.tsx b/subprojects/frontend/src/graph/ZoomCanvas.tsx index 2bb7f139..0254bc59 100644 --- a/subprojects/frontend/src/graph/ZoomCanvas.tsx +++ b/subprojects/frontend/src/graph/ZoomCanvas.tsx | |||
@@ -34,10 +34,11 @@ export type ChangeZoomCallback = (factor: number) => void; | |||
34 | 34 | ||
35 | export type SetFitZoomCallback = (fitZoom: boolean) => void; | 35 | export type SetFitZoomCallback = (fitZoom: boolean) => void; |
36 | 36 | ||
37 | export type FitZoomCallback = (newSize?: { | 37 | export type FitZoomCallback = ((newSize?: { |
38 | width: number; | 38 | width: number; |
39 | height: number; | 39 | height: number; |
40 | }) => void; | 40 | }) => void) & |
41 | ((newSize: boolean) => void); | ||
41 | 42 | ||
42 | export default function ZoomCanvas({ | 43 | export default function ZoomCanvas({ |
43 | children, | 44 | children, |
@@ -79,7 +80,7 @@ export default function ZoomCanvas({ | |||
79 | } | 80 | } |
80 | let width = 0; | 81 | let width = 0; |
81 | let height = 0; | 82 | let height = 0; |
82 | if (newSize === undefined) { | 83 | if (newSize === undefined || typeof newSize === 'boolean') { |
83 | const elementRect = elementRef.current.getBoundingClientRect(); | 84 | const elementRect = elementRef.current.getBoundingClientRect(); |
84 | const currentFactor = d3.zoomTransform(canvasRef.current).k; | 85 | const currentFactor = d3.zoomTransform(canvasRef.current).k; |
85 | width = elementRect.width / currentFactor; | 86 | width = elementRect.width / currentFactor; |
@@ -96,8 +97,11 @@ export default function ZoomCanvas({ | |||
96 | (canvasRect.width - 2 * fitPaddingOrDefault) / width, | 97 | (canvasRect.width - 2 * fitPaddingOrDefault) / width, |
97 | (canvasRect.height - 2 * fitPaddingOrDefault) / height, | 98 | (canvasRect.height - 2 * fitPaddingOrDefault) / height, |
98 | ); | 99 | ); |
99 | const zoomTransition = makeTransition(canvasRef.current); | 100 | const target = |
100 | zoomRef.current.transform(zoomTransition, d3.zoomIdentity.scale(factor)); | 101 | newSize === false |
102 | ? d3.select(canvasRef.current) | ||
103 | : makeTransition(canvasRef.current); | ||
104 | zoomRef.current.transform(target, d3.zoomIdentity.scale(factor)); | ||
101 | }, | 105 | }, |
102 | [fitPaddingOrDefault, makeTransition], | 106 | [fitPaddingOrDefault, makeTransition], |
103 | ); | 107 | ); |