Fork me on GitHub
Loading...

ire_census.js

This application is built upon a reusable javascript library that is meant to make it very easy for you to add census data to your own web apps. If this library doesn't completely serve your needs, you may wish to read more about the data JSON API and geographic boundary service which the library uses.

Where do I get it?

The library is stored on GitHub. The easiest thing to do is to load it from there using this HTML:

<script src="https://raw.github.com/ireapps/census/master/tools/js/ire_census.js"></script>

Of course, you can also download it and serve it locally, min-ify it, etc.

Note: this library depends upon jQuery. You must load the jQuery library before loading ire_census.js.

What does it do?

The library creates a javascript "namespace" ire_census. All functions described below are called using that namespace, e.g. ire_census.get_state_fips('Illinois')

AJAX helpers

The most interesting features of the library are those which simplify the process of making an AJAX call to fetch SF1 data or census geography data.

do_with_sf1_data(geoid,handler)

Arguments:

do_with_geodata(geoid,handler)

Arguments:

do_with_contains_results(point,handler,options)

Arguments:

do_with_available_states(handler)

Arguments:

do_with_labels(handler)

Arguments:

Data helpers

sf1val(sf1_json,field,year_or_cat)

Given an SF1 data JSON object (of the type passed to the callback for do_with_sf1_data) and a field code, return the value for 2010. Optionally, a third argument may be passed to retrieve other data: '2000', 'delta', or 'pct_change'

sf1val_pct(sf1_json,field,year_or_cat)

Given an SF1 data JSON object (of the type passed to the callback for do_with_sf1_data) and a field code, return the 2010 value as a percentage of the total population or number of housing units for that geography. Optionally, a third argument may be passed to retrieve other data: '2000'. The other two categories ('delta' and 'pct_change') are not meaningfully implemented for this function.

table_name(label_data, table_code)

table_universe(label_data, table_code)

table_size(label_data, table_code)

Given a label_data structure (of the type passed to the callback for do_with_labels), and a table code, return the name, universe, or size (number of fields) for that table.

label_text(label_data, field_code)

Given a label_data structure (of the type passed to the callback for do_with_labels), and a field code, return the name for that field. Note that for fields which are "children" of other fields, the label may be difficult to interpret without information about the parents. That information is in the label_data structure, but you are on your own for navigating it.

get_state_fips(state)

Given the properly capitalized name of a state (or state-like geography), return the two digit FIPS code for that state.

get_fips_state(fips)

Given a two-digit FIPS code for a state (or state-like geography), return the name of that state.

table_from_field(field_code)

Given a field code, compute the appropriate table code. e.g. given P001001 return P1

build_bulk_data_url(state,sumlev,table,format)

Given a state, summary level, and table, compute the URL for downloading the bulkdata export for that combination.. If omitted, the 'format' is assumed to be CSV, and for the moment, only CSV data is available from the IRE census service.

build_shapefile_url(state,sumlev)

Given a state FIPS code and a summary level code, compute the URL for downloading the corresponding official census shapefiles. At this time, only 040 (state), 050 (county), 060 (county subdivision), 140 (census tract) and 160 (census designated place) are supported.

table_comparator(table)

Probably misnamed, this is actually a key function meant to be used with a javascript sort function to make P/PCT/PCO tables sort ahead of H/HCT tables, because that's how the Census does it.

Arguments: