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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tree3-react

v1.1.4

Published

A javascript library for generating interactive phylogenetic tree visualizations. Relies on [D3](http://d3js.org) [hierarchy layout](https://github.com/d3/d3-3.x-api-reference/blob/master/Hierarchy-Layout.md) to generate SVG elements, with a focus on cust

Readme

tree3-react

A javascript library for generating interactive phylogenetic tree visualizations. Relies on D3 hierarchy layout to generate SVG elements, with a focus on customizability.

Example Github Page

Check out the Radial, Rectangular, and Unrooted trees in this demo!

Features

  • Layouts: Radial, Rectangular, Unrooted (Equal-Angle)
  • Pan/Zoom functionality
  • Callback functions for tree interactions
  • Customizable menu options for links, nodes, and leaves

Tree params

data

(String) required. Newick data.

width

(Radial tree only!) (number) Determines the width of the generated svg. Defaults to 1000.

scale

(Unrooted tree only!) (number) Used to scale the size of the tree to make nodes and leaves more readable. Defaults to 500.

onNodeClick, onNodeMouseOver, onNodeMouseOut

function (event, node) Click, mouse enter, and mouse leave callback functions for inner nodes.

onLeafClick, onLeafMouseOver, onLeafMouseOut

function (event, node) Click, mouse enter, and mouse leave callback functions for leaves.

onLinkClick, onLinkMouseOver, onLinkMouseOut

function (event, source node, target node) Click, mouse enter, and mouse leave callback functions for links.

customNodeMenuItems, customLeafMenuItems

Array of objects with the following properties:

| Property | Type | Description | |----------|------|-------------| | label | function(node) => string | Determines the label of the custom option | | onClick | function(node) => void | Callback function when option is selected | | toShow | function(node) => boolean | Determines whether to show this option for the given node |

Example:

customNodeMenuItems={[
  {
    label: (node) => "Custom Action",
    onClick: (node) => console.log("Clicked on node:", node),
    toShow: (node) => node.data.someProperty === true
  }
]}

customLinkMenuItems

Array of objects with the following properties:

| Property | Type | Description | |----------|------|-------------| | label | function(sourceNode, targetNode) => string | Determines the label of the custom option | | onClick | function(sourceNode, targetNode) => void | Callback function when option is selected | | toShow | function(sourceNode, targetNode) => boolean | Determines whether to show this option for the given link |

nodeStyler, leafStyler

function (node) Callback used for custom rendering options.

linkStyler

function (source node, target node) Callback used for custom rendering options.

homeNode

(string) Name of the node to automatically center on upon rendering the tree.

Tree Functions

These functions can be accessed through the useRef React hook of the tree element.

getNodes

Returns the d3 selection of all nodes.

getLeaves

Returns the d3 selection of all leaves.

getLinks

Returns the d3 selection of all links.

setVariableLinks (boolean)

Determines whether to render the links according to their length. For a radial tree, this defaults to false. For a rectangular tree, this defaults to false. Unrooted trees do not have this function.

setDisplayLeaves (boolean)

Determines whether to render leaf labels or not. Defaults to true.

setTipAlign (boolean)

Determines whether to align tips with each other, or to attach tips on the ends of branches. Defaults to false. Unrooted trees do not have this function.

recenterView

Resets the pan/zoom of the tree.

getRoot

Returns the root node. Unrooted trees do not have this function.

getData

(Unrooted Tree only!) Returns the unrooted tree data object.

getContainer

Returns the HTML div element that the svg is rendered in.

findAndZoom (query)

Pans the svg to center the node or leaf.

Tree State

Stores the changes made to a tree in an object. When a tree is rendered given a state object, any applicable transforms will be applied once when first initialized.

Root

state.root: string will find a given node name and reroot to this node.

Running example

cd /tree3
npm i 
npm run build:example
npm run start:example

Usage

import React, { Component } from 'react'

import { RadialTree } from 'tree3-react'

const newickData = "(((A:0.2, B:0.3):0.3,(C:0.5, D:0.3):0.2):0.3, E:0.7):1.0;"

class Example extends Component {
  render() {
    return (
      <div>
        <RadialTree data={newickData}/>
      </div>
    )
  }
}

License

MIT ©