//@code_start jQuery(function(){ /* * Generate the colors shown on the map based upon the json data input */ generateColors = function(jsonData){ var colors = {}, key; for (key in map.regions) { // check state in json if (jsonData.hasOwnProperty(key)) { // This state should be red or blue if (Object.prototype.toString.call(jsonData[key]) == '[object Array]') { colors[key] = jsonData[key][0].Color; // color of first member of array } // end if else { colors[key] = jsonData[key].Color; } // end else } // end outer if else { // this state should be gray colors[key] = "#95a5a6"; } // end else } // end for map.series.regions[0].setValues(colors); }; function getDevicePixelRatio() { if (window.devicePixelRatio === undefined) return 1; // No pixel ratio available. Assume 1:1. return window.devicePixelRatio; } getImageUrl = function(code, name) { var base_url = 'https://www.jobsgrowth.org/wp-content/themes/jobsgrowth/images/'; var ext = ".png"; /*var size = 1 < getDevicePixelRatio() ? "@2x" : "";*/ var size = ""; return base_url + code + '_' + name.replace(" ", "-") + size + ext; } /* * Get HTML for all senators of a state * Assume input is an array of state objects or a state object */ getHtmlLabelMulti = function(code, jsonObject) { var returnHtml = '
'; if (Object.prototype.toString.call(jsonObject) == '[object Array]') { for (var i = 0; i < jsonObject.length; i++) { returnHtml += getHtmlLabelSingle(code, jsonObject[i]); } // end for } // end if else { returnHtml += getHtmlLabelSingle(code, jsonObject); } return returnHtml + '
'; } // end function /* * Returns generated HTML for a state object input. */ getHtmlLabelSingle = function(code, stateObject) { var specElection = stateObject.Special_Election ? "***" : ""; var text1 = 'Senator ' + stateObject.Current_Senator; var text2 = '' + stateObject.Current_Party + ' - ' + stateObject.Name + specElection + ''; return '
' + '
' + text1 + '
' + '
' + text2 + '
'; } // end function getHtmlLabelSingle // initialize the map jQuery.getJSON('https://www.jobsgrowth.org/wp-content/themes/jobsgrowth/data/state_data.json', function(data) { // define map map = new jvm.WorldMap({ map: 'us_aea_en', container: jQuery('#map'), backgroundColor: null, series: { regions: [{ attribute: 'fill' }] }, onRegionLabelShow: function(event, label, code){ if (data.hasOwnProperty(code)) { label.html(getHtmlLabelMulti(code, data[code])); } // end if else { label.html('' + label.html() + ''); } // end else } // end anonymous function }); generateColors(data); // define map colors }) }) //@code_end