A Better Way to Code

Introducing d3.express: the integrated discovery environment.

Update January 31, 2018: d3.express is now Observable, and we’re live at beta.observablehq.com!

The purpose of visualization is insight, not pictures.

Visualization is a means to an end. A means to insight. A way to think, to understand, to discover, and to communicate something about the world. If we consider only the task of assigning visual encodings, of constructing visualizations, we ignore myriad other challenges: finding relevant data, cleaning it, transforming it into efficient structures, analyzing it with statistics, modeling, explaining our discoveries…

Ghost in the Shell (1995)

Programming is blindly manipulating symbols.

By “blindly”, he means we can’t see the results of our manipulation. We can edit a program, re-run it, and diff the output, but programs are complex and dynamic, so this is neither a direct nor an immediate observation of our edit. By “symbols”, he means we don’t manipulate the output of our program directly but instead work in abstractions. These abstractions may be powerful, but they can also be difficult to grasp. In Donald Norman’s terms, these are the gulf of evaluation and the gulf of execution.

Introducing d3.express

If we can’t eliminate coding, can we at least make it easier for humans, with our sausage fingers and finite-sized brains?

1. Reactivity

The first principle of d3.express is reactivity. Rather than issuing commands to modify shared state, each piece of state in a reactive program defines how it is calculated, and the runtime manages their evaluation; the runtime propagates derived state. If you’ve written spreadsheet formulas, you’ve done reactive programming.

Visual Outputs

Like the developer console, the result of evaluating a cell in d3.express is visible immediately beneath the code. But unlike the console, cells in d3.express can output graphical user interfaces! So let’s visualize our data as a simple line chart.

Animation

How about Canvas? Say we want a globe. We can fetch world country boundaries, and then apply an orthographic projection.

(This looks better at 60 FPS.)

Interaction

If generators are good for scripted animations, what about interaction? Generators again to the rescue! Only now our generators are asynchronous, yielding a promise that resolves whenever there is new input.

Animated Transitions

By default, reactions are instantaneous: when a variable’s value changes, the runtime recomputes derived variables and updates the display immediately. But immediacy is not required and it is sometimes useful to animate transitions for object constancy. Here, for example, we can follow the bars as they are reordered:

2. Visibility

Inline visual outputs improve our ability to inspect the program’s current state. Interactive programming improves our ability to scrutinize behavior by poking: changing, deleting, reordering code, and seeing what happens. For example, by commenting out forces in the force-directed graph below, we get a better sense of their contribution to the layout.

Visualizing Algorithms

A more explicit approach to studying program behavior is to augment the code to expose internal state. Generators help here, too. We can take a normal function, like this one for summing an array of numbers:

Source: bl.ocks.org/mbostock/ca5b03a33affa4160321
The overlapping placement (left) causes the front chain to be cut (right).
When a circle is outside the enclosing circle (left) it must be tangent to the new enclosing circle (right).

3. Reusability

One way to write less code is to reuse it. The 440,000 or so packages published to npm attest to the popularity of this approach.

(This looks better at 60 FPS.)

4. Portability

Notebooks in d3.express run in the browser, not in a desktop app or in the cloud; there is a server to save your edits, but all computation and rendering happens locally in the client. What does it mean to have a web-first discovery environment?

Source: github.com/TheUpshot/leo-senate-model

https://d3.express

Thank you for reading!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mike Bostock

Building a better computational medium. Founder @observablehq. Creator #d3js. Former @nytgraphics. Pronounced BOSS-tock.