react-treebeard vs react-d3-tree
React Tree Visualization Libraries
react-treebeardreact-d3-treeSimilar Packages:

React Tree Visualization Libraries

React tree visualization libraries are specialized tools designed to represent hierarchical data structures in a visually appealing manner. They enable developers to create interactive tree diagrams that can display relationships and data hierarchies effectively. These libraries are particularly useful in applications that require data representation such as organizational charts, file explorers, or any nested data structure. The choice between different libraries often depends on the specific needs for customization, performance, and ease of use in rendering complex data structures.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-treebeard67,5931,692-727 years agoMIT
react-d3-tree01,191121 kB148a year agoMIT

Feature Comparison: react-treebeard vs react-d3-tree

Customization

  • react-treebeard:

    react-treebeard provides a simpler customization interface, focusing on basic styling and behavior adjustments. While it allows for some level of customization, it is less flexible than react-d3-tree, making it more suitable for straightforward tree visualizations.

  • react-d3-tree:

    react-d3-tree offers extensive customization options through D3.js, allowing developers to manipulate styles, shapes, and animations at a granular level. This flexibility enables the creation of visually complex and interactive trees that can adapt to various data presentations and user interactions.

Performance

  • react-treebeard:

    react-treebeard performs well with smaller to medium-sized trees but may experience performance issues with very large datasets due to its simpler rendering approach. It is best used when the tree structure is not overly complex.

  • react-d3-tree:

    react-d3-tree is optimized for performance with large datasets, leveraging D3's efficient rendering capabilities. It can handle complex trees with many nodes without significant performance degradation, making it suitable for applications with extensive hierarchical data.

Ease of Use

  • react-treebeard:

    react-treebeard is designed for ease of use and quick integration into projects. Its API is straightforward, making it accessible for developers who may not have extensive experience with tree visualizations or D3.js.

  • react-d3-tree:

    react-d3-tree has a steeper learning curve due to its reliance on D3.js, which requires familiarity with data-driven documents and SVG manipulation. Developers may need to invest more time in understanding how to effectively use the library and D3's concepts.

Interactivity

  • react-treebeard:

    react-treebeard offers basic interactivity, such as expanding and collapsing nodes, but lacks the depth of interaction found in react-d3-tree. It is suitable for applications where simple tree navigation is sufficient.

  • react-d3-tree:

    react-d3-tree supports advanced interactivity features, including drag-and-drop functionality, zooming, and panning. This makes it ideal for applications that require user interaction with the tree structure, enhancing the overall user experience.

Community and Support

  • react-treebeard:

    react-treebeard has a smaller community compared to react-d3-tree, which may result in fewer resources and examples available for troubleshooting. However, it still has sufficient documentation to assist developers in getting started.

  • react-d3-tree:

    react-d3-tree benefits from the large D3.js community, providing access to a wealth of resources, examples, and support. This can be advantageous for developers looking to implement complex visualizations and needing guidance.

How to Choose: react-treebeard vs react-d3-tree

  • react-treebeard:

    Choose react-treebeard if you prefer a simpler, more straightforward implementation for displaying tree structures. It is well-suited for applications that require basic tree functionality with a focus on ease of use and quick setup, making it a good choice for smaller projects or when rapid development is a priority.

  • react-d3-tree:

    Choose react-d3-tree if you need a highly customizable and flexible tree visualization that leverages D3.js for rendering. It is ideal for developers looking for extensive control over the appearance and behavior of the tree, as well as those who require advanced features like animations and transitions.

README for react-treebeard

react-treebeard

Build Status Coverage Status

React Tree View Component. Data-Driven, Fast, Efficient and Customisable.

Install

npm install react-treebeard --save

Example

An online example from the /example directory can be found here: Here

Quick Start

import React, {PureComponent} from 'react';
import ReactDOM from 'react-dom';
import {Treebeard} from 'react-treebeard';

