feat(svelte): add functions to useSvelteFlow

This commit is contained in:
moklick
2023-03-14 17:24:01 +01:00
parent 2e486384a8
commit 5b3c260e45
9 changed files with 102 additions and 25 deletions
+7 -6
View File
@@ -127,19 +127,20 @@ export function createStore(params: CreateStoreParams): SvelteFlowStore {
store.nodes.set(nextNodes);
}
function zoomIn(options?: ViewportHelperFunctionOptions) {
function zoomBy(factor: number, options?: ViewportHelperFunctionOptions) {
const { zoom: d3Zoom, selection: d3Selection } = get(store.d3);
if (d3Zoom && d3Selection) {
d3Zoom.scaleBy(getD3Transition(d3Selection, options?.duration), 1.2);
d3Zoom.scaleBy(getD3Transition(d3Selection, options?.duration), factor);
}
}
function zoomIn(options?: ViewportHelperFunctionOptions) {
zoomBy(1.2, options);
}
function zoomOut(options?: ViewportHelperFunctionOptions) {
const { zoom: d3Zoom, selection: d3Selection } = get(store.d3);
if (d3Zoom && d3Selection) {
d3Zoom.scaleBy(getD3Transition(d3Selection, options?.duration), 1 / 1.2);
}
zoomBy(1 / 1.2, options);
}
function setMinZoom(minZoom: number) {