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

tree-graph-flex

v1.0.25

Published

Tree builder, with a lot of options

Downloads

5

Readme

Tree Graph Flex

This is simple component which renders data as a tree using svg.

Example

Installing

npm install tree-graph-flex --save

Usage

import  { TreeGraphFlex } from 'tree-graph-flex';

ReactDOM.render(
 <React.StrictMode>
   <TreeGraphFlex 
     data={data}
     nodeContent={ node => <div> {node.subject} </div> }
     yOffset={15}
     xOffset={ level => 30 + level * 10 }
     nodeWidth={150}
     nodeHeight={50}
     pathShape={"bezier"}
     lineClassName={"connectingLines"}
     nodeBoxClassName={"nodeBox"}
     direction={"forward"}
   />
 </React.StrictMode>,
 document.getElementById('root')
);

Example data object

const data = {
  id: "0",
  subject: "animals",
  children: [
    {
      id: "1",
      subject: "dogs",
      children: [
        {
          id: "1.1",
          subject: "terriers",
          children: [],
        },
        {
          id: "1.2",
          subject: "mastiffs",
          children: [],
        },
      ],
    },
    {
      id: "2",
      subject: "birds",
      children: [
        {
          id: "2.1",
          subject: "parrots",
          children: [],
        },
        {
          id: "2.2",
          subject: "crows",
          children: [],
        },
      ],
    },
  ],
};

Component props

| Property | Type | Mandatory | Default | Description | | :----------------- | :----------------- | :-------- | :--------------- | :---------------------------------------------------------------------------------------------- | | data | object | yes | no | The data to be rendered as a tree | | nodeWidth | number | no | 100 | Width node container | | nodeHeight | number | no | 50 | Height node container | | xOffset | number or function | no | 50 | Distance between adjacent nodes by x | | yOffset | number | no | 50 | Distance between adjacent nodes by y | | pathShape | enum or function | no | “bezier” | Defines curve shape, which connects nodes | | nodeContent | function | yes | no | Node box content. Html element | | lineClassName | string | no | "connectingLine" | ClassName, defines style of curve shape, which connects nodes | | nodeBoxClassName | string | no | "nodeBox" | ClassName, defines style of node view | | direction | enum | no | "forward" | defines building diagram order. If "forward" - root element at left side, "reverse" - at right. |

props description:

nodeWidth, nodeHeight - size of node box in pixels, defined by HTML element size, that return by nodeContent function;

xOffset, yOffset - distance between adjacent nodes. xOffset may be a function with level argument, where level - tree branches level;

pathShape - there are three preset functions: bezier, straight and roundedAngles. Functions return d attribute for tag path as string. Instead, you can pass your function, which accepts following parameters: start x, start y, end x, end y. Corner rounding in roundedAngles function calculates automatically, and it depends on distance between adjacent nodes. As bonus, there is another one preset function - staticRadiusRoundedAngles, which accepts five arguments. Fifth argument - corner rounding radius.

nodeContent - any HTML element or react component.

direction - diagram order. If "forward" - root element at left side, "reverse" - at right.


TypeDoc documentation