by zackzackzack · 14y ago · 0 comments
1.) To convert numbers, they use +number, where number is a string. That is some excellent short hand and relies on automatic type conversion in javascript. Not sure what the speed is like, but I imagine it doesn't slow down things much,
2.) They forgot that they had jQuery loaded in already. You can see this by looking at the lines when they define w and h. They use d3 to get the height and width in a awkward way. $("vis").width() would have done the same for less thought.
3.) They are using some tools to check for or create automatic clean javascript. Not a semi-colon or tab out of line. Probably jslint, because they use a forEach at some point and I don't believe coffeescript uses forEach's in it's output. Coffeescript is probably worth the time to learn then; All those function(d){return d.a} become just (d)-> d.a.
Depending on your style, this could be useful as well: getter = function(attr){ return function(d){ return d[attr]; } }
ds.attr("x",get("x"))
4.) I am embarrassed I didn't know d3.svg.axis existed. That saves time and mistakes.
All in all, well done. Learned a good amount from reading through that. Thanks!
And btw, no code cleanup tools in use, just my OCD. ;) I haven't used Coffeescript yet. Will have to check it out.