Skip to content

Commit 204c84a

Browse files
committed
chore: tweak reset
1 parent 2b09027 commit 204c84a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

frontend/routes/package/(_islands)/DependencyGraph.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function renderErrorDependency(dependency: DependencyGraphKindError) {
113113

114114
function useDigraph(dependencies: DependencyGraphProps["dependencies"]) {
115115
const controls = useSignal({ pan: { x: 0, y: 0 }, zoom: 1 });
116+
const defaults = useSignal({ pan: { x: 0, y: 0 }, zoom: 1 });
116117
const ref = useRef<HTMLDivElement>(null);
117118
const svg = useRef<SVGSVGElement | null>(null);
118119
const viz = useSignal<Viz | undefined>(undefined);
@@ -124,10 +125,10 @@ function useDigraph(dependencies: DependencyGraphProps["dependencies"]) {
124125
const { width: rWidth, height: rHeight } = ref.current
125126
.getBoundingClientRect();
126127

127-
controls.value.pan.x = (rWidth - sWidth) / 2;
128-
controls.value.pan.y = (rHeight - sHeight) / 2;
129-
controls.value.zoom = Math.min(rWidth / sWidth, rHeight / sHeight);
130-
128+
defaults.value.pan.x = (rWidth - sWidth) / 2;
129+
defaults.value.pan.y = (rHeight - sHeight) / 2;
130+
defaults.value.zoom = Math.min(rWidth / sWidth, rHeight / sHeight);
131+
controls.value = { ...defaults.value };
131132
svg.current.style.transform =
132133
`translate(${controls.value.pan.x}px, ${controls.value.pan.y}px) scale(${controls.value.zoom})`;
133134
}
@@ -140,7 +141,7 @@ function useDigraph(dependencies: DependencyGraphProps["dependencies"]) {
140141
svg.current.style.transform =
141142
`translate(${controls.value.pan.x}px, ${controls.value.pan.y}px) scale(${controls.value.zoom})`;
142143
}
143-
}, [controls]);
144+
}, []);
144145

145146
const zoom = useCallback((zoom: number) => {
146147
controls.value.zoom = Math.max(
@@ -152,12 +153,13 @@ function useDigraph(dependencies: DependencyGraphProps["dependencies"]) {
152153
svg.current.style.transform =
153154
`translate(${controls.value.pan.x}px, ${controls.value.pan.y}px) scale(${controls.value.zoom})`;
154155
}
155-
}, [controls]);
156+
}, []);
156157

157158
const reset = useCallback(() => {
158-
controls.value = { pan: { x: 0, y: 0 }, zoom: 1 };
159+
controls.value = { ...defaults.value };
159160
if (svg.current) {
160-
svg.current.style.transform = "";
161+
svg.current.style.transform =
162+
`translate(${controls.value.pan.x}px, ${controls.value.pan.y}px) scale(${controls.value.zoom})`;
161163
}
162164
}, []);
163165

0 commit comments

Comments
 (0)