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

d3ndro

v1.0.1

Published

Plots R HClust objects as dendrograms using D3

Downloads

756

Readme

d3ndro   License: CC BY 4.0

Interactive Hierarchical Clustering Vizualization Using D3 & R.

Features

  • Collapsible d3ndrogram (see Configuration)
  • Colored leaf nodes (per datum via callback)
  • Colored text labels
  • Quick Scrolling Navigation
  • Simple Integration with R's hclust function

Installation

Installing is as simple as including this in your html document:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/d3ndro.js"></script>

Alternatively, if you use npm, you can install it using the following command:

npm install d3ndro

Demonstration

You can see a demonstration of this library by cloning the repo and running any simple webserver in the root directory. I personally prefer python's SimpleHTTPServer.

python -m SimpleHTTPServer 8888

Then open http://localhost:8888/demo in your favorite web browser.

Usage

This visualization tool is meant to be used in conjunction with R's hclust function. See src/hclust2json.R for an hclust2json function that exports d3ndro-compatible JSON.

Once you have generated the JSON from R, you'll need to bring it into your web page using d3. If you aren't using d3 elsewhere in your project, you can use d3ndro.d3 to access d3's functions. See the demo source code for an example.

Configuration

Options

The d3ndro package offers easy configuration options available through d3ndro.options. To set, just edit the global d3ndro.options object before calling any other functions. I recommend placing configuration options in the same script tag that you use to include d3ndro if you use a script tag to include d3ndro.

|Option|Description|Default| |---|---|---| |d3ndro.options.backgroundColor|Function returning the background color for the d3ndrogram plot. Function can take parsedJSON as a parameter.|function() { return "#FFF"; }| |d3ndro.options.collapsible|Determines whether internal tree nodes should collapse children into them when clicked (and uncollapse when clicked again).|undefined // (false)| |d3ndro.options.fontSize|Font size for leaf labels and axes text.|16| |d3ndro.options.highlightOnHover|Determines whether the path through the tree to the current leaf node should be highlighted when the mouse is over the leaf node|undefined // (false)| |d3ndro.options.internalNodeRadius|Size of the internal (non-leaf) nodes in the tree.|4| |d3ndro.options.itemColor|Function to determine color of leaf nodes. Can take datum (d) as an argument. See the demo for more deatils.|function() { return "#000"; }| |d3ndro.options.labelSpace|Space allocated for each leaf node/label.|function() { return this.fontSize/2 * Math.max(...Object.keys(parsedJSON.leafLabels).map((key)=>key.length)); }| |d3ndro.options.leafNodeRadius|Radius of the leaf node circles in pixels.|5| |d3ndro.options.mergeColor|Function returning the color of internal (non-leaf) nodes and connections in the tree. Function can take a merge node datum and index as arguments.|function() { return "#666"; }| |d3ndro.options.padding|Number of pixels to offset the dendrogram from the edge.|24| |d3ndro.options.spacing|Space to put between each leaf node/label.|24| |d3ndro.options.svgHeight|Height of the SVG element conaining the d3ndrogram.|400| |d3ndro.options.svgOverflow|Function returning the CSS Policy for when the d3ndrogram is larger than the width. See this tutorial for more information. Function can take parsedJSON as a parameter.|function() { return "scroll"; }| |d3ndro.options.textColor|Function returning the color for label text. Function can take a leaf datum as an argument.|function(...args) { return this.itemColor.call(this, args); }|

Events

The d3ndro package also exposes events using jQuery for convenience of integration. See the demo for an example on how to listen to events. For your reference, a list of all exposed d3ndro events has been given below:

|Event|Description|Location| |-----|-----------|--------------| |d3ndro:leaf:click|When a leaf node is clicked.|src/interaction/collapse.js| |d3ndro:collapse|When an internal node is collapsed.|src/interaction/collapse.js| |d3ndro:uncollapse|When a collapsed internal node is expanded.|src/interaction/collapse.js| |d3ndro:highlight|When a path to a leaf node is highlighted.|src/interaction/highlight.js| |d3ndro:flash|When a path to a leaf node is emboldened temporarily through animation.|src/interaction/highlight.js| |d3ndro:unhighlight|When highlighting is removed from a path to a leaf node.|src/interaction/highlight.js| |d3ndro:groupHighlight|When group highlighting is toggled on an internal (non-leaf) node.|src/interaction/highlight.js| |d3ndro:scroll|When automatic scrolling to a leaf node is invoked.|src/interaction/scroll.js|