599 points · by kickout · 6y ago · 92 comments
Since 2011, there were already numerous cycles of the best of breed JavaScript SPA frameworks and libraries (I'm talking everything from jQuery, through AngularJs, to React), but in data visualization, D3 seems to hold its position very well.
What are the things that D3 did right to get the acclaim, and why does it keep it for so long?
D3 is approaching 10 years since the initial release, did it stand the test of time and will it keep its power for the next 10 years?
Once upon a time, there was an infovis library for Java called Prefuse. Then the developers abandoned that library for a Flash infovis library called Flare. A JS library called Protovis was inspired by Flare, and then Protovis itself was replaced with D3.
I've used 3 of those libraries (never wrote any Flash code). The only one I would actually recommend people use is D3--it's literally the first (honestly, only) infovis toolkit I've used that doesn't feel like pulling teeth to get anything done.
What D3 does differently from its lineage is that it is data-centric. Each datapoint is an object, corresponding to a DOM node, and the layouts in D3 don't actually draw anything; they just set properties on the object--you're responsible for actually converting those into setting SVG properties for display.
It sounds like this would be a nasty headache, but this way is actually much better than the traditional way of handling things (where the visualization is essentially treated as a display widget in a normal GUI toolkit). Any time you want to progress beyond a basic "display a graph with static data," you start to need a lot more fine-grained control over display elements. Want to link multiple displays of the same dataset, so clicking on one in one screen highlights them in all the others? That's very hard in prefuse, but quite easy in D3.
Luckily there's now plenty of d3 wrappers to cover common cases.
d3 (especially now that they've broken the bits and bobs into discrete packages) takes a very unixy philosophy: do one thing and do it well. d3 lets you iterate over your data and get useful items back (e.g. scales that you can use to create geometric shapes for a chart). It's intimidating for some but offers a ton of flexibility you don't see with other charting libraries.
Mike Bostock also put a lot of effort into making sure that d3 lets you create beautiful charts.
Every other charting library I've seen takes a very different approach. Often enabling you to create ugly, inflexible charts.
As a dev, what D3 did right for me is kept the code stable, provided clear sample code for most use-cases, the internet (thanks folks) made lots of runnable examples available via blocks and jsfiddle, maintained precise documentation (even for older versions in github as markdown files) and has almost no external dependencies (so my local .js+.html files from 3 years ago still work without needing any broken npm install or jspm install)
Moving from v3 to v4 was not as painful as I thought it would be.
Once I got over the core concepts of selections and enter/update/exit cycles it has been a breeze and a pleasure to work with.
Thanks Mike and everyone else who's made reasonable and sensible choices for D3 !
I have been reading two resources about it, https://ourmachinery.com/post/data-structures-part-1-bulk-da... and https://stackoverflow.com/questions/39799874/why-does-javasc....
Traditionally plotting libraries like Matlab and Matplotlib work on arrays of data.
That means: it's conceptually overloaded for doing quick-and-dirty conventional charts, where you just want to plug in a few parameters and have it "just work" - but excellent once you need to customize and make it work with your specific requirements.
That it has the concepts, and a clear notion of them, is the critical difference. Most libraries, most of the time, don't add new concepts, they just have a premade black box of features and functions. Sometimes you want a premade black box, but often you want to open up the box shortly afterwards, and that creates the inevitable trend towards either remaking it as your own box, or being one of hundreds of people who gradually grow it into a monstrosity that does everything.
But a library that is concept-focused doesn't have to get that much bigger: it's just another kind of interface, like a programming language or an operating system, and that puts it on a more sustainable track.
I just ported a D3 solution to OpenLayers for a client and they where over the moon with the speed at which they could implement new features. Mobile touch was the killer for them and made them finally bite the bullet and port, getting a D3 mapping solution to behave correctly on both the desktop and mobile requires a lot of wiring.
Just look how long Processing held its position. People are still using it with P5 on the web, but I think it makes a bad figure compared to D3.
Again if doing advanced visualizations for a large newspaper, commercial presentation, it’s extremely customizable and makes some really beautiful charts.
Or, you know, use PyGal or another server-side charting library: http://www.pygal.org/en/stable/
Is there much of a market for server-side rendering? I've been putzing around with a d3-inspired charting library in Rust mostly as a brain teaser though.
My recommendation to the technical decision makers in those companies who are either confined to Power BI or just feel a lot safer working in that environment (instead of investing heavily in development time to recreate the same thing) is to embrace the Power BI service out of the box as much as possible, and then if they really need to, create custom D3 Visuals for their reports (yes, this is possible with Power BI, I was quite delighted when I discovered this): https://docs.microsoft.com/en-us/power-bi/developer/visuals/....
I love how it gives an overview of all the d3 modules, then explains them in groups by related functionality. I just started exploring, and will study it over time.
Thank you for sharing your knowledge, the articles are really well-done and high quality. I'm guessing the visualization of d3 modules is done in d3 itself. Beautiful in concept and presentation.
This was remarkably more intuitive and clear and I breezed through
It took me some time to realize that running cells actually change something in the country list.
Would you or someone care to elaborate? Do we mean the 'linking' between 'nodes' (cells) as an interpreter/compiler would do over a file/object structure?
Thus I assume, opening a world of options e.g. for vectorizing performance, type checking and all?
If so, we have in one such notebook a true slice of "visual" IDE the kind of which Microsoft could only ever dream about! (so far) ;-)
[Side-related note: I'm amazed at the emergence of the notebook paradigm over the last 10 years, accelerating for at least 2-4 now. See how they do it at Netflix. There's a case to be made that the notebook paradigm could really bridge wide open the "programming rift" between nerds and, well, everybody else, at least in skill-driven professional contexts. There's a short way from here to a slew of clever domain-driven script languages plugging straight into BI.]
A DAG, or Directed Acyclic Graph. The most familiar example would be dependency graphs between packages. Or the dependency graph of your code (as interpreter/compiler would look at it). Or, any dependency graph in general.
So the way reactive programming works - whether in React, ObservableHQ, or Excel - is this: you have these computation units (cells, pure functions) which have dependencies and they themselves are dependent upon. This forms your calculation graph, which you calculate by starting at the node without dependencies and evaluating one node after another in topological order[0].
The main optimization this permits is reducing the number of calculations: since dependencies are accounted for and navigable, whenever a node X changes, only nodes that depend on it need to be recomputed (and their dependants, recursively).
"vectorizing performance, type checking and all" are not related to this concept. Reactive programming deals just with the dependency graph and (re)computing the right amount of nodes in the right order. Contrast that with a typical REPL model (or Jupyter model), where you execute cells one after another in the order you wrote them, and they mutate the global state of the application.
RE your side note: yes, the notebook thing is a curious phenomenon, especially in a worse-is-better way (why did it have to be first Python, and now JavaScript?!). It's much older than that, though - you could trace its origin through things like Mathcad (essentially a buggy Jupyter requiring lots of clicking, but which produced a convincingly-looking math papers, and could do proper symbolic calculations out of the box), back to the early Lisp era (you don't have to type things into a Lisp REPL; if you type them in a file and annotate with comments as you go, you get a half-baked plaintext Jupyter).
--
[0] - https://en.wikipedia.org/wiki/Topological_sorting - i.e. you turn a graph into a sequence sorted so that the dependencies come before the things that depend on them.
While I do think there could be UX improvements, I don't think this is a flaw in Observable.
So, I am surprised that there is no standalone REPL in that style. The closest things I've found are ObservableHQ and RunKit (the other is much more Jupyter-like, but still - AFAIK runs code in the backend).
However, it does have its performance degradation once you go beyond 3000 nodes of data. So we are now in the process of rebuilding our mapper in Canvas+WebGL via Pixi.js.
[1]https://app.visualsitemaps.com/share/7b4fd8556b102ed739cc308...
e.g. https://github.com/danielgindi/Charts has so many default options set for a graph that 80% of code is doing something like
chart.option.isEnabled = falseI have a browser extension (treeverse.app) where the entire UI is D3. I probably wouldn't write it that way today, but the codebase dates back to ~2014 and it's held up fine.
I tend to leave DOM manipulation to Vue.js unless I need to animate transitions between states. I find it easier to reason about binding data to an html/svg template with Vue than to mess with d3 data joins and enter/update/exit pattern.
d3 is and stays an impressive piece of work.
D3.js, as someone else already noted, is "jQuery for data". And yes, it has its good parts, but the same as for jQuery) the problem is with:
- mixing static HTML/SVG with generated
- no modularization (every modularization is custom)
For the latter, while it may not be a big deal for small projects, for bigger it sucks.
For big stories, I created a game in D3.js. Modularization was... well, argument why I rewrote it a few years later to Vue.js.
For projects with Vue.js, the performance was not my concern.
In any case, if needed, you can use D3.js rendering within a Vue component.
Alternatives at a low level? Hard to say - it really does allow you to do a lot at a very low level if you want BUT...
- Vega Lite / Vega
- HighCharts (paid)
- ChartJS
- Raphael (unsure if this is still used as much)
- Leaflet / Turf for GIS visualizations
- Server-side? PyGal? http://www.pygal.org/en/stable/
If you don't want to go so low-level there are a huge number of D3 abstractions that allow you to pick your chart and work with the data. Britecharts from EventBrite is one example of an actively maintained abstraction. http://eventbrite.github.io/britecharts/
As soon as you go to react & friends, most of the d3 model does become redundant, and Yet Another Thing to burden the team. There's still a temptation to reuse beautiful d3 gallery items posted by others, but generally, they're annoying to patch up & now you must maintain them. Better to use dedicated maintained libs if that's what you want. There have been attempts to do Standard D3 Chart libs, but afaict it's a graveyard of abandonware, and I approach most efforts here with strong caution. (The trend for the last few years has been each bigco to release their own NIH framework and then abandon as the authors leave, and little incentive for D3 design consultants to maintain old projects.)
I agree that React / Redux state can take the place of a lot of the D3 models. That said, it's nice that D3 handles entry / updates and changes so you can point to redux and it "just works" and all the transitions, etc are handled as your app state is handled.
https://vega.github.io/vega/about/vega-and-d3/
Vega lite is what I use as my day to day web graphing driver (it exports to svg which is awesome...)
We're still happy with that decision :)
I liked it quite a bit. It's pretty fast and decently easy to use. Plus, all the examples Mike Bostock has thrown around online really helped for giving me examples of how to do various visualizations I was interested in.
There's more work to do but it's a start