🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-d3-tree

Package Overview
Dependencies
Maintainers
0
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-d3-tree

React component to create interactive D3 tree hierarchies

3.6.6
latest
Source
npm
Version published
Weekly downloads
132K
-19.2%
Maintainers
0
Weekly downloads
 
Created

What is react-d3-tree?

The react-d3-tree package is a React component library for creating interactive and customizable tree diagrams using D3.js. It allows developers to visualize hierarchical data structures in a tree format, providing features like zooming, panning, and node customization.

What are react-d3-tree's main functionalities?

Basic Tree Rendering

This feature allows you to render a basic tree structure using hierarchical data. The code sample demonstrates how to import the Tree component from react-d3-tree and use it to display a simple tree with a parent node and two child nodes.


{
  "import React from 'react';
  "import Tree from 'react-d3-tree';
  "const myTreeData = [
    {
      "name": 'Parent',
      "children": [
        {
          "name": 'Child 1'
        },
        {
          "name": 'Child 2'
        }
      ]
    }
  ];
  "const MyTreeComponent = () => (
    <div id="treeWrapper" style={{ width: '50em', height: '20em' }}>
      <Tree data={myTreeData} />
    </div>
  );
  "export default MyTreeComponent;
}

Custom Node Rendering

This feature allows for custom rendering of tree nodes. The code sample shows how to define a custom node rendering function that uses SVG elements to display nodes, allowing for more control over the appearance and behavior of each node.


{
  "import React from 'react';
  "import Tree from 'react-d3-tree';
  "const renderCustomNode = ({ nodeDatum, toggleNode }) => (
    <g>
      <circle r={15} onClick={toggleNode} />
      <text fill="black" strokeWidth="1" x="20">
        {nodeDatum.name}
      </text>
    </g>
  );
  "const MyTreeComponent = () => (
    <div id="treeWrapper" style={{ width: '50em', height: '20em' }}>
      <Tree data={myTreeData} renderCustomNodeElement={renderCustomNode} />
    </div>
  );
  "export default MyTreeComponent;
}

Zoom and Pan

This feature enables zooming and panning on the tree diagram, allowing users to explore large trees more easily. The code sample demonstrates how to enable zooming by setting the `zoomable` prop to true and adjusting the initial translation of the tree.


{
  "import React from 'react';
  "import Tree from 'react-d3-tree';
  "const MyTreeComponent = () => (
    <div id="treeWrapper" style={{ width: '50em', height: '20em' }}>
      <Tree data={myTreeData} zoomable={true} translate={{ x: 100, y: 100 }} />
    </div>
  );
  "export default MyTreeComponent;
}

Other packages similar to react-d3-tree

Keywords

react

FAQs

Package last updated on 28 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts