Fantasy Election Generator

Developer
Size
14,205 Kb
Views
44,528

How do I make an fantasy election generator?

This is the stripped down version of a fantasy map maker made by the ZingChart team. Here is the original version: http://elections.zingchart.com/map/. What is a fantasy election generator? How do you make a fantasy election generator? This script and codes were developed by ZingChart on 28 July 2022, Thursday.

Fantasy Election Generator Previews

Fantasy Election Generator - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Fantasy Election Generator</title> <script>
zingchart.MODULESDIR = '/scripts/zingchart/modules/';
zingchart.loadModules("maps,maps-usa,patterns");
ZC.LICENSE = ['569d52cefae586f634c54f86dc99e6a9','ee6b7db5b51705a13dc2339db3edaf6d'];
</script> <link rel="stylesheet" href="css/style.css">
</head>
<body> <header id="hero"> <div class="title"> <h1>FANTASY ELECTION GENERATOR</h1> </div> <h2>brought to you by ZingChart</h2> </div>
</header>
<section id="main"> <div id="title"> <h2 id="title-display">Presidential Election 2016</h2> </div> <input type="text" id="title-edit" class="hidden" value="Presidential Election 2016"> <section id="map-container"> <!--Candidate results--> <div id="electoral"> <div class="toggle"> <input type="radio" name="candidate-mode" value="fun" id="fun-mode" checked> <label class="toggle-switch" for="fun-mode" data-state="fun">Fun</label> <input type="radio" name="candidate-mode" value="serious" id="serious-mode"> <label class="toggle-switch" for="serious-mode" data-state="serious">Serious</label> </div> <h3>Electoral Results</h3> <div id="result-chart"></div> <div id="result-chart-flex-container"></div> <div id="result-chart-info"> <div class="flex center"><i class="fa fa-chevron-up"></i></div> <div>270 needed to win |<span style="color: #656565" id="result-claimed">20</span> left to claim</div> </div> <section id="result-container"></section> <section class="flex column"> <!-- <div style="margin-left: 0%">	<div class="switch"> <input id="fun-switch" type="checkbox" class="switch-input"> <label for="fun-switch" class="switch-label"></label> </div> </div> --> <div class="flex row"> <div id="random-button" class="button fun" onclick="randomizeCandidates()">Randomize Candidates!</div> <div id="trump-button" class="button fun" onclick="randomizeTrump()">Trump Vs. ?</div> </div> </section> </div> <!--End Candidate results--> </section>
</section>
<section id="controls"> <div> <h3>Use Preset Result Data</h3> <h6>*Uses current state electoral vote count</h6> </div> <select name="preset" onchange="setResults(event)">	<option value="2012">2012 Election Results</option>	<option value="2008">2008 Election Results</option>	<option value="2004">2004 Election Results</option>	<option value="2000">2000 Election Results</option>	<option value="republican">All Republican</option>	<option value="democratic">All Democratic</option>	<option value="none">All Undecided</option>	</select> <!-- <h3> Randomize Candidates </h3>	<div class="button amber" onclick="randomizeCandidates()">Randomize!</div> --> </div>
</section>
<input type="hidden" id="init-title" value='Presidential Election 2016'>
<input type="hidden" id="init-results" value='{"AL":"republican","AK":"republican","AZ":"democratic","AR":"republican","CA":"republican","CO":"democratic","CT":"democratic","DC":"republican","DE":"republican","FL":"democratic","GA":"democratic","HI":"republican","ID":"republican","IL":"democratic","IN":"republican","IA":"democratic","KS":"democratic","KY":"democratic","LA":"republican","ME":"democratic","MD":"democratic","MA":"republican","MI":"republican","MN":"democratic","MS":"democratic","MO":"democratic","MT":"democratic","NE":"democratic","NV":"democratic","NH":"democratic","NJ":"democratic","NM":"democratic","NY":"democratic","NC":"republican","ND":"republican","OH":"republican","OK":"republican","OR":"republican","PA":"democratic","RI":"democratic","SC":"republican","SD":"republican","TN":"democratic","TX":"republican","UT":"republican","VT":"republican","VA":"republican","WA":"republican","WV":"democratic","WI":"republican","WY":"democratic"}'>
<input type="hidden" id="init-candidates" value='{"democratic":{"name":"McLovin","party":"democratic","displayParty":"democratic","image":"http://i.giphy.com/lZVtxgbiyON8Y.gif","color":"#00AEF3","votes":0},"republican":{"name":"Drake","party":"republican","displayParty":"republican","image":"http://i.giphy.com/FUgmWRgVOLDdS.gif","color":"#DC1A21","votes":0}}'> <script src='https://cdn.zingchart.com/zingchart.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Fantasy Election Generator - Script Codes CSS Codes