const data = {
    name: 'root',
    toggled: true,
    children: [
        {
            name: 'parent',
            children: [
                { name: 'child1' },
                { name: 'child2' }
            ]
        },
        {
            name: 'loading parent',
            loading: true,
            children: []
        },
        {
            name: 'parent',
            children: [
                {
                    name: 'nested parent',
                    children: [
                        { name: 'nested child 1' },
                        { name: 'nested child 2' }
                    ]
                }
            ]
        }
    ]
};

class TreeExample extends PureComponent {
    constructor(props){
        super(props);
        this.state = {data};
    }
    
    onToggle(node, toggled){
        const {cursor, data} = this.state;
        if (cursor) {
            this.setState(() => ({cursor, active: false}));
        }
        node.active = true;
        if (node.children) { 
            node.toggled = toggled; 
        }
        this.setState(() => ({cursor: node, data: Object.assign({}, data)}));
    }
    
    render(){
        const {data} = this.state;
        return (
            <Treebeard
                data={data}
                onToggle={this.onToggle}
            />
        );
    }
}

const content = document.getElementById('content');
ReactDOM.render(<TreeExample/>, content);

If you use react-hooks you should do something like this:

import React, {useState} from 'react';
const TreeExample = () => {
    const [data, setData] = useState(data);
    const [cursor, setCursor] = useState(false);
    
    const onToggle = (node, toggled) => {
        if (cursor) {
            cursor.active = false;
        }
        node.active = true;
        if (node.children) {
            node.toggled = toggled;
        }
        setCursor(node);
        setData(Object.assign({}, data))
    }
    
    return (
       <Treebeard data={data} onToggle={onToggle}/>
    )
}

const content = document.getElementById('content');
ReactDOM.render(<TreeExample/>, content);

Prop Values

data

PropTypes.oneOfType([PropTypes.object,PropTypes.array]).isRequired

Data that drives the tree view. State-driven effects can be built by manipulating the attributes in this object. Also supports an array for multiple nodes at the root level. An example can be found in example/data.js

onToggle

PropTypes.func

Callback function when a node is toggled / clicked. Passes 2 attributes: the data node and it's toggled boolean state.

style

PropTypes.object

Sets the treeview styling. Defaults to src/themes/default.

animations

PropTypes.oneOfType([PropTypes.object, PropTypes.bool])

Sets the treeview animations. Set to false if you want to turn off animations. See velocity-react for more details. Defaults to src/themes/animations.

decorators

PropTypes.object

Decorates the treeview. Here you can use your own Container, Header, Toggle and Loading components. Defaults to src/decorators. See example below:

const decorators = {
    Loading: (props) => {
        return (
            <div style={props.style}>
                loading...
            </div>
        );
    },
    Toggle: (props) => {
        return (
            <div style={props.style}>
                <svg height={props.height} width={props.width}>
                    // Vector Toggle Here
                </svg>
            </div>
        );
    },
    Header: (props) => {
        return (
            <div style={props.style}>
                {props.node.name}
            </div>
        );
    },
    Container: (props) => {
        return (
            <div onClick={this.props.onClick}>
                // Hide Toggle When Terminal Here
                <this.props.decorators.Toggle/>
                <this.props.decorators.Header/>
            </div>
        );
    }
};

<Treebeard data={...} decorators={decorators}/>

Data Attributes

{
    id: '[optional] string',
    name: 'string',
    children: '[optional] array',
    toggled: '[optional] boolean',
    active: '[optional] boolean',
    loading: '[optional] boolean',
    decorators: '[optional] object',
    animations: '[optional] object'
},

id

The component key. If not defined, an auto-generated index is used.

name

The name prop passed into the Header component.

children

The children attached to the node. This value populates the subtree at the specific node. Each child is built from the same basic data structure. Tip: Make this an empty array, if you want to asynchronously load a potential parent.

toggled

Toggled flag. Sets the visibility of a node's children. It also sets the state for the toggle decorator.

active

Active flag. If active, the node will be highlighted. The highlight is derived from the node.activeLink style object in the theme.

loading

Loading flag. It will populate the treeview with the loading component. Useful when asynchronously pulling the data into the treeview.

decorators / animations

Attach specific decorators / animations to a node. Provides the low level functionality to create visuals on a node-by-node basis. These structures are the same as the top level props, described above.