D3 & Web Workers

260 views
Skip to first unread message

Owen Densmore

unread,
Jan 11, 2019, 1:48:43 PM1/11/19
to d3-js
There have been some (silly) articles on D3 being both difficult and out of date. I responded to one of them on medium.com with the comment below.

It did prompt me, however, to come here and ask my question to those much more experienced than I am.

Basically I'm using D3 in a clean Model/View split and running the model in in Web Workers, and even sometimes running the View in the worker and simply passing back an ImageBitMap. But my problem is that I don't know how to separate D3 into its model/view components, which parts are worker-safe.

I believe it would require at least a simple document on which of the 30 repos use the DOM, and which don't. Better yet would be a VirtualDOM of some sort that would allow all of D3 to be used in a worker.

=================================================

I find D3 fascinating, but it’s comprised of 30 repos (see https://unpkg.com/d3/index.js) which is bound to be daunting!

Nonetheless, it certainly gains my respect for brilliant architecture.

HOWEVER! It has a one problem that I see for my continued use of it: Web Workers. Due to a focus on SVG (which I do like, BTW) there is likely a lot of d3 that won’t work in workers.

This might be solved with its own Virtual DOM, and possibly a 31st repo with Worker tools making all of d3 worker friendly. I’ve recently been faced by that for my work and it has been a really fun journey. Hence my concern.

So Mike Bostock, if you see this, could you comment? Possibly a Model/View split? (that’s how my project ran into Worker use)


Mike Tahani

unread,
Jan 29, 2019, 1:04:54 PM1/29/19
to d3...@googlegroups.com
Howdy Owen!

Mike (not Bostock) here. I’m not sure that D3 focuses on SVG, but since a lot of data-based DOM manipulation (read: visualization) happens using SVG, there are a lot of helpful utilities for generating SVG. Afaik, d3-selection is the only module that actually does direct DOM manipulation. All others are utilities for - basically - wrangling data and doing math. 

I use D3 daily without touching the DOM: calculating scales, manipulating data from APIs, calculating bounding boxes for irregular geometries, etc. All of that can be done in a worker and sent back to the frontend where it can be placed into the DOM.

Cheers,
Mike T

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Owen Densmore

unread,
Jan 29, 2019, 2:21:59 PM1/29/19
to d3-js
Thanks Mike, sounds hopeful.

   -- Owen
Reply all
Reply to author
Forward
0 new messages