From ef213b6db9ad60792bb3e508943894da2390af2a Mon Sep 17 00:00:00 2001 From: Alexandr Marchenko Date: Wed, 1 Jan 2025 08:37:37 +0200 Subject: [PATCH 1/3] disble mouse scroll --- src/components/GraphViewport.tsx | 3 +++ src/components/Voyager.tsx | 3 +++ src/graph/viewport.ts | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/GraphViewport.tsx b/src/components/GraphViewport.tsx index 21347813..e7f280f9 100644 --- a/src/components/GraphViewport.tsx +++ b/src/components/GraphViewport.tsx @@ -19,6 +19,8 @@ interface GraphViewportProps { onSelectNode: (id: string | null) => void; onSelectEdge: (id: string) => void; + + disableMouseWheelZoom?: boolean | null; } interface GraphViewportState { @@ -106,6 +108,7 @@ export default class GraphViewport extends Component< this._containerRef.current!, onSelectNode, onSelectEdge, + { mouseWheelZoomEnabled: this.props.disableMouseWheelZoom ? false : true }, ); this.setState({ svgViewport }); }) diff --git a/src/components/Voyager.tsx b/src/components/Voyager.tsx index cfd0115e..f97c2258 100644 --- a/src/components/Voyager.tsx +++ b/src/components/Voyager.tsx @@ -48,6 +48,7 @@ export interface VoyagerProps { hideDocs?: boolean; hideSettings?: boolean; hideVoyagerLogo?: boolean; + disableMouseWheelZoom?: boolean; children?: ReactNode; } @@ -120,6 +121,7 @@ export default function Voyager(props: VoyagerProps) { hideSettings = false, // TODO: switch to false in the next major version hideVoyagerLogo = true, + disableMouseWheelZoom = false, } = props; const viewportRef = useRef(null); @@ -223,6 +225,7 @@ export default function Voyager(props: VoyagerProps) { onSelectNode={handleSelectNode} onSelectEdge={handleSelectEdge} ref={viewportRef} + disableMouseWheelZoom={disableMouseWheelZoom} /> ); diff --git a/src/graph/viewport.ts b/src/graph/viewport.ts index 13cc1f83..1c76c336 100644 --- a/src/graph/viewport.ts +++ b/src/graph/viewport.ts @@ -41,6 +41,7 @@ export class Viewport { public container: HTMLElement, onSelectNode: (id: string | null) => void, onSelectEdge: (id: string) => void, + options: SvgPanZoom.Options = {}, ) { this.onSelectNode = onSelectNode; this.onSelectEdge = onSelectEdge; @@ -51,7 +52,7 @@ export class Viewport { // Allow the SVG dimensions to be computed // Quick fix for SVG manipulation issues. - setTimeout(() => this.enableZoom(), 0); + setTimeout(() => this.enableZoom(options), 0); this.bindClick(); this.bindHover(); @@ -66,13 +67,14 @@ export class Viewport { this.resizeObserver.observe(this.container); } - enableZoom() { + enableZoom(options: SvgPanZoom.Options = {}) { const svgHeight = this.$svg['height'].baseVal.value; const svgWidth = this.$svg['width'].baseVal.value; const bbRect = this.container.getBoundingClientRect(); this.maxZoom = Math.max(svgHeight / bbRect.height, svgWidth / bbRect.width); this.zoomer = svgPanZoom(this.$svg, { + ...options, zoomScaleSensitivity: 0.25, minZoom: 0.95, maxZoom: this.maxZoom, From 899ca930ec7ba8b9a6e50aebe1db8aff16c58bf5 Mon Sep 17 00:00:00 2001 From: Alexandr Marchenko Date: Wed, 1 Jan 2025 08:55:01 +0200 Subject: [PATCH 2/3] readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 945c413b..e4170eda 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ module system it is exported as `GraphQLVoyager` global variable. - `hideDocs` [`boolean`, default `false`] - hide the docs sidebar - `hideSettings` [`boolean`, default `false`] - hide settings panel - `hideVoyagerLogo` [`boolean`, default `true`] - hide voyager logo +- `disableMouseWheelZoom` [`boolean`, default `false`] - disables scroll handler ## Using pre-bundled version From cbe278b14be8f62e5d0c2752a554209e7ac6170a Mon Sep 17 00:00:00 2001 From: Alexandr Marchenko Date: Wed, 1 Jan 2025 09:11:48 +0200 Subject: [PATCH 3/3] fix to make prettier happy --- src/components/GraphViewport.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/GraphViewport.tsx b/src/components/GraphViewport.tsx index e7f280f9..104c5952 100644 --- a/src/components/GraphViewport.tsx +++ b/src/components/GraphViewport.tsx @@ -108,7 +108,11 @@ export default class GraphViewport extends Component< this._containerRef.current!, onSelectNode, onSelectEdge, - { mouseWheelZoomEnabled: this.props.disableMouseWheelZoom ? false : true }, + { + mouseWheelZoomEnabled: this.props.disableMouseWheelZoom + ? false + : true, + }, ); this.setState({ svgViewport }); })