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

treeviz-react

v0.4.0

Published

[![Known Vulnerabilities](https://snyk.io/test/github/dwyl/hapi-auth-jwt2/badge.svg?targetFile=package.json)](https://snyk.io/test/github/dwyl/hapi-auth-jwt2?targetFile=package.json) ![David](https://img.shields.io/david/PierreCapo/treeviz-react) [![licen

Downloads

162

Readme

Treeviz-react

Known Vulnerabilities David license

Treeviz implementation for React

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

| Prop | Type | Default | Definition | | -------------------------- | --------------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | idKey | string | "id" | The unique identifier field in the dataset representing the node | | relationnalField | string | "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). | | hasFlatData | boolean | true | Specify whether the data passed to the tree is flat or already hierarchical | | hasPanAndZoom | boolean | true | Toggle the ability to pan and zoom the tree | | nodeWidth | number | 160 | Width of a node in px | | nodeHeight | number | 100 | Height of a node in px | | linkColor | function | (node) => "#ffcc80" | Color of the link | | linkWidth | function | (node) => 10 | Width of the link | | linkShape | "quadraticBeziers" | "orthogonal" | "curve" | "quadraticBeziers" | Shape of the link | | renderNode | function | (node) => null | HTML template for every node | | isHorizontal | boolean | true | Direction of the tree. If true, the tree expands from left to right. If false, it goes from top to bottom | | onNodeClick | function | (node) => null | Function handling the event when someone click on it | | onNodeMouseEnter | function | (node) => null | Function handling the event when someone hover a node | | onNodeMouseLeave | function | (node) => null | Function handling the event when the mouse pointer leaves a node | | mainAxisNodeSpacing | number or "auto" | 1.3 | Set 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. | | secondaryAxisNodeSpacing | number | 1.25 | Set the distance between nodes in the same level as a coefficient of node dimensions. Recommended to have the value superior to 1 | | marginTop | number | 1.25 | Set the margin between the SVG element and the tree | | marginBottom | number | 1.25 | Set the margin between the SVG element and the tree | | marginLeft | number | 1.25 | Set the margin between the SVG element and the tree | | marginRight | number | 1.25 | Set the margin between the SVG element and the tree | | areaHeight | number | 800 | The height of the area that displays the tree | | areaWidth | number | 500 | the width of the area that displays the tree |