This module allows users to view the results of elections other than Republican presidential primaries.
This module lives in lib/map_center/modules/other_votes.js.
Two tabs are available to the user; one allows the user to select a state for which to view results, and the other allows the user to select a specific race in that state.
The sidebar in this module shows the statewide vote breakdown in the race, and the tooltips for each county shows the countywide vote breakdown in the race.
If config.autoRefresh is true, the map will request and display updated results every config.autoRefreshDelay milliseconds. This does not require a full page refresh.
Results in this module are provided by the Associated Press’ AP Election Services.
All configuration options live in the config object toward the top of the module source and may be overridden by defining a global object named nhmc_live_config, which will be merged into config using jQuery.extend.
defaultRaceNames is an empty object that is completely unused. It has no mention anywhere in the module source except in the initial definition of the config object.
Todo
Remove this.
The results data for each state lives in a static JSONP file at http://www.pbs.org/newshour/vote2012/map/live_data/VIEW_NAME_general.json, where VIEW_NAME is the state’s abbreviation as found in nhmc.config.stateToUSPS, lowercased. The file’s callback name is the same abbreviation, but the name there is uppercased; this was done to avoid conflicts with the lowercase abbreviation in for the state of Indiana, which happens to be a reserved word in JavaScript.
Each state’s results object contains the following properties:
candidates is an object with candidate IDs as keys and candidate names as values. This allows the data in areas, breakdown, colors, images and winners to use the more compact candidate IDs instead of candidate names to save space.
Note
All configuration options use candidates’ names, not their IDs. IDs should not be used with any other modules; AP Election Services arbitrarily assigns them to candidates and may use different IDs from state to state for the same candidate.
lastUpdated is an array containing five elements describing the date and time (in the Eastern time zone, including Daylight Saving Time if in effect) when this results file was last updated.
raceNames is an object with race IDs as keys and race names as values. This allows the data in racees to use the more compact race IDs instead of race names to save space.
Note
All configuration options use races’ names, not their IDs. IDs should not be used with any other modules; AP Election Services arbitrarily assigns them to races and may use different IDs from state to state for races for the same (i.e., federal) position.
races is an object with race IDs as keys and race results objects as values. Each race results object has the following properties:
areas is an object with area IDs as keys and objects with area results as values.
Note
For the purposes of this module, an “area ID” is generally a county FIPS code; for non-county areas (such as states), the full name of the area is used instead.
Each area’s results object contains the following properties:
data is an array that contains one two-element array per candidate: The first element is the candidate ID listed in candidates, and the second element is the number of votes that candidate received. The area’s array is sorted by the number of votes received in descending order; that is, the candidate with the most votes in that area is listed first.
precincts is an array containing two elements:
These may be used to calculate the percent of precincts reporting.
Warning
Rounding errors become significant once more than 99 percent of precincts are reporting; module developers should ensure they do not erroneously report 100 percent of precincts reporting before that is actually the case. (This is primarily an issue when rounding to the nearest integer.)
breakdown is an array identical in format to the county data objects in areas but with results for the entire state.
precincts is an array containing two elements:
These may be used to calculate the percent of precincts reporting.
Warning
Rounding errors become significant once more than 99 percent of precincts are reporting; module developers should ensure they do not erroneously report 100 percent of precincts reporting before that is actually the case. (This is primarily an issue when rounding to the nearest integer.)
winners is an object with area IDs as keys. For each area ID, the value is either the candidate ID for the winner projected by AP or null if no such projection has yet occurred.
test is a Boolean value stating whether AP Election Services marked any of the data used to generate this results file as being test data not intended for publication.
Todo
Add some support for specifying the location of race-specific results files to allow for viewing archived results from past races in states that have held other races since then.
This module makes use of one key-value pair in the fragment identifier via nhmc.ctrl.hashParams: