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

react-tree-vis

v1.0.0

Published

React interactive tree visualization library.

Downloads

29

Readme

Allows you to store and manage information in different tree data structures.

:video_game: Code Sandbox

Storybook

:gift: NPM

Features

  • :package: Only 4kb minified & gzipped / no dependencies
  • :hammer_and_wrench: Perform tree operations with a simple function call
  • :rocket: Components made with only JSX and CSS
  • :nail_care: Make the components of your own with styling options

Data Structures Covered

  • Binary Search Tree

Trie, AVL Tree and more coming soon :see_no_evil:

Who is this library for?

If you are looking for a way to not just only display your data in a tree format but also interact with it, react-tree-vis might be for you. You can simply pass an array of numbers to display it or use our API to insert, delete, search and much more. With react-tree-vis, you can style your tree component with props or override with CSS. Everything is documented below! Also, I would recommend checking out other similar libraries too.

Documentation

Installation

# Yarn
yarn add react-tree-vis

# NPM
npm install react-tree-vis

Quick start

We are displaying data in BST and interacting with it using useTree. Play around with this example here.

import { BinarySearchTree, useTree } from 'react-tree-vis'
import { useState } from 'react'

export default function App() {
  const { ref, insert, remove } = useTree()

  const [insertValue, setInsertValue] = useState(0)
  const [removeValue, setRemoveValue] = useState(0)

  return (
    <div className="App">
      <input
        type="number"
        onChange={(elem) => setInsertValue(parseInt(elem.currentTarget.value))}
      />
      <button onClick={() => insert(insertValue)}>Insert</button>
      <br />
      <input
        type="number"
        onChange={(elem) => setRemoveValue(parseInt(elem.currentTarget.value))}
      />
      <button onClick={() => remove(removeValue)}>Remove</button>

      <BinarySearchTree data={[2, 1, 3]} ref={ref} />
    </div>
  )
}

BinarySearchTree

It organizes numbers in a binary search tree and exposes various styling options.

Props

| Prop | Type | Required | Description | | ------------ | ----------------------------- | -------- | ----------------------------------------------------------------------------------------- | | ref | React.MutableRefObject<any> | :x: | Allows interaction with BST component. ref object passed, is obtained from useTree(). | | data | number[] | :x: | Elements in the array are inserted into the tree on mount. | | treeStyles | object | :x: | Allows overriding default style of the component. |

treeStyles object

An object with properties described below can be passed to treeStyles prop to override default styles.

| Property | Type | Description | Default | | ------------------------------ | -------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | lineColor | string | Color of the line connecting nodes | #ccc | | lineHoverColor | string | Hover color of the line connecting nodes | #5f6674 | | lineRadius | string | Radius of curves in the line | 5px | | nodeBorder | string | Border style of the nodes. Syntax of short-hand CSS border property is accepted here. | none | | nodeBorderRadius | string | Border radius of the nodes | 200px | | nodeBackgroundColor | string | Background color of the nodes | #fff | | nodeShadow | string | Shadow property of the nodes. Syntax of short-hand CSS shadow property accepted here. | -5px -5px 20px #fff, 5px 5px 20px #babecc | | nodeFontColor | string | Font color of the text inside the nodes | #666 | | nodeTextShadow | string | Font shadow of text inside the nodes. | none | | nodeHighlightBorder | string | Border style of the highlighted nodes*. Syntax of short-hand CSS border property is accepted here. | none | | nodeHighlightBackgroundColor | string | Background color of the highlighted nodes | #fff | | nodeHighlightShadow | string | Shadow property of the highlighted nodes. Syntax of short-hand CSS shadow property accepted here. | -5px -5px 20px #fff, 5px 5px 20px #babecc | | nodeHighlightFontColor | string | Font color of the text inside the highlighted nodes | #fff | | nodeHighlightTextShadow | string | Font shadow of text inside the highlighted nodes. | 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #00ff15, 0 0 20px #00ff15, 0 0 25px #00ff15, 0 0 30px #00ff15, 0 0 35px #00ff15 | | nodeHoverBorder | string | Border style of the hovered nodes. Syntax of short-hand CSS border property is accepted here. | none | | nodeHoverBackgroundColor | string | Background color of the hovered nodes | #fff | | nodeHoverShadow | string | Shadow property of the hovered nodes. Syntax of short-hand CSS shadow property accepted here. | -1px -1px 5px #fff, 1px 1px 5px #babecc | | nodeHoverFontColor | string | Font color of the text inside the hovered nodes | #002574 | | nodeHoverTextShadow | string | Font shadow of text inside the hovered nodes. | none | | nodeNullFontColor | string | Font color of the null nodes | #7c7c7c2f | | nodeNullHoverFontColor | string | Font color of the hovered null nodes | #ff0000b9 | | transitionDuration | string | CSS transition duration | 0.5s |

* Nodes searched successfully in the tree are highlighted.

This story allows you to play around with styles! (Refresh to apply styles. Working on improving UX here. Here is a rabbit for inconvenience caused. :rabbit:)

Feel styling options are limited? You can always override them with CSS. All the tree components are given id react-tree-vis. Refer to this CSS file for selectors. Also check out this codesandbox example.

useTree()

This hook allows you to interact with your tree. Insert, remove, search and so much more!

Usage

import { useTree } from 'react-tree-vis'

const tree = useTree()

It returns an object with the following properties.

| Property | Type | Description | | -------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | | ref | React.MutableRefObject<any> | Pass this ref object to your tree component. It binds the functions returned by this hook to that component. | | insert | (value: number) => void | Inserts the value | | remove | (value: number) => boolean | removes the value | | search | (value: number) => boolean | Searches the value and return true if found. Also, node found is highlighted | | getData | (traversalOrder: TraversalOrderType) => number[]* | Return traversal of the tree | | clear | () => void | Removes all nodes | | balance | () => void | Balances the tree | | generateRandomTree | (countOfNodes: number) => void | Removes all nodes and inserts countOfNodes random values. | | checkTreeType | () => BinaryTreeCheckType[]** | Checks whether the current tree is balanced, complete, perfect or full |

* TraversalOrderType = 'inorder' | 'postorder' | 'preorder'
** BinaryTreeCheckType = 'balanced' | 'complete' | 'perfect' | 'full'

Development

Install

yarn install

Develop

yarn storybook

Run tests

yarn test

Author

👤 Vandan Rogheliya

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2021 Vandan Rogheliya. This project is MIT licensed.