Homam's Mind

Sunday, January 12, 2014

D3 Enter - Update - Exit Pattern in LiveScript

Since I first heard of LiveScript a couple of months ago, I've enjoyed programming my small and big JavaScript projects in LiveScript. Here I want to show how LiveScript makes D3 general update pattern easier to work with.



Here's the result showing enter - update - exit pattern in D3 and the gist.

In the above code I'm using LiveScript's property access cascades sugar. Note how it improves the readability of the code and makes it easy to identify enter!, transition! or exit! cascades.

See also how the sampling and shuffle functions are defined by a composition of some functions rather than a for loop that IMHO is much prettier than the original.

Anyway, I enjoy D3 and LiveScript and this two go together like pancakes and syrup!

No comments: