react-d3-tree vs react-flow-renderer vs react-organizational-chart vs react-graph-vis
React Visualization Libraries Comparison
1 Year
react-d3-treereact-flow-rendererreact-organizational-chartreact-graph-visSimilar Packages:
What's React Visualization Libraries?

These libraries are designed to help developers create visual representations of data structures, workflows, and organizational hierarchies within React applications. They provide various features for rendering trees, graphs, and flow diagrams, enabling users to visualize complex relationships and data in an intuitive manner. Each library has its unique strengths and use cases, making them suitable for different types of projects and requirements.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-d3-tree139,4371,126121 kB1444 days agoMIT
react-flow-renderer133,07927,9971.6 MB128-MIT
react-organizational-chart37,044184494 kB152 years agoMIT
react-graph-vis18,094971-604 years agoMIT
Feature Comparison: react-d3-tree vs react-flow-renderer vs react-organizational-chart vs react-graph-vis

Customization Options

  • react-d3-tree:

    react-d3-tree offers extensive customization options for both nodes and links, allowing developers to style elements using CSS and customize the rendering logic. You can define custom node types and control the layout of the tree, making it highly adaptable to different data structures.

  • react-flow-renderer:

    react-flow-renderer provides a rich set of customization features, including node types, edge types, and styling options. It allows for the creation of custom components for nodes and edges, enabling developers to design unique visual elements that fit their application's theme.

  • react-organizational-chart:

    react-organizational-chart offers basic customization options primarily focused on styling the organizational chart. You can customize node appearance and layout, but it is less flexible compared to other libraries when it comes to advanced visual features.

  • react-graph-vis:

    react-graph-vis allows customization of graph elements such as nodes, edges, and labels. You can easily modify the appearance and behavior of graph components, including colors, shapes, and interactivity, making it versatile for various visualization needs.

Ease of Use

  • react-d3-tree:

    react-d3-tree is relatively easy to use for developers familiar with D3.js. It abstracts some complexities of D3 while still allowing access to its powerful features, making it approachable for those who want to create tree visualizations without deep D3 knowledge.

  • react-flow-renderer:

    react-flow-renderer is designed with usability in mind, providing a straightforward API that simplifies the process of creating and managing flow diagrams. Its drag-and-drop interface enhances user experience, making it easy to build complex workflows quickly.

  • react-organizational-chart:

    react-organizational-chart is very easy to implement, especially for those needing to display simple organizational structures. Its API is straightforward, allowing developers to create charts with minimal code.

  • react-graph-vis:

    react-graph-vis is user-friendly and integrates seamlessly with vis.js, which is known for its simplicity. Developers can quickly set up graph visualizations with minimal configuration, making it accessible for quick implementations.

Performance

  • react-d3-tree:

    react-d3-tree is optimized for performance with large datasets, leveraging D3's efficient rendering capabilities. However, performance may vary depending on the complexity of the tree and the number of nodes rendered.

  • react-flow-renderer:

    react-flow-renderer is built for performance, handling large numbers of nodes and edges efficiently. It uses React's reconciliation process to minimize re-renders, ensuring smooth interactions even with complex diagrams.

  • react-organizational-chart:

    react-organizational-chart performs well for small to medium-sized organizational charts but may struggle with very large hierarchies. It is best suited for straightforward use cases where performance is not a critical concern.

  • react-graph-vis:

    react-graph-vis performs well with moderate-sized graphs but may experience performance issues with very large datasets due to the overhead of managing many nodes and edges. Optimizations can be made by limiting the number of visible elements at any one time.

Interactivity

  • react-d3-tree:

    react-d3-tree supports interactivity, allowing users to click on nodes to reveal additional information or perform actions. This feature enhances user engagement and makes the tree more informative.

  • react-flow-renderer:

    react-flow-renderer excels in interactivity, offering features like drag-and-drop, zooming, and panning. Users can interact with nodes and edges dynamically, making it ideal for applications that require user input and manipulation.

  • react-organizational-chart:

    react-organizational-chart offers basic interactivity, such as clicking on nodes to display additional details. However, it lacks the advanced interactive features found in other libraries, making it less suitable for highly interactive applications.

  • react-graph-vis:

    react-graph-vis provides interactive capabilities, allowing users to click and drag nodes, zoom in and out, and manipulate the graph dynamically. This makes it suitable for applications that require user interaction with the data.

