I Built an Interactive SVG Viewer Because Static Diagrams Deserve Better

Published: (February 11, 2026 at 08:23 AM EST)
4 min read
Source: Dev.to

Source: Dev.to

I Built an Interactive SVG Viewer Because Static Diagrams Deserve Better

Cover image for I Built an Interactive SVG Viewer Because Static Diagrams Deserve Better

Khadirullah Mohammad


As developers, we love clear documentation. Use‑case diagrams, cloud architectures, flowcharts — they are the lifeblood of understanding complex systems. Tools like Mermaid.js, PlantUML, and Draw.io are fantastic for creating them.

But viewing them? That experience is often stuck in the past.

If you export a complex architecture diagram as an SVG and embed it on your docs site, it’s just a static image. The text is too small to read, you can’t search for that one specific micro‑service, and if you zoom with your browser the whole page breaks.

I looked for a library to solve this. I found D3.js (too complex for just viewing) and Leaflet (too heavy for a diagram). I didn’t want to write hundreds of lines of code just to let a user zoom into a flowchart.

So, I built DiagView.


Demo

DiagView Demo


What is DiagView?

DiagView is a feature‑rich, interactive wrapper that gives your static SVGs superpowers.

It is built on top of the excellent panzoom library, which handles the low‑level matrix math for smooth 60 fps zooming and panning. While panzoom gives you the engine, DiagView gives you the entire car.


Feature Overview

FeatureDescription
🔍 Deep SearchTraverses the SVG DOM to find and highlight matching nodes
📤 Multi‑Format ExportPNG, SVG, PDF, WebP, or copy to clipboard
🎯 Meeting ModeBuilt‑in laser pointer for remote presentations
🔗 Share LinksGenerate URLs that preserve zoom/pan state
⌨️ Keyboard NavigationArrows to pan, +/- to zoom, F to search
🌗 Auto‑ThemingDetects light/dark mode automatically
📱 Mobile‑First TouchPinch‑to‑zoom, double‑tap to reset

The Landscape: Why Wasn’t This Already Solved?

Before writing any code, I scoured npm and GitHub. Here’s what I found:

  • D3.js – The titan of data visualization. Great for creating graphics from data, not for viewing pre‑made SVGs.
  • svg-pan-zoom – Focused library for adding pan/zoom to SVGs. It’s just the engine – no UI, no search, no export.
  • Leaflet.js – Standard for interactive maps. Overkill for a simple flowchart.

The gap was clear: I needed a batteries‑included solution – something that would just work with a single init() call.


Quick Start

CDN (Fastest)


  

  DiagView.init();

NPM

npm install diagview @panzoom/panzoom
import DiagView from 'diagview';

DiagView.init({
  layout: 'floating',
  accentColor: '#3b82f6',
});

Flexible Layouts

DiagView supports three layout modes to fit your design:

Layout Options

LayoutBest For
HeaderClassic top‑bar controls, documentation sites
FloatingClean HUD‑style buttons on hover, minimal UIs
OffInvisible UI; the diagram itself is the trigger

Under the Hood: Technical Decisions

The Search Engine

The feature I’m most proud of. The search system:

  • Pre‑Caches Candidates – On first open, queries all text elements and stores them in a WeakMap.
  • Uses Dirty Checking – Before writing to the DOM, checks if values have changed.
  • Batches Updates – All DOM mutations are wrapped in requestAnimationFrame.

Result: Searching through diagrams with 2,500+ nodes is instant.

The Export System

Handles edge cases:

  • Robust Dimension Calculation – Uses getBBox() to find the actual content area.
  • Cross‑Origin Font Handling – Inlines Google Fonts for consistent exports.
  • High‑DPI Scaling – Up to 6× resolution for print‑quality images.

Optional Panzoom Dependency

Panzoom is an optional peer dependency:

With PanzoomWithout Panzoom
Full zoom, pan, touch gesturesFullscreen, search, and export still work

This keeps DiagView usable even in constrained environments.

Bundle Size

MetricSize
Raw Minified~70 KB
Gzipped(value omitted in original; keep placeholder)

Enjoy smoother, searchable, export‑ready SVG diagrams with DiagView!

(Transfer)
~19 KB

For context, that’s smaller than a single hero image. It includes all CSS, SVG icons, and the entire UI framework.


Try It Out

I built this to scratch my own itch. If you write technical documentation for a living, I think you’ll find it useful too.

🧪 Live Demo:
GitHub:
📦 NPM:

Have feedback or found a bug? Open an issue on GitHub.

Originally published on khadirullah.com

0 views
Back to Blog

Related posts

Read more »

Server Components aren't SSR!

SSR vs. React Server Components In the dev world, React Server Components RSC are often mistaken for just another form of Server‑Side Rendering SSR. While both...

A Beginner’s Guide to ThreeJs

markdown ! https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2...

📦What is Redux?

If you are learning frontend development, especially with React, you may have heard about Redux. It can seem confusing at first, but the core ideas are simple....