Code reduction

This graph looks like all the other graphs I’ve ever drawn. Round the back, though, it’s very different. The code is a good few hundred lines less than it used to be, so the whole thing is maybe half as long as a similar variant might have been a few months ago. It means that the whole thing is more manageable, replicable and easier to debug. So. Progress.

The main difference is actually how the data is laid out behind the graph. Before, it used to be a table, with each column drawing a new line. Now it’s set up in such a way that each column is all the lines, and the click moves from one column of data to another, rather than one set of columns to another. Doing that means I’m specifying sets of lines rather than individual lines, which obviously makes the whole thing quicker, especially when I’m transitioning from one to another.

To do this I used the D3 Tips and Tricks book/ site, and as ever, got a little bit of help off Stack Overflow.

Comments are closed.