Skip to content

Add pan and zoom to DAG preview - #46

Merged
bentsherman merged 1 commit into
mainfrom
dag-preview-pan-and-zoom
Sep 15, 2026
Merged

bentsherman merged 1 commit into
mainfrom
dag-preview-pan-and-zoom

Conversation

@bentsherman

@bentsherman bentsherman commented Nov 4, 2024

Copy link
Copy Markdown
Member

Adds pan and zoom to the DAG preview webview.

The original version of this PR used svg-pan-zoom, which rewrites the SVG's viewBox and so needs a sized SVG to work against. That forced mermaid.render() instead of startOnLoad, a custom events handler to re-add dragging, and a hardcoded height: 1024px. It also predates the bundled Mermaid and the webview CSP, both of which it would now conflict with.

This version drops the library. The <pre class="mermaid"> goes inside a .viewport div (flex: 1; overflow: hidden) and pan/zoom is a CSS transform on the pre, driven by ~50 lines of vanilla JS. No dependency, no CSP change, startOnLoad untouched. The height is no longer fixed: the body is a flex column at 100vh and the viewport takes whatever is left.

Keeping the transform on the wrapper rather than the viewBox means Export as SVG still serializes the unzoomed diagram instead of baking in the current zoom level. Panning uses window listeners rather than setPointerCapture, which would retarget the subsequent click to the viewport and break click-to-open-file; a drag of more than 4px swallows the click so panning doesn't open files by accident.

Pan/zoom is webview-only, passed through htmlHead's extra parameter. The standalone HTML export is left alone since browsers already scroll and zoom it.

Controls: drag to pan, scroll to zoom at the cursor (clamped 0.1x-20x), double-click to reset.

@alvaromartmart

Copy link
Copy Markdown

Years ago I did a proof of concept of displaying nextflow DAG svg using OpenSeadragon, you can find it here. OpenSeadragon might be a bit overkill for this purpose (or not) but worth checking as the setup could be quite easy and it handles pan, zoom etc (even minimaps) out of the box.

@bentsherman bentsherman changed the title Add pan anz zoom to DAG preview Add pan and zoom to DAG preview Nov 12, 2024
@bentsherman
bentsherman force-pushed the dag-preview-pan-and-zoom branch from 87caa77 to 786ab69 Compare September 15, 2026 19:28
@bentsherman
bentsherman marked this pull request as ready for review September 15, 2026 19:37
@bentsherman
bentsherman merged commit c7d8c2d into main Sep 15, 2026
3 checks passed
@bentsherman
bentsherman deleted the dag-preview-pan-and-zoom branch September 15, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants