npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arsolio/react-tree-graph

v0.0.1

Published

A react library for generating a graphical tree from data using d3

Downloads

2

Readme

react-tree-graph Github

Build Status Coverage Status npm version npm bundle size license Storybook

A simple react component which renders data as a tree using svg.

Supports react 15.3+.

Check out the examples and the demo.

Older Versions

7.X 6.X 5.X 4.X 3.X 2.X 1.X

Installation

npm install react-tree-graph --save

Usage

import { Tree } from 'react-tree-graph';

const data = {
	name: 'Parent',
	children: [{
		name: 'Child One'
	}, {
		name: 'Child Two'
	}]
};

<Tree
	data={data}
	height={400}
	width={400}/>);

import { AnimatedTree } from 'react-tree-graph';

<AnimatedTree
	data={data}
	height={400}
	width={400}/>);

If you are using webpack, and have css-loader, you can include some default styles with:

import 'react-tree-graph/dist/style.css'

Alternatively, both the JavaScript and CSS can be included directly from the dist folder with script tags.

Configuration

Tree

| Property | Type | Mandatory | Default | Description | |:---|:---|:---|:---|:---| | data | object | yes | | The data to be rendered as a tree. Must be in a format accepted by d3.hierarchy. | | margins | object | | { bottom : 10, left : 20, right : 150, top : 10} | The margins around the content. The right margin should be larger to include the rendered label text. | | height | number | yes | | The height of the rendered tree, including margins. | | width | number | yes | | The width of the rendered tree, including margins. | | direction | ltr,rtl | | ltr | The direction the tree will be rendered in. Either left-to-right or right-to-left. | | children | node | | | Will be rendered as children of the SVG, before the links and nodes. | | getChildren | function(node) | | node => node.children | A function that returns the children for a node, or null/undefined if no children exist. | | keyProp | string | | "name" | The property on each node to use as a key. | | labelProp | string | | "name" | The property on each node to render as a label. | | nodeShape | circle,image,polygon,rect | | circle | The shape of the node icons. | | nodeProps | object | | {} | Props to be added to the <circle>, <image>, <polygon> or <rect> element. These will take priority over the default r added to circle and height, width, x and y added to image and rect. | | gProps | object | | { className: 'node' } | Props to be added to the <g> element. The default className will still be applied if a className property is not set. | | pathProps | object | | { className: 'link' } | Props to be added to the <path> element. The default className will still be applied if a className property is not set. | | pathFunc | function(x1,y1,x2,y2) | | curved | Function to calculate the co-ordinates of the path between nodes. | | svgProps | object | | {} | Props to be added to the <svg> element. | | textProps | object | | {} | Props to be added to the <text> element. |

AnimatedTree has the following properties in addition to the above.

| Property | Type | Mandatory | Default | Description | |:---|:---|:---|:---|:---| | duration | number | | 500 | The duration in milliseconds of animations. | | easing | function(interval) | | d3-ease.easeQuadOut | The easing function for animations. Takes in a number between 0 and 1, and returns a number between 0 and 1. | | steps | number | | 20 | The number of steps in animations. A higher number will result in a smoother animation, but too high will cause performance issues. |

Events

Event handlers in nodeProps, gProps and textProps will be called with the node ID as an additional parameter.

function(event, nodeId) { ... }

Event handlers in pathProps will be called with the source and target node IDs as additional parameters.

function(event, sourceNodeId, targetNodeId) { ... }

Overriding props

The following properties can also be overridden by setting then for individual nodes.

| Global Prop | Node Prop | |:---|:---| | keyProp | keyProp | | labelProp | labelProp | | nodeShape | shape |

The following object properties, if set on individual nodes, will be combined with the object properties set on the tree. If a property exists in both objects, the value from the node will be taken.

| Prop | Description | |:---|:---| | nodeProps | | | gProps | | | pathProps | Props for a path are taken from the target node. | | textProps | |