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-latency-heatmap

v1.2.4

Published

A reusable D3 latency heatmap chart.

Downloads

64

Readme

D3 Latency Heatmap

This is a reusable D3 latency heatmap chart, which is a highly effective way to visualize latency data over time. The chart is fast, easy to use, and produces beautiful images such as the below:

Example Latency Heatmap

For more on latency heatmaps, see:

Installing

D3 version 4.x is required (3.x is not supported).

If you use NPM, npm install d3-latency-heatmap. Otherwise, download the latest release binaries or the latest release source code. You can also load directly from unpkg.com. AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3 global is exported:

<script src="//d3js.org/d3.v4.min.js"></script>
<script src="//sengelha.github.io/d3-latency-heatmap/d3-latencyHeatmap.v1.min.js"></script>

<div id="chart"></div>
<script>
(function() {
    var parseTime = d3.timeParse("%Y-%m");
    var chart = d3.latencyHeatmap()
        .x(function (d) { return parseTime(d.date); })
        .y(function (d) { return +d.bucket; })
        .yFormat(function(d) { return d + " s"; })
        .count(function(d) { return +d.count; })
        .colorRange([d3.rgb('#FFFFFF'), d3.rgb('#5B82A1')])
        .tooltipText(function (d) { return "YearMonth: " + d[0].toISOString().substring(0, 7) + "\nBucket: " + d[1] + "\nCount: " + d[2]; })
        .rectSize([8, 8]);
    d3.csv("//sengelha.github.io/d3-latency-heatmap/sample-data.csv", function (data) {
        var svg = d3.select("#chart")
            .datum(data)
            .call(chart);
    });
})();
</script>

Usage Notes

  • In order to use this chart, your data must already be bucketized -- you cannot use raw events. A bucket contains three data points: the x-value, the y-value, and the number of observations in this bucket.
  • The color intensity of a cell is determined based on its value relative to the maximum value of all buckets. This implies that if the number of observations per x-value (e.g. per day) increases over time, the cells will start with faint colors and grow more intense over time.
  • This chart's API was modelled upon Mike Bostock's Toward Reusable Charts proposal.

Examples

API Reference

d3.latencyHeatmap()

Creates a new latency heatmap chart which may later be rendered into a container. Returns a latencyHeatmap object.

The typical pattern that the chart is rendered is by:

  1. Selecting the container (e.g. a div) into which the chart will be rendered
  2. Assigning the data to the container
  3. Using d3's call() method.

Example:

var data = [...]; // May be sourced using d3.csv(), d3.json(), etc.
d3.select("#container")
    .datum(data)
    .call(chart);

latencyHeatmap.colorRange([minColor, maxColor])

Defines the color range to be used when filling cells. This color range will be interpolated using d3.interpolateRgb(). If not set, defaults to [d3.rgb('#FFFFFF'), d3.rgb('#F03524')].

Example:

d3.latencyHeatmap()
    .colorRange([d3.rgb('#FFFFFF'), d3.rgb('#5B82A1')]);

latencyHeatmap.count(accessor)

Defines an count accessor which is called for each row in data. Must return a number, which corresponds to the number of observations within the bucket. If not set, defaults to function(d) { return d[2]; }.

Example:

d3.latencyHeatmap()
    .count(function(d) { return d.count; }); // d is { x: Date, y: number, count: number }

latencyHeatmap.height(h)

Sets the height of the rendered chart to h. Automatically scales the size of the drawn rectangles to fit the specified chart height. If not set, defaults to 400.

This value is ignored if the rectangle size is set using rectSize().

Example:

d3.latencyHeatmap()
    .height(400);

latencyHeatmap.rectSize([w, h])

Sets the size of the individual rectangles used to draw the chart to be width w and height w. When set, the chart automatically calculates the total width and height based on the number of elements to be drawn.

Example:

d3.latencyHeatmap()
    .rectSize([6, 4]);

latencyHeatmap.tooltipText(formatter)

Defines an accessor which can be used to control how tooltips for each drawn rectangle are formatted. formatter is called with an array with three elements: the x-value for the tick (a Date object), the y-value for the tick (a number) and the count. If not set, no tooltips are drawn.

Example:

d3.latencyHeatmap()
    .tooltipText(function (d) { return "X: " + d[0] + " Y: " + d[1] + " Count: " + d[2]; });

latencyHeatmap.width(w)

Sets the width of the rendered chart to w. Automatically scales the size of the drawn rectangles to fit the specified chart width. If not set, defaults to 600.

This value is ignored if the rectangle size is set using rectSize().

Example:

d3.latencyHeatmap()
    .width(600);

latencyHeatmap.x(accessor)

Defines an x accessor which is called for each row in data. Must return a Date object, which must correspond to the timestmap of the bucket. If not set, defaults to function(d) { return d[0]; }.

Example:

d3.latencyHeatmap()
    .x(function(d) { return d.x; }); // d is { x: Date, y: number, count: number }

latencyHeatmap.xFormat(formatter)

Defines an accessor which can be used to control how tick labels on the x-axis are formatted. formatter is called with the x-value for the tick, which is a Date object. If not set, defaults to the d3 default time axis tick formatter.

Example:

d3.latencyHeatmap()
    .xFormat(function(dt) { return dt.toLocaleString(); });

latencyHeatmap.y(accessor)

Defines an y accessor which is called for each row in data. Must return a number, which corresponds to the y-value of the bucket. If not set, defaults to function(d) { return d[1]; }.

Example:

d3.latencyHeatmap()
    .y(function(d) { return d.y; }); // d is { x: Date, y: number, count: number }

latencyHeatmap.yFormat(accessor)

Defines an accessor which can be used to control how tick labels on the y-axis are formatted. formatter is called with the y-value for the tick. If not set, defaults to the d3 default linear axis tick formatter.

Example:

d3.latencyHeatmap()
    .yFormat(function(y) { return y + " ms"; }); // y values are denoted in ms

License

This project is licensed under the MIT License.