0.4.0 ā€¢ Published 4 years ago

treeviz-react v0.4.0

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

Treeviz-react

Known Vulnerabilities David license

Treeviz implementation for React

npm.io

Usage

npm install treeviz-react

// or

yarn add treeviz-react
import React from 'react';
import { TreevizReact } from 'treeviz-react';

const data = [
  { id: 1, text_1: 'Chaos', text_2: 'Void', father: null, color: '#FF5722' },
  { id: 2, text_1: 'Tartarus', text_2: 'Abyss', father: 1, color: '#FFC107' },
  { id: 3, text_1: 'Gaia', text_2: 'Earth', father: 1, color: '#8BC34A' },
  { id: 4, text_1: 'Eros', text_2: 'Desire', father: 1, color: '#00BCD4' },
];

const Foo = () => {
  return (
    <TreevizReact
      data={data}
      idKey={'id'}
      relationnalField={'father'}
      nodeWidth={200}
      nodeHeight={100}
      mainAxisNodeSpacing={2}
      secondaryAxisNodeSpacing={1.3}
      renderNode={(node) =>
        `<div style="height:${node.settings.nodeHeight}px;display:flex;align-items:center;margin-left:12px">Node name: ${node.data.text_1}</div>`
      }
      onNodeClick={(node) => console.log('you clicked on node ' + node.id)}
      duration={500}
      linkWidth={(node) => 3}
    />
  );
};

The tree will automatically update whenever one of those props change. Note that is not recommended to update the relationnalField and the idKey prop once the component has been mounted.

API

PropTypeDefaultDefinition
idKeystring"id"The unique identifier field in the dataset representing the node
relationnalFieldstring"father"In case of flat dataset, usually the relationnal field between each node is the field representing the father of the node, linking it to the id of the field. (See example below).
hasFlatDatabooleantrueSpecify whether the data passed to the tree is flat or already hierarchical
hasPanAndZoombooleantrueToggle the ability to pan and zoom the tree
nodeWidthnumber160Width of a node in px
nodeHeightnumber100Height of a node in px
linkColorfunction(node) => "#ffcc80"Color of the link
linkWidthfunction(node) => 10Width of the link
linkShape"quadraticBeziers" | "orthogonal" | "curve""quadraticBeziers"Shape of the link
renderNodefunction(node) => nullHTML template for every node
isHorizontalbooleantrueDirection of the tree. If true, the tree expands from left to right. If false, it goes from top to bottom
onNodeClickfunction(node) => nullFunction handling the event when someone click on it
onNodeMouseEnterfunction(node) => nullFunction handling the event when someone hover a node
onNodeMouseLeavefunction(node) => nullFunction handling the event when the mouse pointer leaves a node
mainAxisNodeSpacingnumber or "auto"1.3Set the distance in pixels between two depths in the tree. If the value is auto it will automatically display the tree to fit the size of the container.
secondaryAxisNodeSpacingnumber1.25Set the distance between nodes in the same level as a coefficient of node dimensions. Recommended to have the value superior to 1
marginTopnumber1.25Set the margin between the SVG element and the tree
marginBottomnumber1.25Set the margin between the SVG element and the tree
marginLeftnumber1.25Set the margin between the SVG element and the tree
marginRightnumber1.25Set the margin between the SVG element and the tree
areaHeightnumber800The height of the area that displays the tree
areaWidthnumber500the width of the area that displays the tree
0.4.0

4 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago