npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

graphwagu

v1.0.0

Published

A GPU-accelerated force-directed graph layout algorithm using WebGPU. Layouts are computed fully on GPU with Barnes-Hut Approximation.

Readme

ForceDirected API Reference

A GPU-accelerated force-directed graph layout algorithm using WebGPU. Layouts are computed fully on GPU with Barnes-Hut Approximation.

Installation

npm install graphwagu

Usage

import { ForceDirected } from 'graphwagu';

// Initialize with WebGPU device (with limits available to your hardware)
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice({
    requiredLimits: {
        maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
        maxComputeWorkgroupsPerDimension: adapter.limits.maxComputeWorkgroupsPerDimension,
        maxBufferSize: adapter.limits.maxBufferSize,
        maxComputeInvocationsPerWorkgroup: adapter.limits.maxComputeInvocationsPerWorkgroup,
        maxComputeWorkgroupStorageSize: adapter.limits.maxComputeWorkgroupStorageSize
    }}
);
const forceDirected = new ForceDirected(device);

// Set node and edge data
const nodes = [
  /* value, x, y, size for each node */
  0, 0.2, 0.1, 0,
  0, 0.5, -0.1, 0,
  // ...
];
const edges = [
  /* source, target pairs */
  0, 1,  // Edge from node 0 to node 1
  1, 2,  // Edge from node 1 to node 2
  // ...
];

forceDirected.setNodeEdgeData(nodes, edges);

// Run the simulation
await forceDirected.runForces();

// Updated node positions are in forceDirected.nodeDataBuffer (GPUBuffer)

Class: ForceDirected

Constructor

new ForceDirected(device: GPUDevice)

Creates a new ForceDirected instance.

Parameters:

  • device - A WebGPU device instance

Example:

const forceDirected = new ForceDirected(device);

Properties

coolingFactor: number

The cooling factor applied to the simulation (default: 0.985). Controls how quickly the simulation stabilizes.

theta: number

The theta parameter for Barnes-Hut approximation (default: 0.8). Lower values increase accuracy but decrease performance.

l: number

The ideal edge length parameter (default: 0.01).

iterationCount: number

The number of iterations to run in one call to runForces() (default: 1).

Methods

setNodeEdgeData(nodes: number[], edges: number[]): void

Sets the node and edge data for the simulation.

Parameters:

  • nodes - Array of node data in format [value, x, y, size, value, x, y, size, ...] where each group of 4 represents position (x, y) along with size and value (TODO: have size and value affect simulation) of a node
  • edges - Array of edge data in format [source, target, source, target, ...] where each pair represents an edge between two nodes

Example:

const nodes = [
  0, 0.2, 0.1, 0, // Node 0: position (0.2, 0.1)
  0, 0.5, -0.1, 0, // Node 1: position (0.5, -0.1)
];
const edges = [
  0, 1,  // Edge between node 0 and 1
];
forceDirected.setNodeEdgeData(nodes, edges);

runForces(coolingFactor?: number, l?: number, theta?: number, iterationCount?: number): Promise<void>

Runs the force-directed simulation.

Parameters:

  • coolingFactor - Optional cooling factor (default: uses class property)
  • l - Optional ideal edge length (default: uses class property)
  • theta - Optional approximation parameter (default: uses class property)
  • iterationCount - Optional number of iterations (default: uses class property)

Returns: Promise that resolves when simulation is complete

Example:

// Run with default parameters
await forceDirected.runForces();

// Run with custom parameters
await forceDirected.runForces(0.99, 0.1, 1.5, 100);

Requirements

  • WebGPU-compatible browser
  • Access to navigator.gpu API