@import url(https://fonts.googleapis.com/css?family=Titillium+Web:400,600italic,700,400italic|Montserrat:400,700|Open+Sans:400,300,700,600);
* { box-sizing: border-box;
}
h1,
h2,
h3,
h4,
h5,
h6 { margin: 0; font-family: "Montserrat";
}
h5,
h6 { font-weight: normal;
}
body { font-family: 'Open Sans'; background-color: #FFF; color: #222; margin: 0;
}
input[type="text"],
input[type="file"],
select { margin: 0 0 1em; border: 1px solid #ccc; outline: none; padding: 0.5em; border-radius: 5px; -webkit-transition: background-color 1s; transition: background-color 1s;
}
select { height: 50px; font-size: 1rem; width: 100%;
}
/**************************
*	Generic
**************************/
.hidden { display: none !important;
}
/* Positioning */
.flex { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex;
}
/**************************
*	UI Components
**************************/
/* Button */
.button { padding: 0.5em 1em; margin: 0.5em; cursor: pointer; box-shadow: 3px 3px 2px rgba(0, 0, 0, 0.15); border-radius: 5px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; text-align: center;
}
.large.button { font-size: 1.4rem;
}
.button.gradient { color: white; background: #FFB75E; /* fallback for old browsers */ background: -webkit-linear-gradient(to left, #FFB75E, #ED8F03); /* Chrome 10-25, Safari 5.1-6 */ background: -webkit-linear-gradient(right, #FFB75E, #ED8F03); background: linear-gradient(to left, #FFB75E, #ED8F03); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
.button.gradient:hover { background-color: #fff; /*transition: background-color 1s;*/
}
.button.serious { background-color: #22a4e4; color: white;
}
.button.fun { background: -webkit-linear-gradient(right, #ff4b1f, #ff9068); background: linear-gradient(to left, #ff4b1f, #ff9068); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ color: white;
}
.button.fun:hover { background-color: #ff4b1f;
}
.button.amber { background-color: #FFC107; color: white;
}
.button.amber:hover { background-color: #dea704;
}
.button.green { background-color: #4CAF50; color: white;
}
.button.green:hover { background-color: #388E3C;
}
.button.red { background-color: #F44336; color: white;
}
.button.red:hover { background-color: #D32F2F;
}
/* Switch */
.switch { position: relative; display: inline-block;
}
.switch-input { display: none;
}
.switch-label { display: block; width: 50px; height: 29px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}
.switch-label:before,
.switch-label:after { content: ''; font-size: 0.8rem; color: #444; display: block; position: absolute; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}
.switch-label:before { width: 110px; height: 100%; padding: 2px; background: -webkit-linear-gradient(right, #ff4b1f, #ff9068); background: linear-gradient(to left, #ff4b1f, #ff9068); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ border-radius: 50px;
}
.switch-label:after { top: 0; left: 0; width: 55px; height: 25px; border-radius: 50px; line-height: 1.5rem; padding: 4px; text-align: center; content: 'Fun'; background-color: #fff; box-shadow: 0 0 2px rgba(0, 0, 0, 0.45); -webkit-transition: left 0.25s ease; transition: left 0.25s ease;
}
.switch-input:checked + .switch-label { /* Switch Rail */ /* Switch Knob */
}
.switch-input:checked + .switch-label:before { /*background-color: #89c12d;*/ background: #dedede; background: #22a4e4;
}
.switch-input:checked + .switch-label:after { content: 'Serious'; left: 55px;
}
/* Toggle */
.toggle { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; width: 100%; margin: 1rem 0; box-shadow: 4px 4px 4px 0px rgba(70, 71, 71, 0.08)
}
.toggle input[type=radio] { display: none;
}
.toggle label { cursor: pointer; border: 1px solid #222; padding: 0.5rem; background-color: #F0F0F0; border: 1px solid #D9D9D9; font-weight: bold; width: 50%; text-align: center; color: #A9A9A9;
}
.toggle label:first-of-type { border-right: 0px; border-top-left-radius: 4px; border-bottom-left-radius: 4px;
}
.toggle label:last-of-type { border-top-right-radius: 4px; border-bottom-right-radius: 4px;
}
.toggle input[type="radio"]:checked+label[for="fun-mode"] { background-color: #fff; color: #ff4b1f;
}
.toggle input[type="radio"]:checked+label[for="serious-mode"] { background-color: #fff; color: #22a4e4;
}
/**************************
*	Hero
**************************/
#hero { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; font-size: 1.8rem; background-color: #002868; color: #FFF; text-align: center; word-break: normal; word-wrap: break-word;
}
#hero .title { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; width: 100%; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; margin-top: 1rem; margin-bottom: 1rem; text-align: center; word-break: normal; word-wrap: break-word;
}
#hero h2 { font-size: 1rem; font-weight: 400; margin-bottom: 1rem; word-break: normal; word-wrap: break-word;
}
/**************************
*	Main
**************************/
#main { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; padding: 2rem; border-bottom: 1px solid #BBB;
}
#title { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; font-size: 2rem; margin-bottom: 1rem; text-align: center; word-break: normal; word-wrap: break-word;
}
#title-edit { font-size: 3rem; font-weight: 600; width: 100%; text-align: center; font-family: "Montserrat"; word-break: break-word; padding: 1rem;
}
#map-container { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; flex-wrap: wrap;
}
.zingchart-touch-layer { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}
#election-map-flex-container { width: 100%; height: 500px; max-width: 850px;
}
/* Map custom tooltip */
.map-tooltip { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; position: absolute; width: 170px; height: 180px; z-index: 1000; font-family: 'Montserrat'; background-color: white; border: 1px solid #eee; border-radius: 5px; padding: 5px; box-shadow: 10px 10px 46px -13px rgba(31, 31, 31, 1);
}
#tooltip-subtitle { font-size: 0.8rem;
}
#tooltip-historical,
#tooltip-chart-data { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; font-size: 0.8rem;
}
#electoral { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; font-size: 1rem; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; border: 1px solid #EEE; padding: 0 1rem 1rem;
}
#result-chart { position: absolute; margin-top: 0.5rem;
}
#result-chart-flex-container { width: 100%; height: 15px;
}
#result-chart-info { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; margin-top: 10px;
}
#result-container { -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; flex-wrap: wrap; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex;
}
#electoral .result { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; margin-top: 20px; border: 1px solid #fff; padding: 0.5rem; border-radius: 5px; min-width: 400px;
}
.profile-pic { min-width: 100px; max-width: 100px; min-height: 100px; max-height: 100px; border-radius: 150px; background-position: center center; background-size: cover; background-repeat: no-repeat;
}
.edit-candidate { color: #222; cursor: pointer; font-size: 1.2rem;
}
.fa-pencil-square-o:hover { color: #FAC82F;
}
.candidate { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; padding: 0.5rem; width: 100%; max-width: 300px; font-family: 'Montserrat';
}
.candidate .name { font-size: 1.5rem; word-wrap: break-word;
}
.candidate .score { font-size: 2.5rem;
}
.candidate .description,
.candidate .party { font-size: 0.8rem;
}
/**************************
*	Controls
**************************/
#controls { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-justify-content: space-around; -ms-flex-pack: distribute; justify-content: space-around; padding: 1rem;
}
#controls .cell { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; margin: 0.5rem; border: 1px solid #EEE; background-color: #FFF; padding: 0.5rem; -webkit-box-flex: 1; -webkit-flex-grow: 1; -ms-flex-positive: 1; flex-grow: 1; min-width: 400px;
}
.cell li { margin: 0.5rem; font-weight: 300;
}
.cell h3 { margin: 0.5rem 0; text-algin: center;
}
/**************************
*	Media Queries
**************************/
@media (min-width: 426px) { #election-map-flex-container { min-height: 400px; max-height: 400px; } .chart.small, .chart.normal { display: initial; } #result-container { -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; }
}
@media (min-width: 768px) { .chart.small, .chart.normal { display: initial; } #result-container { -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; }
}
@media (min-width: 1024px) { .chart.small, .chart.normal { display: initial; } #result-container { -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; }
}
@media (min-width: 1200px) { #map-container { -webkit-flex-wrap: nowrap; -ms-flex-wrap: nowrap; flex-wrap: nowrap; } #electoral { max-width: 500px; } #election-map-flex-container { min-height: 500px; max-height: 500px; } #result-container { -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: inherit; -webkit-justify-content: inherit; -ms-flex-pack: inherit; justify-content: inherit; } .chart.small, .chart.normal, .chart.wide { display: initial; }
}
@media (max-width: 425px) { #hero h1 { font-size: 3rem; } #controls { padding: 0.5rem; } #electoral .result, .cell, #controls .cell { min-width: inherit; } #modal-form { max-width: 300px; } .candidate .name { font-size: 1.5rem; } #main { padding: 0.5rem; } #title { font-size: 1.7rem; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; } #election-map-flex-container { min-height: 225px; max-height: 200px; } #result-container { -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; } #result-chart-flex-container { max-width: 250px; } .chart.small { display: initial; }
}

