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: 'https://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)) })

!