State Election Map now available!

My latest project, State Election Map, is now available! It’s a neat way to visualize US presidential election results from 1972 to 2016.

The coolest part is that you can look at each state’s result relative to the national popular vote, so you can see states becoming more Democratic/Republican over time. (check out California and Alabama going on opposite trajectories…)

Other interesting observations: Nixon won by a ton in 1972 (which means that whole Watergate stuff was really unnecessary!), Reagan won by a ton in 1984, and check out the 1976 bizarro-world map! I guess that’s what you get when you have a Southern Democrat running before the Southern Strategy had entirely taken hold…

From a technical perspective, the map is built in React, which I’ve used before, and TypeScript, which was new to me. And I’m a big fan! Using Visual Studio + TypeScript meant I got helpful syntax errors at edit-time, which I’m really not used to in a JavaScript-y language.

I did my best to separate the map/timeline parts into separate components, so I’m hoping to publish them separately and eventutally rewrite my same-sex marriage map to use them too. But that’s a ways down the line!

Man, Javascript is still kind of dumb

I’m working on rewriting my floating point to hex converter with React. This time I thought I’d do it “right” and use all the nifty Javascript tools that everyone complains about instead of just putting a bunch of inline Javascript/JSX in an HTML file, even though that works well enough. Long term, I’d like to rewrite the marriage map with React and D3.js, so I thought this would be a good dry run.

But, maaaaan:
– I literally had to buy a React+d3.js ebook to figure out how to get all this crap set up. (the book is pretty good, by the by)
– The book recommends starting from a particular git repository. To clone that on my linux machine I had to set up some SSH key stuff, which seemed like overkill. (why do I need to do that for anonymous access?)
– To set it up, it downloads something on the order of 300 packages through npm. I wish I were exaggerating.
– Building it (even without minifying the source!) takes a solid 6 seconds on my desktop machine. This is for a ~100 line javascript file. The non-minified version is more than 2 MB of Javascript! Even the minified one is ~180K, which seems like way too much.
– React now recommends you use ES6 instead of calling React.createClass(), and there are some niceties there. But there also some stupid gotchas, like the fact that you have to call .bind(this) on every method for it to be able to access this, because Javascript is the worst.
– For some reason I’m not able to debug with Firefox’s debugging tools. (luckily Edge seems to work well)
– I wasted an hour because the new fancy fetch standard (not supported in some versions of IE so you need a polyfill) has a method called text() that returns the text of the response. Wait, no, it actually returns a promise that has the text of the response. I never realized how much I liked C#’s standard of ending asynchronous methods with “Async” before…

Anyway, I think I’m past all this crap, but I’m starting to remember why Javascript is terrible!