Skip to content

VivaGraph 1.0: one call draws a graph with ngraph.forcelayout and its view - #286

Merged
anvaka merged 3 commits into
masterfrom
v1
Nov 22, 2026
Merged

anvaka merged 3 commits into
masterfrom
v1

Conversation

@anvaka

@anvaka anvaka commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

VivaGraph becomes the front door to ngraph.forcelayout and the modules next to it. This is a rewrite: nothing of the 0.x code or API is kept. 0.x is preserved on the new 0.x branch.

const graph = Viva.createGraph();
graph.addLink('Alice', 'Bob');
Viva.render(graph);

240 people in six teams

What render() does

It makes the choices the forcelayout demo makes, in about 400 lines (src/render.js):

  • Start: pivot positions, then the force layout with dual tree repulsion.
  • Where it runs: WebGPU for graphs of 2,000 nodes and more when there is a hardware adapter; the CPU otherwise, and whenever the GPU refuses or is lost.
  • Loop: as many steps as fit a frame's budget (1 to 10), stops when the layout settles, wakes when the graph, a setting or a dragged node moves it.
  • Drawing: the view with its style, fit, labels (when nodes have names), hover, drag, select, tooltip, keyboard and search modules.
  • Page: a canvas that fills the window or your element, follows its size and the pixel ratio, and sits under what the element already holds.

Everything it builds stays reachable (viva.layout, viva.view, viva.scene), and the parts are exported.

Builds

File For Size (gzip)
dist/vivagraph.min.js script tag, global Viva, everything inside 773 KB (220 KB)
dist/vivagraph.module.js bundlers and <script type="module"> 800 KB unminified (221 KB)
dist/vivagraph.gpu.js the WebGPU runner, loaded by the module build only when a layout goes to the GPU 552 KB unminified (159 KB)

How the dependencies come in

The view, the WebGPU runner and the pivot start are not on npm. package.json installs the ngraph.forcelayout repository as a tarball of one commit, and src/deps.js reaches into its modules/ folder. Everything is bundled, so the published package would have no dependencies. When the modules are published, only the import paths in src/deps.js and src/gpu.js change.

The pinned commit is ngraph.forcelayout's main at 6818df8: version 4.0.0, with the fix for almost transparent links on small graphs (anvaka/ngraph.forcelayout#127, found here).

Checks

  • npm test: 11 unit tests pass (Node).
  • npm run test:browser: 8 tests pass in headless Chrome 146 on an M4 Max, on the built files. They cover the script-tag and module builds, a container, pause, resume, restart, dispose, a growing graph, an empty graph, every recipe in the README, and WebGPU (start, restart, dispose).
  • The five pages in examples/ render without console errors; I looked at each screenshot.
  • CI (Ubuntu, Node 20, 22 and 24) passes, browser tests included. The runners have no hardware WebGPU, so there the tests cover the fall back to the CPU.
  • Not checked: any browser other than Chrome, and a real phone.

Decisions for the author

  • Custom SVG nodes are gone. Pages that draw nodes as their own SVG or images have no path to 1.0; the README tells them to stay on vivagraphjs@0.
  • The license stays BSD-3 here, while ngraph.forcelayout and its modules are MIT.
  • GitHub Pages still serves the 0.x demos from gh-pages. Nothing here touches it; the new examples are not deployed.
  • Publishing (npm publish, and whether as 1.0.0-alpha.0 under a next tag first) is left to you.

🤖 Generated with Claude Code

… view

A rewrite. Viva.render(graph) puts together ngraph.forcelayout and the add-on
modules of its repository, with the choices their demo makes: pivot start,
dual tree repulsion, WebGPU for graphs of 2,000 nodes and more on a hardware
adapter, automatic steps per frame, stop when settled, WebGL drawing, labels
for named nodes, hover, drag, select, tooltips, search and keyboard navigation.

- src/render.js is the entry point; the parts are exported too.
- dist/ has a script-tag build (global Viva) and an ES module whose WebGPU
  runner is a second file, loaded on demand.
- The add-on modules are not on npm yet: package.json installs the
  ngraph.forcelayout repository at a pinned commit, and everything is bundled.
- Tests: unit tests in Node, and the built library in headless Chrome.
- The 0.x sources are removed here; they stay on the 0.x branch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@socket-security

socket-security Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedw-gl@​0.21.1801008779100
Updatedngraph.events@​0.0.4 ⏵ 1.4.0100 +110094 +780 -2100
Updatedngraph.graph@​0.0.14 ⏵ 20.1.2100 +1100100 +182100
Added@​rollup/​plugin-node-resolve@​16.0.39910010084100
Added@​rollup/​plugin-commonjs@​29.0.39910010086100
Addedterser@​5.51.410010010094100
Addedpuppeteer-core@​25.18.1951009597100
Addedrollup@​4.68.89610010099100
Updatedngraph.forcelayout@​0.5.0 ⏵ 4.0.0N/AN/AN/AN/AN/A

View full report

anvaka and others added 2 commits November 21, 2026 22:23
…link fix

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…y notices

The README and the changelog now describe 1.0.0-alpha.0 under npm's `next` tag:
`npm install vivagraphjs` keeps installing 0.12.

dist/ contains gl-matrix and bezier-easing (MIT, inlined by w-gl's build) without their
notices, so the package now ships THIRD-PARTY-NOTICES.md with both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anvaka
anvaka marked this pull request as ready for review November 22, 2026 12:58
@anvaka
anvaka merged commit cd38fe1 into master Nov 22, 2026
5 checks passed
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.

1 participant