Globals
Properties
Methods
Abstract types
Properties
stateNameHash
Example
stateNameHash['01']
// returns 'Alabama'
Parameter
Name | Type | Optional | Description |
---|---|---|---|
stateFips |
string |
|
The state fips code. |
- Throws
-
Error
- If the state fips code is invalid.
- Returns
-
string
- The state name
usBounds USBounds
The bounds of the United States.
Methods
boundariesAvailableForRaceType(raceType) → array
Examples
boundariesAvailableForRaceType('president')
// returns ['state', 'county']
boundariesAvailableForRaceType('senate')
// returns ['state']
boundariesAvailableForRaceType('house')
// returns ['district']
boundariesAvailableForRaceType(2016)
// returns null
Parameter
Name | Type | Optional | Description |
---|---|---|---|
raceType |
string |
|
- Returns
-
array
- An array of the available district types
candidateVotePercentage(candidateVote, totalVotes) → number
Given the absolute number of votes a candidate has received, and the total number of votes in the election, returns the percentage of votes the candidate has received.
Example
getPercentageOfVotes(100, 200)
// returns 50
Parameters
Name | Type | Optional | Description |
---|---|---|---|
candidateVote |
number |
|
The number of votes the candidate has received. |
totalVotes |
number |
|
The total number of votes in the election. |
- Returns
-
number
- The percentage of votes the candidate has received.
getStateAbbrFromStateFips(stateFips) → string
Examples
getStateAbbrFromStateFips('01')
// returns 'AL'
getStateAbbrFromStateFips('36')
// returns 'NY'
getStateAbbrFromStateFips('XX')
// throws an error
Parameter
Name | Type | Optional | Description |
---|---|---|---|
stateFips |
string |
|
The state fips code. |
- Throws
-
Error
- If the state fips code is invalid.
- Returns
-
string
- The state abbreviation
getStateCodeFromCountyFips(countyFips) → string
Get the state code from the county fips string
Examples
getStateCodeFromCountyFips('01001')
// returns '01'
getStateCodeFromCountyFips(01000)
// throws Error
getStateCodeFromCountyFips('01')
// throws Error
Parameter
Name | Type | Optional | Description |
---|---|---|---|
countyFips |
string |
|
The county fips code. |
- Returns
-
string
- The state fips code.
isBoundaryAvailableForRaceType(raceType, boundaryType)
Examples
isBoundaryAvailableForRaceType('president', 'county')
// returns true
isBoundaryAvailableForRaceType('president', 'state')
// returns true
isBoundaryAvailableForRaceType('president', 'district')
// returns false
Parameters
Name | Type | Optional | Description |
---|---|---|---|
raceType |
string |
|
The race type, like 'president', 'house', or 'senate' |
boundaryType |
string |
|
The type of boundary, like 'county', 'state', or 'district' |
partyNameNormalizer(partyNameString) → string
Normalizes a party name string to a standardized format.
Example
const partyName = partyNameNormalizer('R') // returns 'rep'
const partyName = partyNameNormalizer('REP') // returns 'rep'
const partyName = partyNameNormalizer('Republican') // returns 'rep'
const partyName = partyNameNormalizer('republican') // returns 'rep'
Parameter
Name | Type | Optional | Description |
---|---|---|---|
partyNameString |
string |
|
The party name string to be normalized. |
- Returns
-
string
The normalized party name.
sortCandidatesByVotes(candidates, sortFunction) → Array
Given an array of candidate objects, returns a sorted array of candidate objects, sorted by the number of votes they have received with the specified sort function.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
candidates |
Array |
|
An array of candidate objects. |
sortFunction |
function() |
|
The function to use to sort the candidates (like d3.descending) |
- Throws
-
Error
- If the candidates array is invalid.
- Returns
-
Array
- A sorted array of candidate objects.
stateAbbrToFips(stateAbbreviation) → string
Get the state fips code from the abbreviation, like 'NY' to '36'
Example
getStateFipsFromAbbreviation('NY')
// returns '36'
Parameter
Name | Type | Optional | Description |
---|---|---|---|
stateAbbreviation |
string |
|
The state abbreviation. |
- Returns
-
string
- The state fips code.
stateAbbrToName(stateAbbr) → string
Example
getStateNameFromStateAbbr('AL')
// returns 'Alabama'
Parameter
Name | Type | Optional | Description |
---|---|---|---|
stateAbbr |
string |
|
Two letter state abbreviation |
- Throws
-
Error
- If the state abbreviation is invalid.
- Returns
-
string
- The state name
stateFipsToName(stateFips) → string
Example
stateFipsToName('01')
// returns 'Alabama'
Parameter
Name | Type | Optional | Description |
---|---|---|---|
stateFips |
string |
|
- Throws
-
Error
- If the state fips code is invalid.
- Returns
-
string
- The state name
stateNameToFips(stateName) → string
Example
getStateFipsFromStateName('Alabama')
// returns '01'
Parameter
Name | Type | Optional | Description |
---|---|---|---|
stateName |
string |
|
- Throws
-
Error
- If the state name is invalid.
- Returns
-
string
- The state fips code
Abstract types
County Object
An array of county names with their corresponding FIPS codes.
Properties
Name | Type | Optional | Description |
---|---|---|---|
fips_code |
number |
|
The FIPS code of the county. |
name |
string |
|
The name of the county. |
StatePlaneProjections Object
Represents the state planes and bounds for every state.
Properties
Name | Type | Optional | Description |
---|---|---|---|
proj |
string |
|
The projection |
rotate |
Array of number |
|
The rotation of the projection. |
bounds |
Array of number |
|
The bounds of the projection. |
parallels |
Array of number |
|
The parallels of the projection. |
USBounds Object
Represents the bounds of the United States.
Properties
Name | Type | Optional | Description |
---|---|---|---|
type |
string |
|
The type of the feature collection. |
features |
Array of Object |
|
The features of the collection. |