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

translator-graph-view

v0.4.0

Published

React Typescript library for displaying knowledge graphs using ReactFlow and ELKjs.

Readme

translator-graph-view

A React TypeScript component for interactive knowledge graph visualization, designed for use with the NIH's Biomedical Data Translator. Built on ReactFlow and ELKjs.

Renders Biolink Model knowledge graphs with automatic layout, type-based color coding, and interactive selection.

Features

  • Interactive graph visualization with pan, zoom, and selection
  • Five automatic layout algorithms: hierarchical, force-directed, grid, and radial
  • Nodes color-coded by Biolink type
  • Controlled and uncontrolled selection modes
  • Controlled hover state with event callbacks
  • Multi-edge rendering with curved paths for parallel edges
  • Inferred edge styling (dashed stroke)
  • MiniMap and zoom controls
  • Full TypeScript type definitions
  • ESM and CommonJS support

Installation

npm install translator-graph-view elkjs

React 18+ and elkjs 0.9+ are required as peer dependencies.

Usage

import { GraphView } from 'translator-graph-view';
import 'translator-graph-view/styles.css';

const data = {
  nodes: {
    'n1': { id: 'n1', names: ['Aspirin'], types: ['biolink:Drug'] },
    'n2': { id: 'n2', names: ['Headache'], types: ['biolink:Disease'] },
  },
  edges: {
    'e1': { id: 'e1', subject: 'n1', object: 'n2', predicate: 'biolink:treats' },
  },
};

const elkWorkerUrl = new URL('elkjs/lib/elk-worker.min.js', import.meta.url).href;

function App() {
  return (
    <div style={{ width: '100%', height: '600px' }}>
      <GraphView
        data={data}
        layout="hierarchical"
        elkWorkerUrl={elkWorkerUrl}
        onNodeClick={(node) => console.log('Clicked:', node)}
        onSelectionChange={(selection) => console.log('Selected:', selection)}
      />
    </div>
  );
}

The GraphView container must have a defined width and height.

API

<GraphView />

| Prop | Type | Default | Description | |------|------|---------|-------------| | data | GraphData | required | Graph nodes and edges | | elkWorkerUrl | string | required | URL to the ELKjs web worker script (see below) | | layout | LayoutType | 'hierarchical' | Layout algorithm | | onSelectionChange | (selection: Selection) => void | - | Fires when selection changes | | onNodeClick | (node: GraphNode) => void | - | Fires when a node is clicked | | onEdgeClick | (edge: GraphEdge) => void | - | Fires when an edge is clicked | | onNodeHover | (node: GraphNode \| null, geometry: HoverGeometry \| null) => void | - | Fires when a node is hovered or unhovered | | onEdgeHover | (edge: GraphEdge \| null, geometry: HoverGeometry \| null) => void | - | Fires when an edge is hovered or unhovered | | hoveredNodeId | string \| null | - | Controlled hover: highlights the given node | | hoveredEdgeId | string \| null | - | Controlled hover: highlights the given edge | | nodeHoverAnchor | HoverAnchorPosition | 'topCenter' | Anchor point returned in HoverGeometry for node hovers | | edgeHoverAnchor | HoverAnchorPosition | 'midpoint' | Anchor point returned in HoverGeometry for edge hovers | | selectedIds | string[] | - | Controlled selection by node/edge ID | | edgeType | EdgeType | 'straight' | Edge path style: 'bezier', 'straight', 'step', or 'smoothstep' | | showEdgeLabels | boolean | true | Show predicate labels on edges | | multiEdgeSpacing | number | 60 | Pixel spacing between parallel edges sharing the same node pair | | className | string | - | Additional CSS class for the container |

elkWorkerUrl

Layout computation is offloaded to a web worker, keeping the ~1.5 MB ELK engine out of your main bundle. You must provide a URL pointing to the ELK worker script. In Vite-based apps:

const elkWorkerUrl = new URL('elkjs/lib/elk-worker.min.js', import.meta.url).href;

For webpack or other bundlers, serve node_modules/elkjs/lib/elk-worker.min.js as a static asset and pass its URL.

Hover

The component supports both uncontrolled hover (internal styling only) and controlled hover (you drive the highlight state from outside). Use controlled hover to synchronize highlights between the graph and an external UI like a sidebar or detail panel.

Uncontrolled — nodes and edges show hover styles on mouseover with no props needed.

