@visx/network

A simple package to visualize a network or graph layout. Does not currently handle network layout.

Example Usage

import { Graph, DefaultLink, DefaultNode } from '@visx/network';
const nodes = [
  { x: 50, y: 20 },
  { x: 200, y: 300 },
  { x: 300, y: 40 },
];

const dataSample = {
  nodes,
  links: [
    { source: nodes[0], target: nodes[1] },
    { source: nodes[1], target: nodes[2] },
    { source: nodes[2], target: nodes[0] },
  ],
};

const MyGraph = () => (
  <Graph graph={dataSample} linkComponent={DefaultLink} nodeComponent={DefaultNode} />
);

Installation

npm install --save @visx/network

Examples

APIs

#<Graph />

# graphGraph<Link, Node>

Graph to render nodes and links for.

# leftnumber

Left transform offset to apply to links and nodes.

# linkComponentFunctionComponent<LinkProvidedProps<Link>> | ComponentClass<LinkProvidedProps<Link>, any>

Component for rendering a single Link.

# nodeComponentFunctionComponent<NodeProvidedProps<Node>> | ComponentClass<NodeProvidedProps<Node>, any>

Component for rendering a single Node.

# topnumber

Top transform offset to apply to links and nodes.

#<Nodes />

# classNamestring

Classname to add to each node parent g element.

# nodeComponentFunctionComponent<NodeProvidedProps<Node>> | ComponentClass<NodeProvidedProps<Node>, any>

Component for rendering a single link.

# nodesNode[]

Array of links to render.

Default []

# x(d: Node) => number

Returns the center x coordinate of a node.

Default (d: any) => d?.x || 0

# y(d: Node) => number

Returns the center y coordinate of a node.

Default (d: any) => d?.y || 0

#<Links />

# linkComponentFunctionComponent<LinkProvidedProps<Link>> | ComponentClass<LinkProvidedProps<Link>, any>required

Component for rendering a single link.

# classNamestring

Classname to add to each link parent g element.

# linksLink[]

Array of links to render.

Default []

#<DefaultNode />

# cxnumber
# cynumber

#<DefaultLink />

# linkanyrequired