motherjones/us-color-coded-map

Name: us-color-coded-map

Owner: Mother Jones

Description: From Google Spreadsheet to color-coded map of the US, with tooltips.

Created: 2012-12-19 22:54:57.0

Updated: 2016-09-21 22:34:12.0

Pushed: 2014-12-22 21:58:40.0

Homepage:

Size: 640

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

A Google spreadsheet-powered map of the US

Build a color-coded US map from a Google spreadsheet. Good for comparing state metrics or tracking state-level legislation. Here's an example:

screenshot

Examples in the wild

Map: Which States Allow Gay Marriage?

Maps: Solitary Confinement, State by State

Has Your State Outlawed Blowing the Whistle on Factory Farm Abuses?

How it works

MoJo users: Before you get started, follow these instructions.

Each state gets a blurb with a title and deck, and a color based on which category it falls under. All of the data lives in a Google spreadsheet. Note that you can't do markers or individual dots on this map; it's for color-coding each state as a whole.

As for mobile, it works, but truthfully these types of maps suck on mobile. Ideally the map would turn into a color-coded table on mobile. We would love pull requests along these lines.

Modifying the spreadsheet

Make a copy of this template and rename to fit your story.

MoJo staffers: Move the copy into the relevant beat folder in the Mother Jones Google Drive. Change the owner of the spreadsheet to MoJo Data in Share > Advanced.

Here are the columns you'll be working with:

|abbr|headline|body|class| |—|—-|—–|—-| |KS|Kansas|Voters approved a constitutional ban on same-sex marriage in 2005. It was already illegal under state law. A 2012 statute reiterated the state's ban on same-sex marriages. A lawsuit was filed in 2013 seeking state acknowledgement of out-of-state marriages for tax purposes. On November 4, 2014, a federal judge issued a prelimnary injuction against the enforcement of the state's ban. However, that injuction was stayed to allow Kansas time to appeal.|Limbo|

It's best to keep your spreadsheet clean and limited to these four columns, but if you need, feel free to add additional columns for reference. They won't show up in the map, but they won't break it either.

Once you've replaced the spreadsheet data with your own, go to File and click on Publish to the web, then click on Start publishing.

A URL will appear. It will look something like this:

s://docs.google.com/spreadsheet/pub?key=0Arenb9rAosmbdHc4MDVLcEl6bHFhczNKSzZUem1VYWc&output=html

This is your spreadsheet ID or url, which you will later use to connect your spreadsheet to the map.

Modify your project files

MoJo users: By now you should have a local copy of this project repository on your machine. If you don't, go back and follow these instructions.

In index.html:

Paste the ID or url you just copied from your published spreadsheet in place of your_spreadsheet_url_here. The code you are looking for in the index.html file looks like this:

ipt>
us_map ({
  container: 'blurb',
  initial_state: 'CA',
  //proxy: proxy here,
  key: 'your_spreadsheet_url_here',
})
ript>

Next, replace the headline, deck, and legend with your story content. This is the code you're looking for:

<h2>Where is Gay Marriage Legal in the US?</h2>
<p>The most recent status of gay marriage, across the US. Latest state to legalize highlighted below. Click any state for details.</p>

<ul class="list-inline">
    <li><span class="Legal">tag</span> Legal</li>
    <li><span class="Appeal">tag</span> Ban struck down, appeal pending</li>
    <li><span class="Challenged">tag</span> Banned, currently challenged in court</li>
    <li><span class="Banned">tag</span> Banned</li>
</ul>

<aside class="small text-muted">Source: Lambda Legal, Human Rights Campaign</aside>

Modify the legend to match your new classes in this section:

class="list-inline">
<li><span class="Legal">tag</span> Legal</li>
    <li><span class="Appeal">tag</span> Ban struck down, appeal pending</li>
    <li><span class="Challenged">tag</span> Banned, currently challenged in court</li>
    <li><span class="Banned">tag</span> Banned</li>
>

Save your changes. Open up index.html in a web browser and check that your data is showing up correctly. Whenever you make changes to the spreadsheet data, the map will automatically render those changes.

In style.css:

Make sure the categories you added to the class column match the classes in your style.css file. fill, background, and color are CSS properties that assign each class its own color. Each of these properties should have a hex code (e.g. #69A9C5) that denotes the corresponding color for that CSS class.

If your spreadsheet has more than four classes, make sure you create new categories here accordingly, along with their fill, background, and color.

project-specific styles for map and legend */
al {    
fill:#69A9C5;
background:#69A9C5;
color: #69A9C5;

eal {   
fill:#ABD9E9;
background:#ABD9E9;
color:#ABD9E9;

llenged {
fill: #F4A582;
background:#F4A582;
color:#F4A582;

ned { 
fill:#D6604D;
background:#D6604D;
color:#D6604D;

Important note about CSS for SVGs: Since the state shapes are formed by svg paths, the CSS properties you'll need to use are fill instead of background, and stroke instead of border.

Refresh index.html in the web browser and check that your data is still showing up in the map and colored properly.

Stage the map (for MoJo users)

MoJo users: When you're done, upload to s3 and embed in the shell (follow this how to).

Questions?

Hit us up by email, or Twitter: @jaeahjlee or @tasneemraja


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.