Outbound events — use onNodeHover / onEdgeHover to react to hover changes:

const [hoveredNode, setHoveredNode] = useState<GraphNode | null>(null);

<GraphView
  data={data}
  elkWorkerUrl={elkWorkerUrl}
  onNodeHover={(node) => setHoveredNode(node)}
/>

{hoveredNode && <div>Hovering: {hoveredNode.names[0]}</div>}

Controlled (bidirectional) — pass hoveredNodeId / hoveredEdgeId to drive highlights from external UI (e.g. a sidebar list), and use onNodeHover / onEdgeHover to update that state when the user hovers inside the graph:

const [hoveredNodeId, setHoveredNodeId] = useState<string | null>(null);

// Sidebar list item triggers graph highlight
<li
  onMouseEnter={() => setHoveredNodeId(node.id)}
  onMouseLeave={() => setHoveredNodeId(null)}
>
  {node.names[0]}
</li>

// Graph triggers sidebar highlight
<GraphView
  data={data}
  elkWorkerUrl={elkWorkerUrl}
  hoveredNodeId={hoveredNodeId}
  onNodeHover={(node) => setHoveredNodeId(node?.id ?? null)}
/>

Hover geometry

The onNodeHover and onEdgeHover callbacks receive a second HoverGeometry argument containing the hovered element's bounding rect and a pre-computed anchor point in viewport coordinates — useful for positioning tooltips without querying the DOM yourself.

import type { GraphNodeType, HoverGeometry } from 'translator-graph-view';

<GraphView
  data={data}
  elkWorkerUrl={elkWorkerUrl}
  nodeHoverAnchor="topCenter"
  onNodeHover={(node, geometry) => {
    if (node && geometry) {
      showTooltip({ x: geometry.anchor.x, y: geometry.anchor.y });
    } else {
      hideTooltip();
    }
  }}
/>

HoverAnchorPosition can be one of: 'topLeft', 'topCenter', 'topRight', 'centerLeft', 'center', 'centerRight', 'bottomLeft', 'bottomCenter', 'bottomRight', or 'midpoint' (edges only — computes the true midpoint of the SVG path).

When the hover callback fires with null (mouse leaves), geometry is also null. If DOM measurement fails (e.g. SSR), geometry is null.

While the pointer stays over the same node or edge, geometry is re-measured on pan and zoom (throttled with requestAnimationFrame) so anchors stay aligned with the viewport.

DOM queries are scoped to this GraphView instance, so multiple graphs on one page do not pick each other’s elements. Element ids are escaped for attribute selectors (CSS.escape when available).

Multi-edge rendering

When multiple edges connect the same pair of nodes, they automatically spread into distinct quadratic bezier curves. Control the spacing with multiEdgeSpacing (default 60px).

Inferred edges

Edges with inferred: true in the data render with a dashed stroke to visually distinguish them from direct evidence edges.

Layout types

  • 'hierarchical' - Layered top-to-bottom (default)
  • 'hierarchicalLR' - Layered left-to-right
  • 'force' - Force-directed
  • 'grid' - Box/grid
  • 'radial' - Radial/circular

Data format

interface GraphData {
  nodes: Record<string, GraphNode>;
  edges: Record<string, GraphEdge>;
}

interface GraphNode {
  id: string;
  names: string[];
  types: string[];       // e.g. ['biolink:Drug']
  curies?: string[];
}

interface GraphEdge {
  id: string;
  subject: string;       // source node ID
  object: string;        // target node ID
  predicate: string;     // e.g. 'biolink:treats'
  inferred?: boolean;    // renders with dashed stroke when true
}

Hooks

  • useGraphLayout({ nodes, edges, layout, elkWorkerUrl }) - Computes ELK layout positions for ReactFlow nodes/edges via a web worker
  • useSelection({ data, onSelectionChange }) - Manages node/edge selection state

Utilities

  • transformNodesToFlow(data) / transformEdgesToFlow(data) - Convert GraphData to ReactFlow format
  • getColorForType(type) - Get a consistent color for a Biolink type string
  • simplifyTypeName(type) - Extract a readable name from a Biolink URI
  • getNodesById(data, ids) / getEdgesById(data, ids) - Look up nodes/edges by ID

Development

npm install
npm run dev        # Start dev server with example app
npm run build      # Build the library
npm run typecheck  # Type-check without emitting

License

MIT