@vx/network

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

Example Usage

import { Graph, DefaultLink, DefaultNode } from '@vx/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 @vx/network

Examples

Components

APIs

#<Graph />

# Graph.graphGraph<Link, Node>optional

Graph to render nodes and links for.

# Graph.leftnumberoptional

Left transform offset to apply to links and nodes.

# Graph.linkComponentstring | FunctionComponent<LinkProvidedProps<Link>> | ComponentClass<LinkProvidedProps<Link>, any>optional

Component for rendering a single Link.

# Graph.nodeComponentstring | FunctionComponent<NodeProvidedProps<Node>> | ComponentClass<NodeProvidedProps<Node>, any>optional

Component for rendering a single Node.

# Graph.topnumberoptional

Top transform offset to apply to links and nodes.

#<Nodes />

# Nodes.classNamestringoptional

Classname to add to each node parent g element.

# Nodes.nodeComponentstring | FunctionComponent<NodeProvidedProps<Node>> | ComponentClass<NodeProvidedProps<Node>, any>optional

Component for rendering a single link.

# Nodes.nodesNode[]optional

Array of links to render.

Default []

# Nodes.x(d: Node) => numberoptional

Returns the center x coordinate of a node.

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

# Nodes.y(d: Node) => numberoptional

Returns the center y coordinate of a node.

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

#<Links />

# Links.linkComponentstring | FunctionComponent<LinkProvidedProps<Link>> | ComponentClass<LinkProvidedProps<Link>, any>required

Component for rendering a single link.

# Links.classNamestringoptional

Classname to add to each link parent g element.

# Links.linksLink[]optional

Array of links to render.

Default []

#<DefaultNode />

# DefaultNode.cxnumberoptional
# DefaultNode.cynumberoptional

#<DefaultLink />

# DefaultLink.linkanyrequired