I'm loving exploring the supernaturally awesome D3 Javascript information visualization framework.
So I took my favorite D3 visualization, the Multiple Foci Force-Directed Layout, and converted it to CoffeeScript, a fantastically slick modern language, drawing on Ruby and Python, which compiles seamlessly to cogent JavaScript.
The files included are:
- app.original.js - the original JavaScript example from D3
- app.coffee - my CoffeeScript translation of the above example
- app.js - the CoffeeScript above compiled back into JavaScript
Since I'm learning CoffeeScript, I wanted to check that the compiled JavaScript matched the original JavaScript. This is not as simple as comparing the two files, as there are non-operational difference that I'd like to ignore. So I did what they do in CoffeeScript land: wrote a task in my Cakefile to check for differences. So if you have a CoffeeScript environment set up, you can compile the CoffeeScript to JavaScript with:
cake build
and you can check that the output is (pretty much) the same as the original with:
cake check
This will "sanitize" the JavaScript, ironing out minor distractions, and output the remaining differences (if any) in standard unix "diff" format.
If you are looking at this on Github, you can see a live demo here: bl.ocks.org/1091420
Please feel free to fork this gist, or send me a note, if you see things to improve.
Finally, a big thanks to Mike Bostock, the creator of both D3, the infoviz framework I've been seeking for a long time, and also the awesometown Gist viewer bl.ocks.org.
If you used coffee's
--bare
arg, coffeescript wouldn't add a function wrapper, and you wouldn't have to strip it out in your sanitise task.