US Congressional Districts AR
Updated 6 years ago by Flourish team
How to use this template
This template is designed to show election results by Congressional district for the United States House of Representatives. States within the map can be selected by moving the camera using a cursor or the orientation controls on a mobile device.
Camera Requirements
Users of mobile devices will be prompted for camera access. This is not required but enhances the experience. In order for access to be allowed this visualization must be served over https.
Data requirements
This visualization requires one data table. Each row represents a candidate, their district, state, party, and percentage of the vote recieved. Within a given district the candidate with the highest percent value will be displayed as the winner.
Credits
Created by Pitch Interactive and Google News Lab.
API information
This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.
template: _732
version: _5
Template data
There are three different formats in which you can supply data to this template. The most convenient for you to use likely depends on the source of your data, as described below.
1. Array of arrays, and a bindings object
You can supply arrays of arrays to opts.data
, which might look
like:
{ data: { results: [ [ "ResultsColumn1Value1", "ResultsColumn2Value1", [ "ResultsColumn1Value2", "ResultsColumn2Value2", [ "ResultsColumn1Value3", "ResultsColumn2Value3", ... ] } }
where each array of arrays represents the rows in a data sheet.
To tell the API how the values from each column should be
associated with the keys that the template is expecting, you must also supply
an object attached to opts.bindings
. (The meanings of the
keys in the bindings object are documented
below.) The minimal bindings you can
supply for this template are as shown in this example:
{ template: "_732", version: "_5", bindings: { results: { state: 0, // index of a column in your data district: 1, // index of a column in your data candidate: 2, // index of a column in your data party: 3, // index of a column in your data percent: 4, // index of a column in your data } }, data: { results: [ [ "ResultsColumn1Value1", "ResultsColumn2Value1", [ "ResultsColumn1Value2", "ResultsColumn2Value2", [ "ResultsColumn1Value3", "ResultsColumn2Value3", ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_732", version: "_5", bindings: { results: { state: 0, // index of a column in your data district: 1, // index of a column in your data candidate: 2, // index of a column in your data party: 3, // index of a column in your data percent: 4, // index of a column in your data } }, data: { results: [ [ "ResultsColumn1Value1", "ResultsColumn2Value1", [ "ResultsColumn1Value2", "ResultsColumn2Value2", [ "ResultsColumn1Value3", "ResultsColumn2Value3", ... ] } }
2. Array of objects with arbitrary keys, and a bindings object
This format is most likely useful when you have data from an external source,
such as CSV data loaded from d3-dsv.
You should supply this attached to the opts.data
, which might look
like:
{ results: [ { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, ... ] }
... but with the keys being the column headers from your
source data instead. You must also supply an object attached to
opts.bindings
. The minimal bindings you can
supply for this template are as shown in this example:
{ template: "_732", version: "_5", bindings: { results: { state: "ResultsHeader1", district: "ResultsHeader2", candidate: "ResultsHeader3", party: "ResultsHeader4", percent: "ResultsHeader5", } }, data: { results: [ { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_732", version: "_5", bindings: { results: { state: "ResultsHeader1", district: "ResultsHeader2", candidate: "ResultsHeader3", party: "ResultsHeader4", percent: "ResultsHeader5", } }, data: { results: [ { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, { "ResultsHeader1": ..., "ResultsHeader2": ..., ... }, ... ] } }
(As before, the keys containing "Header" would be replaced by column names from your data source.)
3. Array of objects with template-defined keys
There is an alternative format you can use, which is likely to be easier to
use if your data is not from a spreadsheet source. With this alternative format
you supply your data to the template as
an array of objects, attached to opts.data
, where the keys must
be those used by the template, as documented below. In this case
there is no need to supply a bindings object, since the key names are already
those expected by the template. The required properties in the data
object are as follows (scroll down for a
description of what each property is):
{ template: "_732", version: "_5", data: { results: [ { state: ..., district: ..., candidate: ..., party: ..., percent: ... }, ... ] }, ... }
And the full list of all possible properties is as follows:
{ template: "_732", version: "_5", data: { results: [ { state: ..., district: ..., candidate: ..., party: ..., percent: ... }, ... ] }, ... }
Meanings of the template data keys:
- results.state: state
- results.district: district
- results.candidate: candidate
- results.party: party
- results.percent: percent
Template settings
Options for opts.state
.
About
title text
Title. Visualization Title
description text
Description. Introductory and explanatory text
action text
Action. Action button text
Colors
Democratic color
Democratic Color. Color used for Democratic Districts
Republican color
Republican Color. Color used for Republican Districts
Other color
Other Color. Color used for Other Districts