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

d3-hist2d

v1.0.7

Published

Hist2D is a two dimensional histogram D3 v4+ module

Downloads

53

Readme

2D Histogram

CircleCI Codacy Badge

d3.hist2d plugin implements a non-blocking rectangular binning. It's useful for displaying a scatterplot with millions of points, aggregating the data into a more coarse representation suitable for display.

It can be used as a module of a larger application, because it doesn't block the UI, it computes the values between each animation frame.

Inspired by the work of Mike Bostock.

Example

http://bl.ocks.org/herkulano/4f43dbf3473dc5503052

Usage

# hist2d([data], callback)

Expects [data] to be an array of arrays: [[1,2],[3,4],...]

The callback function is called when the binning is complete. It sends the data to its parameter.

d3.hist2d()
  .bins(40)
  .domain([[0, 100], [0, 100]])
  (data, draw);

function draw(hist) {
  // hist is the binned data
}

The returned data is an array of bins. Each bin contains its position in columns and rows as x and y:

  • x - the column's position
  • y - the row's position

Bins that are empty are omitted.

# hist2d.bins(bins)

Sets the number of columns and rows for the bins of the rectangular histogram. The total number of bins is columns * rows === bins * bins

# hist2d.indices([x index, y index])

Defines the indices of the data in the original array. This is useful if the data has more than two values or if the values are out of order.

Example:

[
  [0, 43, 12248, 30],
  [1, 45, 12398, 40],
  [2, 46, 12456, 50],
  ...
]

// we want to use [2] as x and [1] as y
d3.hist2d()
  .bins(40)
  .indices([2, 1])
  .domain([[0, 100], [0, 100]])
  (data, draw);

If indices is not set it defaults to [0, 1].

# hist2d.domain([ [x domain], [y domain] ])

Sets the input domains for x and y. Expects an array with two arrays of numbers.

# hist2d.size([width, height])

[width, height] of the scatterplot. Sets the width and height of the cells size / bins.

# hist2d.size()

Returns an array with the width and height of the cells [width, height].

# hist2d.interval(interval)

The binning function is non-blocking, so the values are computed between each animation frame for 12ms by default.

License & Acknowledgements

LICENSE

Analytics