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-worker

v1.0.3

Published

Render D3 charts inside background process (worker)

Downloads

6

Readme

d3-worker

preview

<head>
    <!-- Enable <d3-worker> tag -->
    <script src="../dist/d3-worker-wrapper.js" type="text/javascript"></script>
</head>
    
<d3-worker renderer="../dist/test_render.js" type="json" source="../test/cor.json">
    <set name="sortBy" value="name" />
</d3-worker> <!-- repeated 4 times in example -->
// test_render.js
export class Render extends BaseRenderer {
    constructor() {
        super();
        this.register();
    }

    sizeHint(size) { /* tell the host chart its dimensions to reflow */ }
    load(data) { /* fetch data for rendering from *source*  */ }
    render(config) { /* draw witn d3 here */ }
}
new Render();

Live example

Synopsis

This library does rendering of the d3 chart in two stages:

  1. Worker stage. Renders SVG in a background process into fake-DOM.
  2. Component stage. Now SVG is subdued to the real-DOM component and requires only updates, which are fast.

Both stages share the same renderer code.

The point is to allow interaction with some d3 charts while other d3 charts are being loaded and rendered, the first time slowly.

It's still a work in progress package, any contributions or critique would be appreciated!

Install

npm install d3-worker

Usage

Just use the <d3-worker> tag as above and include dist/d3-worker-wrapper.min.js in your html file.

Settings can be passed to renderer script by <set> tag.

There's an example in /docs:

  • index.html
  • renderTest.js

run server from package root, go to http://localhost:8000/docs

Try it on github pages

Dependencies

  • Web Components support in browser (turn it on in FireFox by setting dom.webcomponents.enabled=true, dom.webcomponents.customelements.enabled=true)
  • nodom library for fake-DOM (using forked version)
  • D3 library
  • Spin.js library for nice spinner
  • rollup for building

Issues

There're two things can have negative affect on performance:

  • serializing and de-serializing of the fake-DOM.
  • layout reflow when inserting fake chunk received from worker.

The latter is resolved by means of Shadow DOM ability to encapsulate its contexts read here about CSS Containment.

The side effect is you have to provide size hint for component manually. Otherwise, when size is being calculated naturally, e.g. regarding with the content have been generated by d3, the reflow time taken cancels all the positive effects of parallel processing.

Todo

  • [ ] Remove duplication of d3 library code base for wrapper & renderer
  • [ ] Fix config passed to render
  • [ ] component.updateFinished event
  • [ ] cleanse workers
  • [ ] Use class instead of ugly renderer boilerplate
  • [ ] Custom shadow DOM Styles
  • [ ] Render to raster. Requires Offscreen Canvas feature
  • [ ] Make sane ES6 exports
  • [ ] Replace eval() with dynamic import()
  • [ ] Import thru <link rel="import">
  • [ ] Zero-copy transfer from worker
  • [ ] Provide wrap() for usage without components
  • [ ] Add docs
  • [ ] Test with polyfill