Integration

  • react-d3-tree:

    react-d3-tree can be integrated with other D3 visualizations, allowing developers to create comprehensive data visualizations that include trees alongside other chart types. This makes it a good choice for projects requiring diverse visual representations.

  • react-flow-renderer:

    react-flow-renderer can be easily integrated with other libraries and frameworks, making it versatile for building complex applications. Its modular design allows for seamless integration with state management libraries and other UI components.

  • react-organizational-chart:

    react-organizational-chart is primarily focused on organizational charts and may not integrate as seamlessly with other visualization libraries. It is best used in scenarios where organizational structures are the primary focus.

  • react-graph-vis:

    react-graph-vis integrates smoothly with vis.js, enabling developers to leverage the full power of the vis.js library for graph visualizations. This makes it a strong choice for projects that require advanced graph features.

How to Choose: react-d3-tree vs react-flow-renderer vs react-organizational-chart vs react-graph-vis
  • react-d3-tree:

    Choose react-d3-tree if you need to create interactive tree diagrams with D3.js integration. It is ideal for visualizing hierarchical data structures and offers a variety of customization options for nodes and links.

  • react-flow-renderer:

    Select react-flow-renderer if you are looking to build flow-based applications or workflows. It provides a flexible API for creating and managing nodes and edges, making it suitable for applications like flowcharts, mind maps, and process diagrams.

  • react-organizational-chart:

    Use react-organizational-chart if you need to create organizational charts specifically. It is straightforward to implement and is tailored for displaying hierarchical relationships within organizations.

  • react-graph-vis:

    Opt for react-graph-vis if you require a library that can handle complex graph visualizations with ease. It integrates with the vis.js library, allowing for dynamic and interactive graph displays, which is perfect for social networks or relationship mapping.

README for react-d3-tree

React D3 Tree

build status coverage status npm package npm package: downloads monthly npm package: minzipped size npm package: types code style: prettier

👾 Playground

📖 API Documentation (v3)

React D3 Tree is a React component that lets you represent hierarchical data (e.g. family trees, org charts, file directories) as an interactive tree graph with minimal setup, by leveraging D3's tree layout.

Upgrading from v1? Check out the v2 release notes.

Legacy v1 docs

Contents

Installation

npm i --save react-d3-tree

Usage

import React from 'react';
import Tree from 'react-d3-tree';

// This is a simplified example of an org chart with a depth of 2.
// Note how deeper levels are defined recursively via the `children` property.
const orgChart = {
  name: 'CEO',
  children: [
    {
      name: 'Manager',
      attributes: {
        department: 'Production',
      },
      children: [
        {
          name: 'Foreman',
          attributes: {
            department: 'Fabrication',
          },
          children: [
            {
              name: 'Worker',
            },
          ],
        },
        {
          name: 'Foreman',
          attributes: {
            department: 'Assembly',
          },
          children: [
            {
              name: 'Worker',
            },
          ],
        },
      ],
    },
  ],
};

export default function OrgChartTree() {
  return (
    // `<Tree />` will fill width/height of its container; in this case `#treeWrapper`.
    <div id="treeWrapper" style={{ width: '50em', height: '20em' }}>
      <Tree data={orgChart} />
    </div>
  );
}

Props

For details on all props accepted by Tree, check out the TreeProps reference docs.

The only required prop is data, all other props on Tree are optional/pre-defined (see "Default value" on each prop definition).

Working with the default Tree

react-d3-tree provides default implementations for Tree's nodes & links, which are intended to get you up & running with a working tree quickly.

This section is focused on explaining how to provide data, styles and event handlers for the default Tree implementation.

Need more fine-grained control over how nodes & links appear/behave? Check out the Customizing the Tree section below.

Providing data

By default, Tree expects each node object in data to implement the RawNodeDatum interface:

interface RawNodeDatum {
  name: string;
  attributes?: Record<string, string | number | boolean>;
  children?: RawNodeDatum[];
}

The orgChart example in the Usage section above is an example of this:

  • Every node has at least a name. This is rendered as the node's primary label.
  • Some nodes have attributes defined (the CEO node does not). The key-value pairs in attributes are rendered as a list of secondary labels.
  • Nodes can have further RawNodeDatum objects nested inside them via the children key, creating a hierarchy from which the tree graph can be generated.

Styling Nodes

Tree provides the following props to style different types of nodes, all of which use an SVG circle by default:

  • rootNodeClassName - applied to the root node.
  • branchNodeClassName - applied to any node with 1+ children.
  • leafNodeClassName - applied to any node without children.

