Skip To Main Content

d3.chart v0.2: Iterating on Reusability

Posted by Mike Pennisi

Feb 21 2014

It’s been about eight months since we announced d3.chart, and today we’re excited to release a new version of the framework for creating reusable visualizations. We’ve strived to incorporate as many of the lessons we learned in the eight months since the initial release.

For detailed explanations of these changes, see our migration guide and the project wiki.

Simplifying Internals

Any developer who has been writing software for more than 6 months knows what regret feels like. Our old code often prompts questions along the lines of, “What was I thinking?” I wish it weren’t the case, but the same phenomenon applies to code you promote for general public use.

For instance, we know that “KISS” is a popular acronym for “keep it simple, stupid”. This tenet holds particular importance to open source projects, where collaboration is contingent on the approachability of the source. Somehow, knowing these things did not stop us from writing a function that was best-named variadicNew. Sure, it allowed chart constructors to accept any number of arguments, but this feels like a minor perk when compared to the complexity it introduces to the library internals. We’ve removed it in version 0.2 for simplicity’s sake.

Read more about chart initialization in our guide here.

Improving Composability

We’re also familiar with the benefits of the single-responsibility principle. This did not stop us from designing a chart method that both created a new chart and attached it to the parent—Chart#mixin. In version 0.2, charts are created with a constructor and attached in a separate operation with Chart#attach. This grants chart creators finer control when composing charts from other charts.

Read more about the attach method in our guide here.

There has been a longstanding challenge in composing multiple charts that each require different portions of the parent’s data. We experimented with less-than optimal workarounds to address this (for example, overriding an instance’s transform method to serve this purpose), but we ultimately decided we needed to change the library to help out. In version 0.2, we are introducing Chart#demux: a method that allows separating the incoming data for the various attached charts more easily.

Read more about the demux method in our guide here.

Moving Forward

We’re dedicated to making d3.chart as good as it can be, and we’re full of ideas for where it can go next. We’ll be revisiting Chart#mixin with an eye towards reusable visualization “components”—elements like tooltips and keys that are intended to supplement other charts. We’ll look at how attachment Charts might themselves be data-driven (enabling visualizations with variable number of data series). We’ll see if d3.chart might more cleanly integrate with D3.js’s Layouts and Lines. And of course, we’ll continue working with the library users to identify new opportunities.

We don’t know where d3.chart is going, but we’re excited to figure it out with you!

Comments

We moved off of Disqus for data privacy and consent concerns, and are currently searching for a new commenting tool.

Contact Us

We'd love to hear from you. Get in touch!