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

@redsift/d3-rs-table

v0.1.0

Published

Displays a 2D array as a HTML table using D3v4.

Downloads

7

Readme

d3-rs-table

d3-rs-table is a component that can map a 2D matrix to an old school table/tr/td layout. It serves as a simple example demonstrating the implementation of our reusable chart model for D3 at Redsift and a baseline for comparing view/data binding approaches for other frameworks. Note, this does not utilise d3.transition(). This component is dependent on D3 v4 (Alpha).

Builds

Circle CI

UMD from //static.redsift.io/reusable/d3-rs-table/latest/d3-rs-table.umd-es15.min.js

Usage

Data Format

var data = [ 	
				[ 'a', 'b', ... ], 
				[ '1', '2', ... ], 
				... 
			]

In this model, the first entry is the first row of the table.

Call

Assuming data compatible with the layout above is available:

var tbl = d3_rs_table.html();
d3.select('body').datum(data).call(tbl);	

Updating is simply mutating the data array and calling d3.select('body').datum(data).call(tbl) with the same reusable component instance.

Usage

headerRow0 -> true, header is the first row. false, header is the first col. null/undefined, no header.

text -> data formatting function.

Comparing

Any fair comparison against this component in other presentation frameworks should include the following features:

  • Ability to change the dimensions of the data array and rebind the presentation.
  • Support ragged arrays via the update flow i.e. arrays where the rows of the array may be of different sizes and have this reflect in the generated DOM.
  • Ability to customise the text presentation on demand via a callback. E.g. in the example, the instance of the component constructed uses a function to format the number to 2 decimal places via var tbl = htmlTable().text((d) => d.toFixed(2)).
  • Ability to optionally render the first row or first column of the data set as a th element instead of a td. While style can be achieved using CSS, this demonstrates the ability to express sophisticated DOM element generation rules.

Other points to consider:

  • Sparse arrays should be treated as expected i.e. empty cells should be created for null data elements.
  • The DOM should be allowed to render between every update using an approach suitable for the framework in question.
  • Use a type stable array when running the benchmark e.g. arrays of floats in the reference example.

Performance

One of the primary uses of this component is testing performance of the DOM binding. A monolithic version of the test is available here or as a Codepen here. The times embedded are not fully representative, as they only measure the time spent in the data binding portion of the library. Developer tools e.g. Chrome Timeline > Capture > JS/Paint, provides a more complete picture. Typically a 2500 item data array binds in 8 to 13 ms in Chrome 49 and corresponds to a 25fps once layout, update and paint are done. Safari 9 has a JS time of 3 to 5 ms. Times on a mobile device are visibly slower but acceptable with 16 ms JS times on iOS 9.x with Mobile Safari.

D3 v4 vs v3

One interesting observation when using the D3 v4 Alpha is that the performance averages improve by ~15% with comparable standard deviations. D3.js v4 Alpha vs D3.js v3 Release, note a minor change to the d3.timer API between v3 and v4.