To visually distinguish these three types of nodes from each other by color, we could provide each with their own class:

/* custom-tree.css */

.node__root > circle {
  fill: red;
}

.node__branch > circle {
  fill: yellow;
}

.node__leaf > circle {
  fill: green;
  /* Let's also make the radius of leaf nodes larger */
  r: 40;
}
import React from 'react';
import Tree from 'react-d3-tree';
import './custom-tree.css';

// ...

export default function StyledNodesTree() {
  return (
    <div id="treeWrapper" style={{ width: '50em', height: '20em' }}>
      <Tree
        data={data}
        rootNodeClassName="node__root"
        branchNodeClassName="node__branch"
        leafNodeClassName="node__leaf"
      />
    </div>
  );
}

For more details on the className props for nodes, see the TreeProps reference docs.

Styling Links

Tree provides the pathClassFunc property to pass additional classNames to every link to be rendered.

Each link calls pathClassFunc with its own TreeLinkDatum and the tree's current orientation. Tree expects pathClassFunc to return a className string.

function StyledLinksTree() {
  const getDynamicPathClass = ({ source, target }, orientation) => {
    if (!target.children) {
      // Target node has no children -> this link leads to a leaf node.
      return 'link__to-leaf';
    }

    // Style it as a link connecting two branch nodes by default.
    return 'link__to-branch';
  };

  return (
    <Tree
      data={data}
      // Statically apply same className(s) to all links
      pathClassFunc={() => 'custom-link'}
      // Want to apply multiple static classes? `Array.join` is your friend :)
      pathClassFunc={() => ['custom-link', 'extra-custom-link'].join(' ')}
      // Dynamically determine which `className` to pass based on the link's properties.
      pathClassFunc={getDynamicPathClass}
    />
  );
}

For more details, see the PathClassFunction reference docs.

Event Handlers

Tree exposes the following event handler callbacks by default:

Note: Nodes are expanded/collapsed whenever onNodeClick fires. To prevent this, set the collapsible prop to false.
onNodeClick will still fire, but it will not change the target node's expanded/collapsed state.

Customizing the Tree

renderCustomNodeElement

The renderCustomNodeElement prop accepts a custom render function that will be used for every node in the tree.

Cases where you may find rendering your own Node element useful include:

  • Using a different SVG tag for your nodes (instead of the default <circle>) - Example (codesandbox.io)
  • Gaining fine-grained control over event handling (e.g. to implement events not covered by the default API) - Example (codesandbox.io)
  • Building richer & more complex nodes/labels by leveraging the foreignObject tag to render HTML inside the SVG namespace - Example (codesandbox.io)

pathFunc

The pathFunc prop accepts a predefined PathFunctionOption enum or a user-defined PathFunction.

By changing or providing your own pathFunc, you are able to change how links between nodes of the tree (which are SVG path tags under the hood) are drawn.

The currently available enums are:

  • diagonal (default)
  • elbow
  • straight
  • step

Want to see how each option looks? Try them out on the playground.

Providing your own pathFunc

If none of the available path functions suit your needs, you're also able to provide a custom PathFunction:

function CustomPathFuncTree() {
  const straightPathFunc = (linkDatum, orientation) => {
    const { source, target } = linkDatum;
    return orientation === 'horizontal'
      ? `M${source.y},${source.x}L${target.y},${target.x}`
      : `M${source.x},${source.y}L${target.x},${target.y}`;
  };

  return (
    <Tree
      data={data}
      // Passing `straight` function as a custom `PathFunction`.
      pathFunc={straightPathFunc}
    />
  );
}

For more details, see the PathFunction reference docs.

Development

Setup

To set up react-d3-tree for local development, clone the repo and follow the steps below:

# 1. Set up the library, create a reference to it for symlinking.
cd react-d3-tree
npm i
npm link

# 2. Set up the demo/playground, symlink to the local copy of `react-d3-tree`.
cd demo
npm i
npm link react-d3-tree

Tip: If you'd prefer to use your own app for development instead of the demo, simply run npm link react-d3-tree in your app's root folder instead of the demo's :)

Hot reloading

npm run build:watch

If you're using react-d3-tree/demo for development, open up another terminal window in the demo directory and call:

npm start

Contributors

A huge thank you to all the contributors, as well as users who have opened issues with thoughtful suggestions and feedback.