Rendering in Canvas on the server
How about we do another one of those things right now? As mentioned before, the output from our little server app is pretty dull. Let's render a map using Canvas.
We haven't really talked about it much, but Canvas is another cool way D3 can be used to render data. Instead of writing a bunch of elements into a DOM tree format like SVG, Canvas renders pixels in a 2D plane, which can be much better for performance. It's a much different workflow than what we're used to, and I don't focus on it too much in this book because it tends to be harder to debug for beginners, but let's give it a shot and deep dive into it for one example.
By the way, it's worth noting this is a super weird way to use Canvas compared to how we can in the browser; normally, we'd just rely on the browser's built-in Canvas renderer, but we don't have that luxury on the server. Note, however, that the Canvas code we're writing for node-canvas
will work the same way in the browser, in case...