From eeaccc36c5b123978489f96dc39c0c70556643db Mon Sep 17 00:00:00 2001 From: Jack Griffiths Date: Tue, 22 Oct 2024 20:10:39 +0100 Subject: [PATCH] Add commands for zoom to fit --- docs/visual-editor/setup.md | 4 + packages/renderer-vue/playground/App.vue | 11 ++ packages/renderer-vue/src/commandList.ts | 2 + packages/renderer-vue/src/icons/ZoomScan.vue | 22 ++++ packages/renderer-vue/src/icons/index.ts | 1 + packages/renderer-vue/src/settings.ts | 12 ++ packages/renderer-vue/src/toolbar/Toolbar.vue | 2 + packages/renderer-vue/src/viewModel.ts | 2 + packages/renderer-vue/src/zoomToFit.ts | 120 ++++++++++++++++++ 9 files changed, 176 insertions(+) create mode 100644 packages/renderer-vue/src/icons/ZoomScan.vue create mode 100644 packages/renderer-vue/src/zoomToFit.ts diff --git a/docs/visual-editor/setup.md b/docs/visual-editor/setup.md index 63ad0930..c67d5315 100644 --- a/docs/visual-editor/setup.md +++ b/docs/visual-editor/setup.md @@ -85,6 +85,10 @@ Settings can be changed by accessing the `settings` property of the view model r | nodes.reverseY | boolean | false | | contextMenu.enabled | boolean | true | | contextMenu.additionalItems | ContextMenuItem[] | [] | +| zoomToFit.paddingLeft | number | 300 | +| zoomToFit.paddingRight | number | 50 | +| zoomToFit.paddingTop | number | 110 | +| zoomToFit.paddingBottom | number | 50 | For example, to enable displaying the value of a node interface on hover: diff --git a/packages/renderer-vue/playground/App.vue b/packages/renderer-vue/playground/App.vue index a9f70f0b..35033a9e 100644 --- a/packages/renderer-vue/playground/App.vue +++ b/packages/renderer-vue/playground/App.vue @@ -15,6 +15,7 @@ + @@ -154,6 +155,16 @@ const changeSidebarWidth = () => { const clearHistory = () => { baklavaView.commandHandler.executeCommand(Commands.CLEAR_HISTORY_COMMAND); }; + +const zoomToFitRandomNode = () => { + if (baklavaView.displayedGraph.nodes.length === 0) { + return; + } + + const nodes = baklavaView.displayedGraph.nodes; + const node = nodes[Math.floor(Math.random() * nodes.length)]; + baklavaView.commandHandler.executeCommand(Commands.ZOOM_TO_FIT_NODES_COMMAND, true, [node]); +}