Fantasy Election Generator - Script Codes JS Codes

var historicalResults = { "2000": { "AL": "republican", "AK": "republican", "AZ": "republican", "AR": "republican", "CA": "democratic", "CO": "republican", "CT": "democratic", "DC": "democratic", "DE": "democratic", "FL": "republican", "GA": "republican", "HI": "democratic", "ID": "republican", "IL": "democratic", "IN": "republican", "IA": "democratic", "KS": "republican", "KY": "republican", "LA": "republican", "ME": "democratic", "MD": "democratic", "MA": "democratic", "MI": "democratic", "MN": "democratic", "MS": "republican", "MO": "republican", "MT": "republican", "NE": "republican", "NV": "republican", "NH": "republican", "NJ": "democratic", "NM": "democratic", "NY": "democratic", "NC": "republican", "ND": "republican", "OH": "republican", "OK": "republican", "OR": "democratic", "PA": "democratic", "RI": "democratic", "SC": "republican", "SD": "republican", "TN": "republican", "TX": "republican", "UT": "republican", "VT": "democratic", "VA": "republican", "WA": "democratic", "WV": "republican", "WI": "democratic", "WY": "republican" }, "2004": { "AL": "republican", "AK": "republican", "AZ": "republican", "AR": "republican", "CA": "democratic", "CO": "republican", "CT": "democratic", "DC": "democratic", "DE": "democratic", "FL": "republican", "GA": "republican", "HI": "democratic", "ID": "republican", "IL": "democratic", "IN": "republican", "IA": "republican", "KS": "republican", "KY": "republican", "LA": "republican", "ME": "democratic", "MD": "democratic", "MA": "democratic", "MI": "democratic", "MN": "democratic", "MS": "republican", "MO": "republican", "MT": "republican", "NE": "republican", "NV": "republican", "NH": "democratic", "NJ": "democratic", "NM": "republican", "NY": "democratic", "NC": "republican", "ND": "republican", "OH": "republican", "OK": "republican", "OR": "democratic", "PA": "democratic", "RI": "democratic", "SC": "republican", "SD": "republican", "TN": "republican", "TX": "republican", "UT": "republican", "VT": "democratic", "VA": "republican", "WA": "democratic", "WV": "republican", "WI": "democratic", "WY": "republican" }, "2008": { "AL": "republican", "AK": "republican", "AZ": "republican", "AR": "republican", "CA": "democratic", "CO": "democratic", "CT": "democratic", "DC": "democratic", "DE": "democratic", "FL": "democratic", "GA": "republican", "HI": "democratic", "ID": "republican", "IL": "democratic", "IN": "democratic", "IA": "democratic", "KS": "republican", "KY": "republican", "LA": "republican", "ME": "democratic", "MD": "democratic", "MA": "democratic", "MI": "democratic", "MN": "democratic", "MS": "republican", "MO": "republican", "MT": "republican", "NE": "republican", "NV": "democratic", "NH": "democratic", "NJ": "democratic", "NM": "democratic", "NY": "democratic", "NC": "democratic", "ND": "republican", "OH": "democratic", "OK": "republican", "OR": "democratic", "PA": "democratic", "RI": "democratic", "SC": "republican", "SD": "republican", "TN": "republican", "TX": "republican", "UT": "republican", "VT": "democratic", "VA": "democratic", "WA": "democratic", "WV": "republican", "WI": "democratic", "WY": "republican" }, "2012": { "AL": "republican", "AK": "republican", "AZ": "republican", "AR": "republican", "CA": "democratic", "CO": "democratic", "CT": "democratic", "DC": "democratic", "DE": "democratic", "FL": "democratic", "GA": "republican", "HI": "democratic", "ID": "republican", "IL": "democratic", "IN": "republican", "IA": "democratic", "KS": "republican", "KY": "republican", "LA": "republican", "ME": "democratic", "MD": "democratic", "MA": "democratic", "MI": "democratic", "MN": "democratic", "MS": "republican", "MO": "republican", "MT": "republican", "NE": "republican", "NV": "democratic", "NH": "democratic", "NJ": "democratic", "NM": "democratic", "NY": "democratic", "NC": "republican", "ND": "republican", "OH": "democratic", "OK": "republican", "OR": "democratic", "PA": "democratic", "RI": "democratic", "SC": "republican", "SD": "republican", "TN": "republican", "TX": "republican", "UT": "republican", "VT": "democratic", "VA": "democratic", "WA": "democratic", "WV": "republican", "WI": "democratic", "WY": "republican" }
};
var democraticPool = [{ name: 'Hillary Clinton', image: 'http://i.giphy.com/xT9DPlQR6ZTZFj3exi.gif', party: 'democratic' }, { name: 'Bernie Sanders', image: 'http://i.giphy.com/xT0BKrys7790Hl1zJC.gif', party: 'democratic' },
];
var republicanPool = [{ name: 'John Kasich', image: 'http://i.giphy.com/qxqXS7PhBWgWk.gif', party: 'republican'
}, { name: 'Ted Cruz', image: 'http://i.giphy.com/y3MyxNIp9KDkc.gif', party: 'republican'
}, { name: 'Donald Trump', image: 'http://i.giphy.com/xTiTnHXbRoaZ1B1Mo8.gif', party: 'republican'
}]
var candidatePool = [{ name: 'Dwayne Johnson', image: 'http://i.giphy.com/11ezOCtJ7Eetri.gif' }, { name: 'Seth Rogen', image: 'http://i.giphy.com/xT9DPwMQoRugrODugw.gif' }, { name: 'Arnold Schwarzenegger', image: 'http://i.giphy.com/YoB1eEFB6FZ1m.gif' }, { name: 'Sylvester Stallone', image: 'http://i.giphy.com/IowDquXX7skw0.gif' }, { name: 'Jean-Claude Van Damme', image: 'http://i.giphy.com/N6S2qlrMhLuQo.gif' }, { name: 'Steven Seagal', image: 'http://i.giphy.com/N6S2qlrMhLuQo.gif' }, { name: 'Jackie Chan', image: 'http://i.giphy.com/bXbLIVWu9lmHm.gif' }, { name: 'Bruce Lee', image: 'http://i.giphy.com/UseBZDm3O00hy.gif' }, { name: 'Superman', image: 'http://i.giphy.com/R8MIGe47XWx68.gif' }, { name: 'Batman', image: 'http://i.giphy.com/a5viI92PAF89q.gif' }, { name: 'Admiral Ackbar', image: 'http://i.imgur.com/LaJ9Kmo.gif' }, { name: 'Chewbacca', image: 'http://i.giphy.com/5tRGwBkWx8Vt6.gif' }, { name: 'Samuel Jackson', image: 'http://i.giphy.com/JnkucpCZMvr8Y.gif' }, { name: 'Gandalf', image: 'http://i.giphy.com/WLIerIoiUJL1K.gif' }, { name: 'Paris Hilton', image: 'http://i.giphy.com/jDjfjjEU2fUNq.gif' }, { name: 'Kim Kardashian', image: 'http://i.giphy.com/R5EMZ8EhpgCuQ.gif' }, { name: 'Kanye West', image: 'http://i.giphy.com/9x7gvqaWEG7qE.gif' }, { name: 'Captain Kirk', image: 'http://i.giphy.com/yBT2Tsff1Rsdy.gif' }, { name: 'John Cena', image: 'http://i.giphy.com/ccRdPf8zWkivm.gif' }, { name: 'Spock', image: 'http://i.giphy.com/qLDWCx8VLJShy.gif' }, { name: 'Drake', image: 'http://i.giphy.com/FUgmWRgVOLDdS.gif' }, { name: 'Manny Pacquiao', image: 'http://i.giphy.com/mlyP6oNG1Eaxa.gif ' }, { name: 'President Skroob', image: 'http://i.giphy.com/VWsVhATeaceze.gif' }, { name: 'Drake', image: 'http://i.giphy.com/Wy32VYRbuzLDG.gif' }, { name: 'Drake', image: 'http://i.giphy.com/pJnecs5VloVuE.gif' }, { name: 'Steph Curry', image: 'http://i.giphy.com/qRGHFIf65QpVu.gif' }, { name: 'Morty', image: 'http://i.giphy.com/YTu9T2FIiGlWg.gif' }, { name: 'Rick Sanchez', image: 'http://i.giphy.com/S0PHmmqZzUBO0.gif' }, { name: 'Lil B the BasedGod', image: 'http://i.giphy.com/10LH9EHpOGe796.gif' }, { name: 'Erlich Bachman', image: 'http://i.giphy.com/ERl9DiRyWQWWc.gif' }, { name: 'Yoda', image: 'http://i.giphy.com/UsmcxQeK7BRBK.gif' }, { name: 'Krieger', image: 'http://i.giphy.com/d2H7o2DQhDQFG.gif' }, { name: 'Archer', image: 'http://i.giphy.com/VaWZIxqTkzKsU.gif' }, { name: 'President Camacho', image: 'http://i.giphy.com/vDZACy278sqT6.gif' }, { name: 'Putin', image: 'http://i.giphy.com/Pr8tx4ZWLjthm.gif' }, { name: 'Adele', image: 'http://i.giphy.com/imWi1uq6yhUs0.gif' }, { name: 'Nyan Cat', image: 'http://i.giphy.com/sIIhZliB2McAo.gif' }, { name: 'Hodor', image: 'http://i.giphy.com/oxjiz4EH7tMcM.gif' }, { name: 'Oprah', image: 'http://i.giphy.com/4dJ2ekKoBZq6Y.gif' }, { name: 'Luigi', image: 'http://i.giphy.com/LLfmQjxmhnuhi.gif' }, { name: 'Vanilla Ice', image: 'http://i.giphy.com/WkLQDjfJ34HYs.gif' }, { name: 'Grumpy Cat', image: 'http://i.giphy.com/m7BTtLWhjkEJa.gif' }, { name: 'Miley Cyrus', image: 'http://i.giphy.com/hdal9LnSyVXy.gif' }, { name: 'Ellen', image: 'http://i.giphy.com/wxw2e19ZMsjio.gif' }, { name: 'Val "Ice" Kilmer', image: 'http://i.giphy.com/TANlLoZuVJBrW.gif' }, { name: 'Kobra Kai Sensei', image: 'http://i.giphy.com/HdhmYaheh46Lm.gif' }, { name: 'Patrick Swayze', image: 'http://i.giphy.com/69OUouHRzrvcA.gif' }, { name: 'Chuck Norris', image: 'http://i.giphy.com/BIuuwHRNKs15C.gif' }, { name: 'Anthony Michael Hall', image: 'http://i.giphy.com/u5AWcpzNtNVIc.gif' }, { name: 'Beyonce', image: 'http://i.giphy.com/bGOivNrYMeEBq.gif' }, { name: 'Neil Degrasse Tyson', image: 'http://i.giphy.com/cwTtbmUwzPqx2.gif' }, { name: 'Nicolas Cage', image: 'http://i.giphy.com/bn0zlGb4LOyo8.gif' }, { name: 'Jon Snow', image: 'http://i.giphy.com/ZoUWHFPafXkn6.gif' }, { name: 'Tyrion', image: 'http://i.giphy.com/ln4w59b6ZgyM8.gif' }, { name: 'J Lo', image: 'http://i.giphy.com/DlDc6NYZvVcw8.gif' }, { name: 'Sheldon', image: 'http://i.giphy.com/mZ6PCHZAsLBEQ.gif' }, { name: 'Aziz Ansari', image: 'http://i.giphy.com/YxffWg4x40kY8.gif' }, { name: 'Cookie', image: 'http://i.giphy.com/hube3iIKws6mQ.gif' }, { name: 'Ron Swanson', image: 'http://i.giphy.com/d7qFTitBNU9kk.gif' }, { name: 'Hulk Hogan', image: 'http://i.giphy.com/uKwa2KiBA0rTy.gif' }, { name: 'Prince', image: 'http://i.giphy.com/CE5LPDMZP73l6.gif' }, { name: 'Tom Hardy', image: 'http://i.giphy.com/XJsjcTpov98mA.gif' }, { name: 'Homer Simpson', image: 'http://i.giphy.com/AVilYmB74xhK.gif' }, { name: 'Bill Murray', image: 'http://i.giphy.com/uYuNfAcaAP06A.gif' }, { name: 'Will Ferrell', image: 'http://i.giphy.com/4C2E88l5CDb0c.gif' }, { name: 'Joe Dirt', image: 'http://i.giphy.com/kOZ5BWKm2tMGs.gif' }, { name: 'Macgruber', image: 'http://i.giphy.com/9umH7yTO8gLYY.gif' }, { name: 'Andy Samberg', image: 'http://i.giphy.com/ci0uDcGQtBh0k.gif' }, { name: 'Charlie Sheen', image: 'http://i.giphy.com/I2eY0B55h0c2A.gif' }, { name: 'Harrison Ford', image: 'http://i.giphy.com/nu5912LGf4LAY.gif' }, { name: 'Kristen Wiig', image: 'http://i.giphy.com/GY2bPXOJCfMVG.gif' }, { name: 'Melissa McCarthy', image: 'http://i.giphy.com/b0Z3ghFcuglBm.gif' }, { name: 'Will Arnett', image: 'http://i.giphy.com/13ZES41BKtMhmo.gif' }, { name: 'McLovin', image: 'http://i.giphy.com/lZVtxgbiyON8Y.gif' }, { name: "Ron Burgundy", image: 'http://i.giphy.com/qFLDOjXRIQXq8.gif' }, { name: 'Captain Picard', image: 'http://i.giphy.com/VLoN2iW8ii3wA.gif' }, { name: 'Obi Wan Kenobi', image: 'http://i.giphy.com/lv5wzrDUdqHxm.gif' }, { name: 'Darth Maul', image: 'http://i.giphy.com/X50f9uthkjN60.gif' }, { name: 'Leonardo i Caprio', image: 'http://i.giphy.com/cyNYYuprfgL84.gif' }, { name: 'Vince Vaughn', image: 'http://i.giphy.com/310MSrfPTUuFa.gif' }, { name: 'Matthew McConaughey', image: 'http://i.giphy.com/z4TryrC69xQCQ.gif' }, { name: 'Iron Man', image: 'http://i.giphy.com/J3W2yi2DgEPV6.gif' }, { name: 'Captain America', image: 'http://i.giphy.com/3LC4FUs3ZmT5K.gif' }, { name: 'Tony Stark', image: 'http://i.giphy.com/e2suIZDKWmhX2.gif' }, { name: 'Taylor Swift', image: 'http://i.giphy.com/MLFnfisFXQS52.gif' }, { name: 'Nicki Minaj', image: 'http://i.giphy.com/xT0BKFqxREAHwgJSMM.gif' }, { name: 'Cher', image: 'http://i.giphy.com/iv4XVmikvZTS8.gif' }, { name: 'Amy Schumer', image: 'http://i.giphy.com/l2JJxNJJoMm4cvunK.gif' }, { name: 'Michelle Obama', image: 'http://i.giphy.com/CgqLPXCa9djMI.gif' }, { name: 'Megyn Kelly', image: 'http://i.giphy.com/GznBSypJ0Fcac.gif' }, { name: 'Rachel Maddow', image: 'http://i.giphy.com/JniCmXsLCA9Fe.gif' }, { name: 'Tina Fey', image: 'http://i.giphy.com/rGcMg4dORyFl6.gif' }, { name: 'Amy Poehler', image: 'http://i.giphy.com/14joII5lDkkVUc.gif' }, { name: 'Carly Fiorina', image: 'http://i.giphy.com/3o85xHMys3mQ7PWFAA.gif' }, { name: 'OJ', image: 'http://i.giphy.com/5aiHdkYD7S0O4.gif' }, { name: 'Howard Stern', image: 'http://i.giphy.com/OP3iHFgWqvRdu.gif' }, { name: 'Mel Gibson', image: 'http://i.giphy.com/xT9DPlAUKTl1GeZjC8.gif' }, { name: 'George Clooney', image: 'http://i.giphy.com/3rgXBHqyE7umstZkIw.gif' }, { name: 'Matt Damon', image: 'http://i.giphy.com/oJtvZaeT2Wg3m.gif' }, { name: 'Ben Affleck', image: 'http://i.giphy.com/2g7dWlLwENbUc.gif' }, { name: 'Tom Brady', image: 'http://i.giphy.com/oftF1ohC3E8XC.gif' }, { name: 'Gisele Bündchen', image: 'http://i.giphy.com/eyNKN0ZUWyiNa.gif' }, { name: 'Derek Zoolander', image: 'http://i.giphy.com/3XSWffoziHWtG.gif' }, { name: 'Hanzel', image: 'http://i.giphy.com/f45L0r0jdzfNe.gif' }, { name: 'Mugatu', image: 'http://i.giphy.com/7GsdDdLUM1MVW.gif' }, { name: 'James Bond', image: 'http://i.giphy.com/143OOSsuEtK5NK.gif' }, { name: 'David Hasselhoff', image: 'http://i.giphy.com/UuDxS2EBRZSyA.gif' }, { name: 'Bono', image: 'http://i.giphy.com/5lNqKeqbOIkEw.gif' }, { name: 'Michael Jackson ', image: 'http://i.giphy.com/ftXvsSyRzKXXG.gif' }, { name: 'Ronald Mcdonald', image: 'http://i.giphy.com/973871nsZPIdO.gif' }, { name: 'Colonel Sanders', image: 'http://i.giphy.com/mzJWGztscMMw0.gif' }, { name: 'Elvis', image: 'http://i.giphy.com/e5MrrMs5oBto4.gif' }, { name: 'Marilyn Monroe', image: 'http://i.giphy.com/ENRPvZQm4Bs2Y.gif' }, { name: 'Cameron Diaz', image: 'http://i.giphy.com/ZR7WOAqLvbZQY.gif' }, { name: 'Martha Stewart', image: 'http://i.giphy.com/wt7w6iAqn1HtC.gif' }, { name: 'Will Smith', image: 'http://i.giphy.com/n8eU11XoQkuI0.gif' }, { name: 'Katy Perry', image: 'http://i.giphy.com/11Je0AsIHE2TW8.gif' }, { name: 'Queen Elizabeth 2nd', image: 'http://i.giphy.com/2k4CSOMmoFZYc.gif' }, { name: 'Demi Moore', image: 'http://i.giphy.com/DbT5sGnI6B0iI.gif' }, { name: 'Wonder Woman', image: 'http://i.giphy.com/iMOk3wfmE5IoE.gif' }, { name: 'Lady GaGa', image: 'http://i.giphy.com/l4Ki8t1sqbYPlPT1e.gif' }, { name: 'Ryan Reynolds', image: 'http://i.giphy.com/YTfbEV1O8seaY.gif' }, { name: 'Deadpool', image: 'http://i.giphy.com/zxf6g67Kq8zgQ.gif' }, { name: 'Prince William', image: 'http://i.giphy.com/BpBX598BoXhhm.gif' }, { name: 'Prince Harry', image: 'http://i.giphy.com/q8DaNJYkYS4Ra.gif' }, { name: 'Voldemort', image: 'http://i.giphy.com/wLBS2GlPDALS0.gif' }, { name: 'Dumbledore', image: 'http://i.giphy.com/720g7C1jz13wI.gif' }, { name: 'Wilma Flintstone', image: 'http://i.giphy.com/AfxqY3LasHABi.gif' }, { name: 'Betty Rubble', image: 'http://i.giphy.com/sXwd11YAFVuA8.gif' }, { name: 'Katniss', image: 'http://i.giphy.com/nFhgN2Oq4s79m.gif' }, { name: 'Tris', image: 'http://i.giphy.com/ErUOnDvCQZ9oQ.gif' }, { name: 'Rocky', image: 'http://i.giphy.com/1iTH1WIUjM0VATSw.gif' }, { name: 'Jan Brady', image: 'http://i.giphy.com/I1ngrVC1tUZO.gif' }, { name: 'ASAP Rocky', image: 'http://i.giphy.com/G6ChMEr9ULLLW.gif' }
];
var Election = { candidates: { democratic: null, republican: null }, states: { "AZ": { "name": "Arizona", "votes": 11, "win": { "NONE": 11, "democratic": 8, "republican": 18 }, "winRate": { "democratic": "0.31", "republican": "0.69" } }, "AL": { "name": "Alabama", "votes": 9, "win": { "republican": 14, "democratic": 21, "independent": 2 }, "winRate": { "republican": "0.38", "democratic": "0.57", "independent": "0.05" } }, "AK": { "name": "Alaska", "votes": 3, "win": { "NONE": 23, "republican": 13, "democratic": 1 }, "winRate": { "republican": "0.93", "democratic": "0.07" } }, "AR": { "name": "Arkansas", "votes": 6, "win": { "republican": 10, "democratic": 26, "independent": 1 }, "winRate": { "republican": "0.27", "democratic": "0.70", "independent": "0.03" } }, "CA": { "name": "California", "votes": 55, "win": { "republican": 22, "democratic": 15 }, "winRate": { "republican": "0.59", "democratic": "0.41" } }, "CO": { "name": "Colorado", "votes": 9, "win": { "NONE": 2, "republican": 22, "independent": 1, "democratic": 12 }, "winRate": { "republican": "0.63", "independent": "0.03", "democratic": "0.34" } }, "CT": { "name": "Connecticut", "votes": 7, "win": { "republican": 20, "democratic": 17 }, "winRate": { "republican": "0.54", "democratic": "0.46" } }, "DC": { "name": "Washington D.C.", "votes": 3, "win": { "republican": 1, "democratic": 13 }, "winRate": { "republican": "0.071", "democratic": "0.93" } }, "DE": { "name": "Delaware", "votes": 3, "win": { "democratic": 19, "republican": 18 }, "winRate": { "democratic": "0.51", "republican": "0.49" } }, "FL": { "name": "Florida", "votes": 29, "win": { "republican": 15, "democratic": 22 }, "winRate": { "republican": "0.41", "democratic": "0.59" } }, "GA": { "name": "Georgia", "votes": 16, "win": { "democratic": 27, "republican": 9, "independent": 1 }, "winRate": { "democratic": "0.73", "republican": "0.24", "independent": "0.03" } }, "HI": { "name": "Hawaii", "votes": 4, "win": { "NONE": 23, "democratic": 12, "republican": 2 }, "winRate": { "democratic": "0.86", "republican": "0.14" } }, "ID": { "name": "Idaho", "votes": 4, "win": { "NONE": 6, "independent": 1, "democratic": 10, "republican": 20 }, "winRate": { "independent": "0.03", "democratic": "0.32", "republican": "0.65" } }, "IL": { "name": "Illinois", "votes": 20, "win": { "republican": 22, "democratic": 15 }, "winRate": { "republican": "0.59", "democratic": "0.41" } }, "IN": { "name": "Indiana", "votes": 11, "win": { "republican": 29, "democratic": 8 }, "winRate": { "republican": "0.78", "democratic": "0.22" } }, "IA": { "name": "Iowa", "votes": 6, "win": { "republican": 26, "democratic": 11 }, "winRate": { "republican": "0.70", "democratic": "0.30" } }, "KS": { "name": "Kansas", "votes": 6, "win": { "republican": 30, "independent": 1, "democratic": 6 }, "winRate": { "republican": "0.81", "independent": "0.03", "democratic": "0.16" } }, "KY": { "name": "Kentucky", "votes": 8, "win": { "democratic": 23, "republican": 14 }, "winRate": { "democratic": "0.62", "republican": "0.38" } }, "LA": { "name": "Louisiana", "votes": 8, "win": { "democratic": 23, "republican": 13, "independent": 1 }, "winRate": { "democratic": "0.62", "republican": "0.35", "independent": "0.03" } }, "ME": { "name": "Maine", "votes": 4, "win": { "republican": 28, "democratic": 9 }, "winRate": { "republican": "0.76", "democratic": "0.24" } }, "MD": { "name": "Maryland", "votes": 10, "win": { "democratic": 26, "republican": 11 }, "winRate": { "democratic": "0.70", "republican": "0.30" } }, "MA": { "name": "Massachusetts", "votes": 11, "win": { "republican": 18, "democratic": 19 }, "winRate": { "republican": "0.49", "democratic": "0.51" } }, "MI": { "name": "Michigan", "votes": 16, "win": { "republican": 25, "democratic": 12 }, "winRate": { "republican": "0.68", "democratic": "0.32" } }, "MN": { "name": "Minnesota", "votes": 10, "win": { "republican": 19, "democratic": 18 }, "winRate": { "republican": "0.51", "democratic": "0.49" } }, "MS": { "name": "Mississippi", "votes": 6, "win": { "NONE": 1, "republican": 13, "democratic": 21, "independent": 2 }, "winRate": { "republican": "0.36", "democratic": "0.58", "independent": "0.06" } }, "MO": { "name": "Missouri", "votes": 10, "win": { "republican": 16, "democratic": 21 }, "winRate": { "republican": "0.43", "democratic": "0.57" } }, "MT": { "name": "Montana", "votes": 3, "win": { "NONE": 6, "republican": 20, "democratic": 11 }, "winRate": { "republican": "0.65", "democratic": "0.35" } }, "NE": { "name": "Nebraska", "votes": 5, "win": { "republican": 30, "democratic": 7 }, "winRate": { "republican": "0.81", "democratic": "0.19" } }, "NV": { "name": "Nevada", "votes": 6, "win": { "republican": 19, "democratic": 17, "independent": 1 }, "winRate": { "republican": "0.51", "democratic": "0.46", "independent": "0.03" } }, "NH": { "name": "New Hampshire", "votes": 4, "win": { "republican": 26, "democratic": 11 }, "winRate": { "republican": "0.70", "democratic": "0.30" } }, "NJ": { "name": "New Jersey", "votes": 14, "win": { "democratic": 19, "republican": 18 }, "winRate": { "democratic": "0.51", "republican": "0.49" } }, "NM": { "name": "New Mexico", "votes": 5, "win": { "NONE": 11, "democratic": 14, "republican": 12 }, "winRate": { "democratic": "0.54", "republican": "0.46" } }, "NY": { "name": "New York", "votes": 29, "win": { "democratic": 20, "republican": 17 }, "winRate": { "democratic": "0.54", "republican": "0.46" } }, "NC": { "name": "North Carolina", "votes": 15, "win": { "republican": 13, "democratic": 24 }, "winRate": { "republican": "0.35", "democratic": "0.65" } }, "ND": { "name": "North Dakota", "votes": 3, "win": { "NONE": 6, "independent": 1, "republican": 25, "democratic": 5 }, "winRate": { "independent": "0.03", "republican": "0.81", "democratic": "0.16" } }, "OH": { "name": "Ohio", "votes": 18, "win": { "republican": 25, "democratic": 12 }, "winRate": { "republican": "0.68", "democratic": "0.32" } }, "OK": { "name": "Oklahoma", "votes": 7, "win": { "NONE": 10, "democratic": 10, "republican": 17 }, "winRate": { "democratic": "0.37", "republican": "0.63" } }, "OR": { "name": "Oregon", "votes": 7, "win": { "democratic": 14, "republican": 23 }, "winRate": { "democratic": "0.38", "republican": "0.62" } }, "PA": { "name": "Pennsylvania", "votes": 20, "win": { "republican": 24, "democratic": 13 }, "winRate": { "republican": "0.65", "democratic": "0.35" } }, "RI": { "name": "Rhode Island", "votes": 4, "win": { "republican": 18, "democratic": 19 }, "winRate": { "republican": "0.49", "democratic": "0.51" } }, "SC": { "name": "South Carolina", "votes": 9, "win": { "republican": 16, "democratic": 21 }, "winRate": { "republican": "0.43", "democratic": "0.57" } }, "SD": { "name": "South Dakota", "votes": 3, "win": { "NONE": 6, "republican": 27, "democratic": 4 }, "winRate": { "republican": "0.87", "democratic": "0.13" } }, "TN": { "name": "Tennessee", "votes": 11, "win": { "republican": 15, "democratic": 22 }, "winRate": { "republican": "0.41", "democratic": "0.59" } }, "TX": { "name": "Texas", "votes": 38, "win": { "NONE": 1, "democratic": 23, "republican": 13 }, "winRate": { "democratic": "0.64", "republican": "0.36" } }, "UT": { "name": "Utah", "votes": 6, "win": { "NONE": 7, "democratic": 8, "republican": 22 }, "winRate": { "democratic": "0.27", "republican": "0.73" } }, "VT": { "name": "Vermont", "votes": 3, "win": { "republican": 30, "democratic": 7 }, "winRate": { "republican": "0.81", "democratic": "0.19" } }, "VA": { "name": "Virginia", "votes": 13, "win": { "NONE": 1, "republican": 15, "democratic": 21 }, "winRate": { "republican": "0.42", "democratic": "0.58" } }, "WA": { "name": "Washington", "votes": 12, "win": { "NONE": 6, "republican": 15, "democratic": 16 }, "winRate": { "republican": "0.48", "democratic": "0.52" } }, "WV": { "name": "West Virginia", "votes": 5, "win": { "republican": 17, "democratic": 20 }, "winRate": { "republican": "0.46", "democratic": "0.54" } }, "WI": { "name": "Wisconsin", "votes": 10, "win": { "republican": 21, "democratic": 15, "independent": 1 }, "winRate": { "republican": "0.57", "democratic": "0.41", "independent": "0.03" } }, "WY": { "name": "Wyoming", "votes": 3, "win": { "NONE": 6, "republican": 23, "democratic": 8 }, "winRate": { "republican": "0.74", "democratic": "0.26" } } }, results: {}, modalBuffer: null, uid: ""
};
var stateColors = { republican: '#DC1A21', democratic: '#00AEF3', thirdparty: '#FAC82F', none: '#ddd'
};
loadContent();
/** * Class a create Candidates and hold their information. */
function Candidate(_name, _party, _image, _color) { this.name = _name; this.party = _party; this.displayParty = _party; this.image = new Img(_image); this.color = _color; this.votes = 0;
}
function Img(_source) { this.source = (_source) ? _source : '/assets/default.png'; if (typeof _source === 'string') { this.buffer = this.source; this.type = 'url'; //Rebuild the path for the embed view. if (this.buffer.indexOf('/assets/') === -1 && this.buffer.indexOf('http') === -1) { var parts = this.buffer.split('/'); this.buffer = '/map/' + parts[parts.length - 2] + '/' + parts[parts.length - 1]; } } else { this.buffer = null; this.type = 'file'; }
}
function loadContent() { //Set Election results to 2012. Election.title = document.getElementById('init-title').value; Election.results = JSON.parse(document.getElementById('init-results').value); Election.candidates = JSON.parse(document.getElementById('init-candidates').value); for (var party in Election.candidates) { Election.candidates[party].image = new Img(Election.candidates[party].image); } // Load content. var result = {} for (var state in Election.results) { var vote = Election.results[state]; result[state] = { "background-color": (vote == "democratic" ? stateColors.democratic : (vote == "republican" ? stateColors.republican : (vote == "independent" ? stateColors.thirdparty : "#ddd"))) }; } //Render map zingchart.render({ id: 'election-map', data: { backgroundColor: '#FFF', plotarea: { margin: '0 0 0 0', }, globals: { fontFamily: 'Titillium Web', }, shapes: [{ type: 'zingchart.maps', options: { id: 'map', name: 'usa', scale: true, style: { cursor: 'hand', borderColor: 'white', tooltip: { visible: false }, hoverState: { backgroundColor: 'transparent', borderColor: "#FFF", borderWidth: 2 }, items: result } } }] }, height: 500, width: 800 }); //Render tooltips chart zingchart.render({ id: 'tooltip-chart', height: 60, width: 60, data: { type: 'pie', plotarea: { margin: 0 }, plot: { valueBox: { visible: false, fontSize: 8, }, }, series: [{ values: [2], backgroundColor: stateColors.republican }, { values: [5], backgroundColor: stateColors.democrat }, ] } }); //Render result chart zingchart.render({ id: 'result-chart', height: 20, data: { type: "hbar", scaleY: { visible: false, values: "0:538:1" }, scaleX: { visible: false }, plotarea: { margin: 0, padding: 0 }, plot: { stacked: true, tooltip: { visible: false }, hoverState: { visible: false } }, shapes: [{ type: 'rect', width: 2, height: '100%', x: '50%', backgroundColor: "#000" }], series: [{ values: [332], backgroundColor: '#00AEF3' }, { values: [0], backgroundColor: '#DDD' }, { values: [206], backgroundColor: '#DC1A21' }] } }); updateTitle(); updateResults(); updateCandidates(); updateResultChart();
}
function updateTitle() { var title = document.getElementById('title-display'); var titleEdit = document.getElementById('title-edit'); title.innerHTML = titleEdit.value = Election.title;
}
function updateResults() { var results = {}; for (var id in Election.results) { results[Election.results[id]] = (results[Election.results[id]]) ? results[Election.results[id]] + Election.states[id].votes : Election.states[id].votes; } for (var party in Election.candidates) { Election.candidates[party].votes = (results[party]) ? results[party] : 0; }
}
function updateCandidates() { var results = document.getElementById('result-container'); results.innerHTML = "" for (var party in Election.candidates) { results.appendChild(createCandidate(party)); }
}
function createCandidate(party) { var ele = document.createElement('div'); ele.className = 'result' ele.setAttribute('data-party', party); var candidate = Election.candidates[party]; var showWonState = (candidate.votes >= 270) ? '' : 'hidden'; ele.innerHTML = "" + "<div class='edit-candidate'>" + "<span class='hint--top' data-hint='Edit Candidate'><i class='fa fa-pencil-square-o' onclick='openModal(\"" + candidate.party + "\")'></i></span>" + "</div>" + "<div class='profile-pic' style=\"background-image: url('" + candidate.image.buffer + "')\"></div>" + "<div class='candidate' style='color:" + candidate.color + "'>" + "<div class='name'>" + candidate.name + "</div>" + "<div class='party'>" + capitalize(candidate.displayParty) + " Party</div>" + "<div class='score'>" + candidate.votes + " <i class='fa fa-check-circle " + showWonState + "' style='color:#4CAF50'></i>" + "</div>" + "</div>"; return ele;
}
function updateResultChart() { var values = [] for (var party in Election.candidates) { values.push(Election.candidates[party].votes); } var remaining = 538 - (values[0] + values[1]); zingchart.exec('result-chart', 'setseriesvalues', { values: [ [values[0]], [remaining], [values[1]] ] }); document.getElementById('result-claimed').innerHTML = remaining;
}
function getPartyColor(party) { return (party === 'republican') ? stateColors.republican : (party === 'democratic') ? stateColors.democratic : stateColors.thirdparty
}
function capitalize(word) { return word.substr(0, 1).toUpperCase() + word.substr(1);
}
/************* * Events **************/
var map = document.getElementById('election-map');
map.addEventListener('mousemove', function(e) { var tooltip = document.getElementById('election-tooltip'); var rect = tooltip.getBoundingClientRect(); tooltip.style.left = e.pageX - rect.width / 2; tooltip.style.top = e.pageY - (rect.height + 20);
});
zingchart.bind('election-map', 'shape_mouseover', function(e) { var tooltip = document.getElementById('election-tooltip'); tooltip.className = "map-tooltip"; var rect = tooltip.getBoundingClientRect(); tooltip.style.left = e.pageX - rect.width / 2; tooltip.style.top = e.pageY - (rect.height + 20); //Fill in context for the tooltip var state = Election.states[e.shapeid]; //Tooltip title document.getElementById('tooltip-title').innerHTML = state.name; document.getElementById('tooltip-subtitle').innerHTML = state.votes + ' Electoral Votes'; //Update chart var data = []; for (var id in state.winRate) { data.push({ values: [parseFloat([state.winRate[id]]) * 100], 'background-color': getPartyColor(id) }) } zingchart.exec('tooltip-chart', 'setdata', { data: { type: 'pie', plotarea: { margin: 0 }, plot: { valueBox: { visible: false, fontSize: 8, }, }, series: data } }); //Update chart data var chartDataEle = document.getElementById('tooltip-chart-data'); chartDataEle.innerHTML = ""; //Sort ids by value. var arr = Object.keys(state.winRate).map(function(key) { return { name: key, value: state.winRate[key] } }); arr.sort(function(a, b) { return a.value < b.value; }); for (var i = 0; i < arr.length; i++) { var item = document.createElement('div'); var name = capitalize(arr[i].name); item.innerHTML = name + " " + parseInt(arr[i].value * 100) + "%"; item.style.color = getPartyColor(arr[i].name); chartDataEle.appendChild(item); }
});
zingchart.bind('election-map', 'shape_mouseout', function(e) { var tooltip = document.getElementById('election-tooltip'); tooltip.className = "map-tooltip hidden";
});
//Debouncing map for resizing and flexbox.
function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); };
};
/**************************** * Visual Updates *****************************/
function updateControls() { var parties = []; for (var party in Election.candidates) { parties.push(Election.candidates[party].displayParty); } document.getElementById('slider-left').innerHTML = capitalize(parties[0]); document.getElementById('slider-right').innerHTML = capitalize(parties[1]);
}
var toggleElements = document.getElementsByClassName('toggle-switch');
for (var i = 0; i < toggleElements.length; i++) { toggleElements[i].addEventListener('click', function() { var randomButton = document.getElementById('random-button'); var trumpButton = document.getElementById('trump-button'); randomButton.className = trumpButton.className = 'button ' + this.getAttribute('data-state'); randomizeCandidates(this.getAttribute('data-state') === 'serious'); });
}
function randomizeTrump() { randomizeCandidates(null, true);
}
function randomizeCandidates(bSerious, bTrump) { if (typeof bSerious === 'undefined' || bSerious === null) { bSerious = document.getElementById('serious-mode').checked; } bTrump = (typeof bTrump !== 'undefined'); // var randomButton = document.getElementById('random-button'); if (bSerious) { // randomButton.className ="button serious"; var newRepublican = republicanPool[Math.floor(Math.random() * republicanPool.length)]; var newDemocrat = democraticPool[Math.floor(Math.random() * democraticPool.length)]; var republican = Election.candidates['republican']; republican.name = newRepublican.name; republican.image = new Img(newRepublican.image); var democratic = Election.candidates['democratic']; democratic.name = newDemocrat.name; democratic.image = new Img(newDemocrat.image); } else { // randomButton.className ="button fun"; for (var party in Election.candidates) { var candidate = Election.candidates[party]; var newCandidate = candidatePool[Math.floor(Math.random() * candidatePool.length)]; candidate.name = newCandidate.name; candidate.image = new Img(newCandidate.image); } } if (bTrump) { var candidate = Election.candidates.republican; candidate.name = 'Donald Trump'; candidate.image = new Img('http://i.giphy.com/xTiTnHXbRoaZ1B1Mo8.gif'); } randomizeResults();
}
function randomizeResults() { for (var state in Election.results) { Election.results[state] = ((Math.floor(Math.random() * 10)) % 2) ? 'democratic' : 'republican'; } updateResults(); updateCandidates(); updateResultChart(); updateMap();
}
function skewResults(value) { var democraticCount = 0; var expectedCount = Math.ceil(538 * (value / 100)); //Simply iterate through each state alphabetically until the quota is reached. for (var id in Election.states) { var state = Election.states[id]; if (democraticCount + state.votes <= expectedCount) { democraticCount += state.votes; Election.results[id] = 'republican'; } else { Election.results[id] = 'democratic'; } } updateResults(); updateCandidates(); updateResultChart(); updateMap();
}
function setResults(e) { var val = e.currentTarget.value; if (isNaN(parseInt(val))) { for (var id in Election.results) { Election.results[id] = val; } } else { loadHistoricalData(val); } updateResults(); updateCandidates(); updateResultChart(); updateMap();
}
function loadHistoricalData(year) { for (var state in historicalResults[year]) { var vote = historicalResults[year][state]; Election.results[state] = vote; }
}
/*********** * Events ************/
/* Controls */
var slider = document.getElementById('slider-range');
noUiSlider.create(slider, { start: [50], range: { min: [0], max: [100] }
}).on('slide', function(value) { skewResults(parseInt(value))
})
Fantasy Election Generator - Script Codes
Fantasy Election Generator - Script Codes
Home Page Home
Developer ZingChart
Username zingchart
Uploaded July 28, 2022
Rating 3
Size 14,205 Kb
Views 44,528
Do you need developer help for Fantasy Election Generator?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

ZingChart (zingchart) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!