From faff949d1c91f3144222b436412aabff587b4657 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Thu, 8 Oct 2015 13:06:31 -0400 Subject: [PATCH] Restore maps on election pages. * Restore state and district maps on election pages. * Delete some unused code. [Resolves #807] --- static/js/modules/election-lookup.js | 2 +- static/js/modules/maps.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/static/js/modules/election-lookup.js b/static/js/modules/election-lookup.js index 4b59f909b..ad067c5ff 100644 --- a/static/js/modules/election-lookup.js +++ b/static/js/modules/election-lookup.js @@ -1,6 +1,6 @@ 'use strict'; -/* global require, module, window, document */ +/* global window */ var $ = require('jquery'); var URI = require('URIjs'); diff --git a/static/js/modules/maps.js b/static/js/modules/maps.js index 4c5542ecb..7911fe57a 100644 --- a/static/js/modules/maps.js +++ b/static/js/modules/maps.js @@ -1,7 +1,5 @@ 'use strict'; -/* global require, module, window, document */ - var d3 = require('d3'); var $ = require('jquery'); var _ = require('underscore'); @@ -11,18 +9,19 @@ var topojson = require('topojson'); var L = require('leaflet'); require('leaflet-providers'); -var events = require('fec-style/js/events'); - var fips = require('./fips'); var helpers = require('./helpers'); var utils = require('./election-utils'); var states = require('../data/us-states-10m.json'); -var districts = require('../data/districts.json'); -var districtFeatures = topojson.feature(districts, districts.objects.districts); - var stateFeatures = topojson.feature(states, states.objects.states).features; +var stateFeatureMap = _.chain(stateFeatures) + .map(function(feature) { + return [feature.id, feature]; + }) + .object() + .value(); var compactRules = [ ['B', 9], @@ -80,7 +79,7 @@ function stateMap($elm, data, width, height, min, max, addLegend, addTooltips) { max = max || _.max(totals); var scale = chroma.scale(colorScale).domain([min, max]); var quantize = d3.scale.linear().domain([min, max]); - var map = svg.append('g') + svg.append('g') .selectAll('path') .data(stateFeatures) .enter().append('path') @@ -201,7 +200,8 @@ DistrictMap.prototype.load = function(election) { var encoded = utils.encodeDistrict(election.state, election.district); feature = utils.findDistrict(encoded); } else { - feature = fips.fipsByState[parseInt(election.state)]; + var state = fips.fipsByState[election.state].STATE; + feature = stateFeatureMap[state]; } feature && this.render(feature); };