Software Ascending

A software development blog dedicated to high-quality content for experienced engineers who want to…

Follow publication

Member-only story

Not-So-Magic Data Binding in D3.js

--

Example visualizations generated by D3.js, courtesy of d3js.org (https://github.com/d3/d3.github.com/tree/master/ex)

This article describes an epiphany that finally got me caught up with everyone else already successfully using D3.js. If you’ve tried using D3 but struggled to understand how it works and how you’re supposed to use it, this might help. This article does not go into details of how to write D3 code; there are lots of good tutorials and documentation for this available elsewhere online. This article will provide a mental model and clarification that should help you better understand and make use of those tutorials.

I’ve used D3.js for data-visualizations on-and-off for a few years but never considered myself very skilled with it. In particular, I could never understand the apparent magic of data-binding. As a result, I always felt like I was doing things gracelessly, taking a brute force approach to updating visualizations when data changes.

Well, I’ve finally gotten my head around it, and guess what: the brute force approach is essentially the correct one. The data-binding technique that D3 uses is not nearly as magical as I had assumed, and realizing this has enabled me to not only understand how to use D3 effectively but perhaps even to see the grace in how it works.

What D3 Does

Let’s start with a mental model of how D3 works. It really comes down to this: you’re matching up a list of DOM elements…

--

--

Software Ascending
Software Ascending

Published in Software Ascending

A software development blog dedicated to high-quality content for experienced engineers who want to keep learning and growing.

Brian Mearns
Brian Mearns

Written by Brian Mearns

Software Engineer since 2007 ・ Parent ・ Mediocre Runner ・ Flower and Tree Enthusiast ・ Crappy Wood Worker ・ he/him or they/them

No responses yet

Write a response