This simple server and D3 visualization script renders data from the Caselaw Access Project API and renders it to an html page as an SVG. It belongs as part of a poster creation workflow as the second step in a three step chain.
-
The first step, viewable here, is responsible for harvesting and aggregating data from the CAP API. It consumes the API, and makes it easy to write
.tsvfiles containing structure that's consumable by this tool. -
The second step, this tool, is responsible for reading the simplified
.tsvfiles produced in step one, and rendering them as SVG files. -
The third step in the process involved extracting the SVG from the browser, saving it to disk, and opening it in illustrator to add additional textual and explanatory detail.
To use this tool, run through the following steps.
-
After cloning this repository, run
npm installto download and install the required libraries. -
Place the
.tsvyou want to render in theserver/static/datafolder in this repository. This directory is served as a statically accessible directory by express, and the front-end D3 code looks for your.tsvfile here. -
Look at the
/server/scripts/main.jsfile. This is the entry-point for the front-end script. There are three easily controllable parameters here. ThetsvFilenameparameter should be the name of the tsv file you want to visualize. This file should be located in theserver/static/datadirectory. Thewidthparameter is the final width of the svg in points. Thewidthparameter is the final height of the svg in points. Using correct points values for the paper size you'd like to render is helpful once the SVG is in illustrator. -
After updating the filename and other parameters, run
npm run buildfrom the command line. This will compile the new javascript with your changes. If you prefer, you may runnpm run watchinstead. This will create a watch server, which will live-reload your styles and front-end scripts, if you're looking to get a bit deeper into the styling or scripting and modify the visualization. -
In the project directory, run
npm run startto start the lightweight express server that will parse your.tsvand render the resulting SVG visualization. -
Point your browser to
http://localhost:8080. You should be able to see the rendered SVG at that url on your machine. If you rannpm run watchin step 4, you should be able to adjust styles, and see the visualization hot-updated.
When the visualization is to your liking, you might try this tool from the New York Times to extract the SVG for print.
If the tool doesn't seem to work (We've experienced a few issues with this tool in the past), the svg styling is self-contained enough that it should be possible to download the SVG manually. Open the inspector, right click on the svg element containing your visualization, and click "Copy Element". Then open your favorite text editor and paste the element into it. Finally, just save the new file as a .svg. From there, you should be able to open the file in any vector drawing application.
Nic Schumann and Matt Phillips built this on April 29th, 2019 for Public Good Studio in Menlo Park, California.