Git Product home page Git Product logo

datasci-sf-tree-map's Introduction

sf-maps

Mapping San Francisco

Make Choropleths by:

  • census tracts
  • city assessor lots (blocklots) (not yet!)
  • election precincts
  • neighborhoods
  • supervisor districts
  • zip codes

Data from DataSF

Libraries

D3
Colorbrewer
d3-legend

Use

This code uses the pattern from Towards Reusable Charts.
First, you need to have somewhere for the map to go. Add an element to your html file:

<div id="map_container"></div>

The tooltip needs styles from css/stylesheet.css, specifically those for #tooltip and .hidden You need to include d3.v3, topojson, d3-queue, d3-legend, and choropleth.js in the <head>:

<script src="vendor/d3.min.js"></script>
<script src="vendor/topojson.js"></script>
<script src="vendor/d3-queue.js"></script>
<script src="vendor/d3-legend.js"></script>
<script src="js/choropleth.js"></script>

In your JS file, declare some user-set variables:

  • whatMap determines the geography drawn
  • theDataFile path to the csv of data to be rendered
  • idProperty the column from the csv that corresponds to the geographic id
  • dataProperty the column of interesting data associated with the geography
  • mapElement DOM element for the map to be drawn in

The choropleth variable is where all the magic happens:

var choropleth = Choropleth()
...
d3.select(mapElement).call(choropleth)

Options

Before initial render

The following string variables determine how the choropleth gets drawn.

  • whatMap determines the geography drawn
  • theDataFile path to the csv of data to be rendered
  • idProperty the column from the csv that corresponds to the geographic id
  • dataProperty the column of interesting data associated with the geography
  • mapElement DOM element for the map to be drawn in

whatMap

theDataFile

Needs to be a csv file with column headers. One column, identified as idProperty, required to match values from data/geometa.json

idProperty

See required ID values in data/geometa.json

dataProperty

The column heading from your data csv

mapElement

CSS-style selector, default #map_container

After initial render

Use the following JS functions to make changes on the fly

choropleth.quanta( number )

Change number of "Color Buckets". Can also be set before rendering.
Where number is between 3 and 9. See vendor/colorbrewer/colorbrewer.css for available sets
Example: choropleth.quanta(3)

choropleth.colorScheme( string )

Change color scheme. Can also be set before rendering.
Where string is a colorbrewer scale. See vendor/colorbrewer/colorbrewer.css for available colors
Example: choropleth.colorScheme('Reds')

changeData( string )

Change the data color encoded initially as dataProperty
Where string is the property of the csv dataset you want mapped.
Example: changeData('population')

datasci-sf-tree-map's People

Contributors

thfield avatar sbarton272 avatar

Stargazers

Alex Gurrola avatar

Watchers

Dylan J. Sather avatar Jesse Szwedko avatar Mike Zawitkowski avatar geoffnet avatar James Cloos avatar Peter W avatar Sanat Moningi avatar  avatar Judy5000 avatar 24soaringSoarcererszSauronMelkorSargerasAndKai avatar  avatar Rocio Ng avatar Josh Freivogel avatar Abby Stevens avatar Nathan Chau avatar Jude Calvillo avatar billie avatar Vincent La avatar Daniel Zou avatar Justin avatar Ryan Lim avatar  avatar Catherine Zhang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.