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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@petrarca/sonnet-graph

v0.4.2

Published

Renderer-agnostic graph visualization, exploration, and enrichment for the Petrarca Sonnet component library

Readme

@petrarca/sonnet-graph

Renderer-agnostic property graph visualization, exploration, and enrichment for the Petrarca Sonnet component library.

What's included

GraphVisualizer — Main visualization component. Renders a property graph using the active renderer (Cytoscape or Reagraph). Supports node/edge selection, focus mode, hide/show, and graph expansion.

ActionPanel — Side panel showing selected node/edge details and graph exploration actions.

GraphA11yList — Accessible DOM mirror of the graph's selectable elements. Cytoscape (canvas) and Reagraph (WebGL) draw nodes/edges outside the DOM, so they are invisible to screen readers, keyboard users, and DOM automation; this renders a virtualized list of node/edge <button>s that drive the same selection store the canvas reads. sr-only by default (real apps); pass visible for an on-screen outline panel.

GraphRendererProvider — Context provider that selects the active renderer ("cytoscape" or "reagraph").

Store factories — Create the Zustand stores the graph components need: createGraphDataStore, createGraphFilterStore, createGraphExplorationStore, createSelectionStore, createGraphFocusStore.

Graph utilitiesenrichNodes, enrichEdges, buildColorPalette for preparing raw graph data before passing it to stores.


Install

pnpm add @petrarca/sonnet-graph

Required peer dependencies

pnpm add react@">=19" react-dom@">=19"

Renderer peer dependencies

Install only the renderers you use:

pnpm add cytoscape          # Cytoscape.js renderer
pnpm add reagraph           # Reagraph (3D/WebGL) renderer

If you use @petrarca/sonnet-playground (which includes the graph demo page), both cytoscape and reagraph are required even if your app only uses one renderer.

Cytoscape layout plugins (optional)

Install the layout algorithms you need. All are optional — the graph works without them but with fewer layout options:

pnpm add cytoscape-fcose    # Force-directed, compound graph
pnpm add cytoscape-cola     # Constraint-based
pnpm add cytoscape-dagre    # DAG / hierarchical
pnpm add cytoscape-elk      # Eclipse Layout Kernel
pnpm add cytoscape-cise     # Circular layout
pnpm add cytoscape-klay     # KLay hierarchical
pnpm add cytoscape-cxtmenu  # Context menu extension

Local development with SONNET_UI_LOCAL=1

When resolving @petrarca/sonnet-graph from the local dist (via Vite aliases), the Cytoscape plugins must also be aliased to the consumer's node_modules — Vite cannot find them relative to the dist file. Add to your sonnet-aliases.ts:

const nm = path.resolve(baseDir, "node_modules");
// ...
"cytoscape-fcose": path.resolve(nm, "cytoscape-fcose"),
"cytoscape-cola":  path.resolve(nm, "cytoscape-cola"),
"cytoscape-dagre": path.resolve(nm, "cytoscape-dagre"),
"cytoscape-elk":   path.resolve(nm, "cytoscape-elk"),
"cytoscape-cise":  path.resolve(nm, "cytoscape-cise"),
"cytoscape-klay":  path.resolve(nm, "cytoscape-klay"),
"cytoscape-cxtmenu": path.resolve(nm, "cytoscape-cxtmenu"),

See sonnet-ui-starter/sonnet-aliases.ts for a complete reference implementation.


Basic usage

import {
  GraphVisualizer,
  ActionPanel,
  GraphRendererProvider,
  GraphStoresContext,
  createGraphDataStore,
  createGraphFilterStore,
  createGraphExplorationStore,
  createSelectionStore,
  createGraphFocusStore,
  enrichNodes,
  enrichEdges,
  buildColorPalette,
  type RawGraphNode,
  type RawGraphEdge,
  type WorkspaceStores,
} from "@petrarca/sonnet-graph";

// Create stores once (e.g. in a context provider)
const stores: WorkspaceStores = {
  graphData:        createGraphDataStore(),
  graphFilter:      createGraphFilterStore(),
  graphExploration: createGraphExplorationStore(),
  selection:        createSelectionStore(),
  graphFocus:       createGraphFocusStore(),
};

// Render
function MyGraph() {
  return (
    <GraphStoresContext.Provider value={stores}>
      <GraphRendererProvider defaultRenderer="cytoscape">
        <div style={{ display: "flex", height: 600 }}>
          <GraphVisualizer />
          <ActionPanel />
        </div>
      </GraphRendererProvider>
    </GraphStoresContext.Provider>
  );
}

License

See LICENSE.md.