Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hexagonal cartogram of electorate results from 2011 New Zealand election.
var electorates = {
"results": {
"07": {
"electorate_candidate": "BENNETT, Paula Lee",
"urban": "yes",
"map_id": 7,
"electoral_district": "Waitakere",
"valid_winning_candidate_votes": 13465,
"percentage_of_elected_candidate_votes_cast_in_electorate": "44.74%",
"total_votes_cast": 31857,
"on_the_party_list": "yes",
"majority": 9,
"party": "National Party",
"maori_electorate": "no"
},
"30": {
"electorate_candidate": "ARDERN, Philip Shane",
"urban": "",
"map_id": 30,
"electoral_district": "Taranaki-King Country",
"valid_winning_candidate_votes": 20842,
"percentage_of_elected_candidate_votes_cast_in_electorate": "69.65%",
"total_votes_cast": 31461,
"on_the_party_list": "yes",
"majority": 15089,
"party": "National Party",
"maori_electorate": "no"
},
"42": {
"electorate_candidate": "FAAFOI, Kristopher John",
"urban": "yes",
"map_id": 42,
"electoral_district": "Mana",
"valid_winning_candidate_votes": 16323,
"percentage_of_elected_candidate_votes_cast_in_electorate": "48.61%",
"total_votes_cast": 35291,
"on_the_party_list": "yes",
"majority": 2230,
"party": "Labour Party",
"maori_electorate": "no"
},
"48": {
"electorate_candidate": "SMITH, Nicolas Rex",
"urban": "",
"map_id": 48,
"electoral_district": "Nelson",
"valid_winning_candidate_votes": 18360,
"percentage_of_elected_candidate_votes_cast_in_electorate": "53.14%",
"total_votes_cast": 35696,
"on_the_party_list": "yes",
"majority": 7088,
"party": "National Party",
"maori_electorate": "no"
},
"22": {
"electorate_candidate": "COLLINS, Judith Anne",
"urban": "",
"map_id": 22,
"electoral_district": "Papakura",
"valid_winning_candidate_votes": 18096,
"percentage_of_elected_candidate_votes_cast_in_electorate": "59.59%",
"total_votes_cast": 32302,
"on_the_party_list": "yes",
"majority": 9890,
"party": "National Party",
"maori_electorate": "no"
},
"58": {
"electorate_candidate": "GOODHEW, Joanne Gay",
"urban": "",
"map_id": 58,
"electoral_district": "Rangitata",
"valid_winning_candidate_votes": 19580,
"percentage_of_elected_candidate_votes_cast_in_electorate": "55.77%",
"total_votes_cast": 36404,
"on_the_party_list": "yes",
"majority": 6537,
"party": "National Party",
"maori_electorate": "no"
},
"60": {
"electorate_candidate": "CURRAN, Clare Elizabeth",
"urban": "yes",
"map_id": 60,
"electoral_district": "Dunedin South",
"valid_winning_candidate_votes": 16844,
"percentage_of_elected_candidate_votes_cast_in_electorate": "48.89%",
"total_votes_cast": 35692,
"on_the_party_list": "yes",
"majority": 4175,
"party": "Labour Party",
"maori_electorate": "no"
},
"61": {
"electorate_candidate": "CLARK, David Scott",
"urban": "yes",
"map_id": 61,
"electoral_district": "Dunedin North",
"valid_winning_candidate_votes": 12976,
"percentage_of_elected_candidate_votes_cast_in_electorate": "44.25%",
"total_votes_cast": 30292,
"on_the_party_list": "yes",
"majority": 3489,
"party": "Labour Party",
"maori_electorate": "no"
},
"62": {
"electorate_candidate": "ENGLISH, Simon William",
"urban": "",
"map_id": 62,
"electoral_district": "Clutha-Southland",
"valid_winning_candidate_votes": 21375,
"percentage_of_elected_candidate_votes_cast_in_electorate": "68.83%",
"total_votes_cast": 32176,
"on_the_party_list": "yes",
"majority": 16168,
"party": "National Party",
"maori_electorate": "no"
},
"63": {
"electorate_candidate": "ROY, Eric Wilbur",
"urban": "",
"map_id": 63,
"electoral_district": "Invercargill",
"valid_winning_candidate_votes": 17275,
"percentage_of_elected_candidate_votes_cast_in_electorate": "54.58%",
"total_votes_cast": 32811,
"on_the_party_list": "yes",
"majority": 6263,
"party": "National Party",
"maori_electorate": "no"
},
"35": {
"electorate_candidate": "TOLLEY, Anne Merrilyn",
"urban": "",
"map_id": 35,
"electoral_district": "East Coast",
"valid_winning_candidate_votes": 14003,
"percentage_of_elected_candidate_votes_cast_in_electorate": "48.27%",
"total_votes_cast": 30264,
"on_the_party_list": "yes",
"majority": 4774,
"party": "National Party",
"maori_electorate": "no"
},
"32": {
"electorate_candidate": "YOUNG, Jonathan Edgar Joseph",
"urban": "",
"map_id": 32,
"electoral_district": "New Plymouth",
"valid_winning_candidate_votes": 17644,
"percentage_of_elected_candidate_votes_cast_in_electorate": "53.31%",
"total_votes_cast": 34334,
"on_the_party_list": "yes",
"majority": 4270,
"party": "National Party",
"maori_electorate": "no"
},
"24": {
"electorate_candidate": "TISCH, William Lindsay",
"urban": "",
"map_id": 24,
"electoral_district": "Waikato",
"valid_winning_candidate_votes": 19817,
"percentage_of_elected_candidate_votes_cast_in_electorate": "64.9%",
"total_votes_cast": 31970,
"on_the_party_list": "yes",
"majority": 14198,
"party": "National Party",
"maori_electorate": "no"
},
"25": {
"electorate_candidate": "SIMPSON, Scott Anthony",
"urban": "",
"map_id": 25,
"electoral_district": "Coromandel",
"valid_winning_candidate_votes": 18571,
"percentage_of_elected_candidate_votes_cast_in_electorate": "55.05%",
"total_votes_cast": 35006,
"on_the_party_list": "yes",
"majority": 12740,
"party": "National Party",
"maori_electorate": "no"
},
"26": {
"electorate_candidate": "BENNETT, David Allister",
"urban": "yes",
"map_id": 26,
"electoral_district": "Hamilton East",
"valid_winning_candidate_votes": 18505,
"percentage_of_elected_candidate_votes_cast_in_electorate": "57.11%",
"total_votes_cast": 33824,
"on_the_party_list": "yes",
"majority": 8275,
"party": "National Party",
"maori_electorate": "no"
},
"27": {
"electorate_candidate": "MACINDOE, Timothy Harley",
"urban": "yes",
"map_id": 27,
"electoral_district": "Hamilton West",
"valid_winning_candidate_votes": 16587,
"percentage_of_elected_candidate_votes_cast_in_electorate": "53.26%",
"total_votes_cast": 32592,
"on_the_party_list": "yes",
"majority": 4418,
"party": "National Party",
"maori_electorate": "no"
},
"20": {
"electorate_candidate": "SIO, Su'a Viliamu",
"urban": "yes",
"map_id": 20,
"electoral_district": "M\u0101ngere",
"valid_winning_candidate_votes": 18177,
"percentage_of_elected_candidate_votes_cast_in_electorate": "75.9%",
"total_votes_cast": 26528,
"on_the_party_list": "yes",
"majority": 15159,
"party": "Labour Party",
"maori_electorate": "no"
},
"21": {
"electorate_candidate": "WALL, Louisa Hareruia",
"urban": "yes",
"map_id": 21,
"electoral_district": "Manurewa",
"valid_winning_candidate_votes": 14961,
"percentage_of_elected_candidate_votes_cast_in_electorate": "63.27%",
"total_votes_cast": 26457,
"on_the_party_list": "no",
"majority": 8610,
"party": "Labour Party",
"maori_electorate": "no"
},
"04": {
"electorate_candidate": "KEY, John Phillip",
"urban": "",
"map_id": 4,
"electoral_district": "Helensville",
"valid_winning_candidate_votes": 26011,
"percentage_of_elected_candidate_votes_cast_in_electorate": "74.38%",
"total_votes_cast": 36266,
"on_the_party_list": "yes",
"majority": 21066,
"party": "National Party",
"maori_electorate": "no"
},
"23": {
"electorate_candidate": "HUTCHISON, Charles Paul Telford",
"urban": "",
"map_id": 23,
"electoral_district": "Hunua",
"valid_winning_candidate_votes": 22563,
"percentage_of_elected_candidate_votes_cast_in_electorate": "65.59%",
"total_votes_cast": 35885,
"on_the_party_list": "yes",
"majority": 16797,
"party": "National Party",
"maori_electorate": "no"
},
"46": {
"electorate_candidate": "ROBERTSON, Grant Murray",
"urban": "yes",
"map_id": 46,
"electoral_district": "Wellington Central",
"valid_winning_candidate_votes": 18836,
"percentage_of_elected_candidate_votes_cast_in_electorate": "49.15%",
"total_votes_cast": 39816,
"on_the_party_list": "yes",
"majority": 6376,
"party": "Labour Party",
"maori_electorate": "no"
},
"47": {
"electorate_candidate": "KING, Annette Faye",
"urban": "yes",
"map_id": 47,
"electoral_district": "Rongotai",
"valid_winning_candidate_votes": 18179,
"percentage_of_elected_candidate_votes_cast_in_electorate": "50.52%",
"total_votes_cast": 37596,
"on_the_party_list": "yes",
"majority": 9047,
"party": "Labour Party",
"maori_electorate": "no"
},
"08": {
"electorate_candidate": "COLEMAN, Jonathan David",
"urban": "yes",
"map_id": 8,
"electoral_district": "Northcote",
"valid_winning_candidate_votes": 18908,
"percentage_of_elected_candidate_votes_cast_in_electorate": "58.46%",
"total_votes_cast": 33454,
"on_the_party_list": "yes",
"majority": 9379,
"party": "National Party",
"maori_electorate": "no"
},
"45": {
"electorate_candidate": "MALLARD, Trevor Colin",
"urban": "yes",
"map_id": 45,
"electoral_district": "Hutt South",
"valid_winning_candidate_votes": 15828,
"percentage_of_elected_candidate_votes_cast_in_electorate": "49.38%",
"total_votes_cast": 33550,
"on_the_party_list": "yes",
"majority": 4825,
"party": "Labour Party",
"maori_electorate": "no"
},
"28": {
"electorate_candidate": "RYALL, Anthony Boyd Williams",
"urban": "",
"map_id": 28,
"electoral_district": "Bay of Plenty",
"valid_winning_candidate_votes": 23710,
"percentage_of_elected_candidate_votes_cast_in_electorate": "67.48%",
"total_votes_cast": 36622,
"on_the_party_list": "yes",
"majority": 17760,
"party": "National Party",
"maori_electorate": "no"
},
"43": {
"electorate_candidate": "HIPKINS, Christopher John",
"urban": "yes",
"map_id": 43,
"electoral_district": "Rimutaka",
"valid_winning_candidate_votes": 17171,
"percentage_of_elected_candidate_votes_cast_in_electorate": "51.58%",
"total_votes_cast": 34870,
"on_the_party_list": "yes",
"majority": 3286,
"party": "Labour Party",
"maori_electorate": "no"
},
"40": {
"electorate_candidate": "GUY, Allen Nathan",
"urban": "",
"map_id": 40,
"electoral_district": "\u014ctaki",
"valid_winning_candidate_votes": 19151,
"percentage_of_elected_candidate_votes_cast_in_electorate": "51.57%",
"total_votes_cast": 38098,
"on_the_party_list": "yes",
"majority": 5231,
"party": "National Party",
"maori_electorate": "no"
},
"41": {
"electorate_candidate": "HAYES, John Bernard",
"urban": "",
"map_id": 41,
"electoral_district": "Wairarapa",
"valid_winning_candidate_votes": 17881,
"percentage_of_elected_candidate_votes_cast_in_electorate": "52.65%",
"total_votes_cast": 35473,
"on_the_party_list": "yes",
"majority": 7135,
"party": "National Party",
"maori_electorate": "no"
},
"09": {
"electorate_candidate": "TWYFORD, Philip Stoner",
"urban": "yes",
"map_id": 9,
"electoral_district": "Te Atat\u016b",
"valid_winning_candidate_votes": 15860,
"percentage_of_elected_candidate_votes_cast_in_electorate": "53.83%",
"total_votes_cast": 31668,
"on_the_party_list": "yes",
"majority": 5416,
"party": "Labour Party",
"maori_electorate": "no"
},
"31": {
"electorate_candidate": "UPSTON, Louise Claire",
"urban": "",
"map_id": 31,
"electoral_district": "Taup\u014d",
"valid_winning_candidate_votes": 20934,
"percentage_of_elected_candidate_votes_cast_in_electorate": "63.65%",
"total_votes_cast": 34204,
"on_the_party_list": "yes",
"majority": 14115,
"party": "National Party",
"maori_electorate": "no"
},
"59": {
"electorate_candidate": "DEAN, Jacqueline Isobel",
"urban": "",
"map_id": 59,
"electoral_district": "Waitaki",
"valid_winning_candidate_votes": 23219,
"percentage_of_elected_candidate_votes_cast_in_electorate": "61.45%",
"total_votes_cast": 39000,
"on_the_party_list": "yes",
"majority": 14143,
"party": "National Party",
"maori_electorate": "no"
},
"52": {
"electorate_candidate": "ADAMS, Amy Juliet",
"urban": "",
"map_id": 52,
"electoral_district": "Selwyn",
"valid_winning_candidate_votes": 24963,
"percentage_of_elected_candidate_votes_cast_in_electorate": "69.14%",
"total_votes_cast": 37168,
"on_the_party_list": "yes",
"majority": 19451,
"party": "National Party",
"maori_electorate": "no"
},
"05": {
"electorate_candidate": "McCULLY, Murray Stuart",
"urban": "yes",
"map_id": 5,
"electoral_district": "East Coast Bays",
"valid_winning_candidate_votes": 21094,
"percentage_of_elected_candidate_votes_cast_in_electorate": "64.98%",
"total_votes_cast": 33888,
"on_the_party_list": "yes",
"majority": 14641,
"party": "National Party",
"maori_electorate": "no"
},
"51": {
"electorate_candidate": "O'CONNOR, Damien Peter",
"urban": "",
"map_id": 51,
"electoral_district": "West Coast-Tasman",
"valid_winning_candidate_votes": 15753,
"percentage_of_elected_candidate_votes_cast_in_electorate": "47.51%",
"total_votes_cast": 34226,
"on_the_party_list": "no",
"majority": 2539,
"party": "Labour Party",
"maori_electorate": "no"
},
"02": {
"electorate_candidate": "HEATLEY, Philip Reeve",
"urban": "",
"map_id": 2,
"electoral_district": "Whangarei",
"valid_winning_candidate_votes": 20049,
"percentage_of_elected_candidate_votes_cast_in_electorate": "59.18%",
"total_votes_cast": 34995,
"on_the_party_list": "yes",
"majority": 12447,
"party": "National Party",
"maori_electorate": "no"
},
"56": {
"electorate_candidate": "WOODS, Megan Cherie",
"urban": "yes",
"map_id": 56,
"electoral_district": "Wigram",
"valid_winning_candidate_votes": 14080,
"percentage_of_elected_candidate_votes_cast_in_electorate": "45.11%",
"total_votes_cast": 32834,
"on_the_party_list": "yes",
"majority": 1500,
"party": "Labour Party",
"maori_electorate": "no"
},
"03": {
"electorate_candidate": "MITCHELL, Mark Patrick",
"urban": "",
"map_id": 3,
"electoral_district": "Rodney",
"valid_winning_candidate_votes": 20253,
"percentage_of_elected_candidate_votes_cast_in_electorate": "53.54%",
"total_votes_cast": 38997,
"on_the_party_list": "yes",
"majority": 12222,
"party": "National Party",
"maori_electorate": "no"
},
"33": {
"electorate_candidate": "BORROWS, Kerry James",
"urban": "",
"map_id": 33,
"electoral_district": "Whanganui",
"valid_winning_candidate_votes": 16743,
"percentage_of_elected_candidate_votes_cast_in_electorate": "53.69%",
"total_votes_cast": 32259,
"on_the_party_list": "yes",
"majority": 5046,
"party": "National Party",
"maori_electorate": "no"
},
"39": {
"electorate_candidate": "FOSS, Craig Raymond Robert",
"urban": "",
"map_id": 39,
"electoral_district": "Tukituki",
"valid_winning_candidate_votes": 19378,
"percentage_of_elected_candidate_votes_cast_in_electorate": "58.42%",
"total_votes_cast": 34641,
"on_the_party_list": "yes",
"majority": 9660,
"party": "National Party",
"maori_electorate": "no"
},
"01": {
"electorate_candidate": "SABIN, Michael Lewis",
"urban": "",
"map_id": 1,
"electoral_district": "Northland",
"valid_winning_candidate_votes": 18188,
"percentage_of_elected_candidate_votes_cast_in_electorate": "57.55%",
"total_votes_cast": 33245,
"on_the_party_list": "yes",
"majority": 11362,
"party": "National Party",
"maori_electorate": "no"
},
"06": {
"electorate_candidate": "BARRY, Margaret Mary",
"urban": "yes",
"map_id": 6,
"electoral_district": "North Shore",
"valid_winning_candidate_votes": 22709,
"percentage_of_elected_candidate_votes_cast_in_electorate": "62.44%",
"total_votes_cast": 37543,
"on_the_party_list": "yes",
"majority": 15228,
"party": "National Party",
"maori_electorate": "no"
},
"38": {
"electorate_candidate": "LEES-GALLOWAY, Iain Francis",
"urban": "yes",
"map_id": 38,
"electoral_district": "Palmerston North",
"valid_winning_candidate_votes": 16525,
"percentage_of_elected_candidate_votes_cast_in_electorate": "51.32%",
"total_votes_cast": 33534,
"on_the_party_list": "yes",
"majority": 3285,
"party": "Labour Party",
"maori_electorate": "no"
},
"29": {
"electorate_candidate": "BRIDGES, Simon Joseph",
"urban": "yes",
"map_id": 29,
"electoral_district": "Tauranga",
"valid_winning_candidate_votes": 21971,
"percentage_of_elected_candidate_votes_cast_in_electorate": "61.4%",
"total_votes_cast": 37150,
"on_the_party_list": "yes",
"majority": 17264,
"party": "National Party",
"maori_electorate": "no"
},
"14": {
"electorate_candidate": "LOTU-IIGA, Peseta Samuelu Masunu ",
"urban": "yes",
"map_id": 14,
"electoral_district": "Maunga-kiekie",
"valid_winning_candidate_votes": 16189,
"percentage_of_elected_candidate_votes_cast_in_electorate": "49.88%",
"total_votes_cast": 34696,
"on_the_party_list": "yes",
"majority": 3021,
"party": "National Party",
"maori_electorate": "no"
},
"11": {
"electorate_candidate": "O'CONNOR, Simon David",
"urban": "yes",
"map_id": 11,
"electoral_district": "T\u0101maki",
"valid_winning_candidate_votes": 24837,
"percentage_of_elected_candidate_votes_cast_in_electorate": "67.67%",
"total_votes_cast": 38366,
"on_the_party_list": "yes",
"majority": 17786,
"party": "National Party",
"maori_electorate": "no"
},
"10": {
"electorate_candidate": "KAYE, Nicola Laura",
"urban": "yes",
"map_id": 10,
"electoral_district": "Auckland Central",
"valid_winning_candidate_votes": 15038,
"percentage_of_elected_candidate_votes_cast_in_electorate": "45.39%",
"total_votes_cast": 34761,
"on_the_party_list": "yes",
"majority": 717,
"party": "National Party",
"maori_electorate": "no"
},
"13": {
"electorate_candidate": "BANKS, John",
"urban": "yes",
"map_id": 13,
"electoral_district": "Epsom",
"valid_winning_candidate_votes": 15835,
"percentage_of_elected_candidate_votes_cast_in_electorate": "44.1%",
"total_votes_cast": 37185,
"on_the_party_list": "yes",
"majority": 2261,
"party": "ACT New Zealand",
"maori_electorate": "no"
},
"12": {
"electorate_candidate": "SHEARER, David James",
"urban": "yes",
"map_id": 12,
"electoral_district": "Mt Albert",
"valid_winning_candidate_votes": 18716,
"percentage_of_elected_candidate_votes_cast_in_electorate": "59.19%",
"total_votes_cast": 33752,
"on_the_party_list": "yes",
"majority": 10021,
"party": "Labour Party",
"maori_electorate": "no"
},
"15": {
"electorate_candidate": "WILLIAMSON, Maurice Donald",
"urban": "yes",
"map_id": 15,
"electoral_district": "Pakuranga",
"valid_winning_candidate_votes": 20694,
"percentage_of_elected_candidate_votes_cast_in_electorate": "65.86%",
"total_votes_cast": 32995,
"on_the_party_list": "yes",
"majority": 13846,
"party": "National Party",
"maori_electorate": "no"
},
"..": {
"party": ""
},
"17": {
"electorate_candidate": "GOFF, Philip Bruce",
"urban": "yes",
"map_id": 17,
"electoral_district": "Mt Roskill",
"valid_winning_candidate_votes": 17906,
"percentage_of_elected_candidate_votes_cast_in_electorate": "57.15%",
"total_votes_cast": 33249,
"on_the_party_list": "yes",
"majority": 7271,
"party": "Labour Party",
"maori_electorate": "no"
},
"16": {
"electorate_candidate": "CUNLIFFE, David Richard",
"urban": "yes",
"map_id": 16,
"electoral_district": "New Lynn",
"valid_winning_candidate_votes": 16999,
"percentage_of_elected_candidate_votes_cast_in_electorate": "52.14%",
"total_votes_cast": 34345,
"on_the_party_list": "yes",
"majority": 5190,
"party": "Labour Party",
"maori_electorate": "no"
},
"19": {
"electorate_candidate": "ROSS, Jami-Lee Matenga",
"urban": "yes",
"map_id": 19,
"electoral_district": "Botany",
"valid_winning_candidate_votes": 17780,
"percentage_of_elected_candidate_votes_cast_in_electorate": "64.03%",
"total_votes_cast": 29567,
"on_the_party_list": "yes",
"majority": 10741,
"party": "National Party",
"maori_electorate": "no"
},
"54": {
"electorate_candidate": "BROWNLEE, Gerard Anthony ",
"urban": "yes",
"map_id": 54,
"electoral_district": "Ilam",
"valid_winning_candidate_votes": 20070,
"percentage_of_elected_candidate_votes_cast_in_electorate": "60.4%",
"total_votes_cast": 34551,
"on_the_party_list": "yes",
"majority": 13312,
"party": "National Party",
"maori_electorate": "no"
},
"57": {
"electorate_candidate": "DYSON, Ruth Suzanne",
"urban": "yes",
"map_id": 57,
"electoral_district": "Port Hills",
"valid_winning_candidate_votes": 15737,
"percentage_of_elected_candidate_votes_cast_in_electorate": "48.41%",
"total_votes_cast": 33678,
"on_the_party_list": "yes",
"majority": 3097,
"party": "Labour Party",
"maori_electorate": "no"
},
"49": {
"electorate_candidate": "KING, Colin McDonald",
"urban": "",
"map_id": 49,
"electoral_district": "Kaik\u014dura",
"valid_winning_candidate_votes": 19961,
"percentage_of_elected_candidate_votes_cast_in_electorate": "60.25%",
"total_votes_cast": 34575,
"on_the_party_list": "yes",
"majority": 11445,
"party": "National Party",
"maori_electorate": "no"
},
"37": {
"electorate_candidate": "TREMAIN, Christopher James",
"urban": "",
"map_id": 37,
"electoral_district": "Napier",
"valid_winning_candidate_votes": 17337,
"percentage_of_elected_candidate_votes_cast_in_electorate": "52.11%",
"total_votes_cast": 34468,
"on_the_party_list": "yes",
"majority": 3701,
"party": "National Party",
"maori_electorate": "no"
},
"36": {
"electorate_candidate": "McKELVIE, Ian Robert Flockhart",
"urban": "",
"map_id": 36,
"electoral_district": "Rangit\u012bkei",
"valid_winning_candidate_votes": 18284,
"percentage_of_elected_candidate_votes_cast_in_electorate": "58.87%",
"total_votes_cast": 32308,
"on_the_party_list": "yes",
"majority": 9382,
"party": "National Party",
"maori_electorate": "no"
},
"53": {
"electorate_candidate": "DALZIEL, Lianne Audrey",
"urban": "yes",
"map_id": 53,
"electoral_district": "Christchurch East",
"valid_winning_candidate_votes": 15559,
"percentage_of_elected_candidate_votes_cast_in_electorate": "55.54%",
"total_votes_cast": 29163,
"on_the_party_list": "no",
"majority": 5334,
"party": "Labour Party",
"maori_electorate": "no"
},
"34": {
"electorate_candidate": "McCLAY, Todd Michael",
"urban": "",
"map_id": 34,
"electoral_district": "Rotorua",
"valid_winning_candidate_votes": 17188,
"percentage_of_elected_candidate_votes_cast_in_electorate": "56.17%",
"total_votes_cast": 32097,
"on_the_party_list": "yes",
"majority": 7357,
"party": "National Party",
"maori_electorate": "no"
},
"55": {
"electorate_candidate": "WAGNER, Nicola Joanne",
"urban": "yes",
"map_id": 55,
"electoral_district": "Christchurch Central",
"valid_winning_candidate_votes": 12064,
"percentage_of_elected_candidate_votes_cast_in_electorate": "44.53%",
"total_votes_cast": 28494,
"on_the_party_list": "yes",
"majority": 47,
"party": "National Party",
"maori_electorate": "no"
},
"18": {
"electorate_candidate": "ROBERTSON, Harold Valentine Ross",
"urban": "yes",
"map_id": 18,
"electoral_district": "Manukau East",
"valid_winning_candidate_votes": 19399,
"percentage_of_elected_candidate_votes_cast_in_electorate": "77.11%",
"total_votes_cast": 28418,
"on_the_party_list": "no",
"majority": 15838,
"party": "Labour Party",
"maori_electorate": "no"
},
"44": {
"electorate_candidate": "DUNNE, Peter Francis",
"urban": "yes",
"map_id": 44,
"electoral_district": "\u014chariu",
"valid_winning_candidate_votes": 14357,
"percentage_of_elected_candidate_votes_cast_in_electorate": "38.58%",
"total_votes_cast": 38132,
"on_the_party_list": "yes",
"majority": 1392,
"party": "United Future",
"maori_electorate": "no"
},
"50": {
"electorate_candidate": "WILKINSON, Catherine Joan",
"urban": "",
"map_id": 50,
"electoral_district": "Waimakariri",
"valid_winning_candidate_votes": 16787,
"percentage_of_elected_candidate_votes_cast_in_electorate": "47.28%",
"total_votes_cast": 36516,
"on_the_party_list": "yes",
"majority": 642,
"party": "National Party",
"maori_electorate": "no"
}
},
"max_turnout": "39816"
}
<!DOCTYPE html>
<meta charset="utf-8">
<title>Hexagonal Map of NZ General Electorate Party Wins 2011</title>
<style>
.hexagon {
fill: none;
stroke: #000;
stroke-width: .5px;
}
.hex-wrapper {
display: table;
height: 100%;
width: 100%;
overflow: hidden;
padding:0;
margin:0;
}
.hex-label {
display: table-cell;
vertical-align: middle;
height: 100%;
color: white;
font-size: 12px;
font-family: sans-serif;
text-align: center;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.hexbin.v0.min.js?5c6e4f0"></script>
<script src="electorate_data.js" charset="utf-8"></script>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
//map data
var mapdata = [
'..','..','..','..','..','..','..','..','..','..','..','..','..',
'..','..','..','..','..','..','..','01','02','..','..','..','..',
'..','..','..','..','..','..','..','..','03','..','..','..','..',
'..','..','..','..','..','..','..','04','05','06','..','..','..',
'..','..','..','..','..','..','..','..','07','08','..','..','..',
'..','..','..','..','..','..','..','09','10','11','..','..','..',
'..','..','..','..','..','..','..','..','12','13','14','15','..',
'..','..','..','..','..','..','..','16','17','18','19','..','..',
'..','..','..','..','..','..','..','..','..','20','21','..','..',
'..','..','..','..','..','..','..','..','..','22','23','..','..',
'..','..','..','..','..','..','..','..','..','..','24','25','..',
'..','..','..','..','..','..','..','..','..','26','27','28','29',
'..','..','..','..','..','..','..','..','..','..','30','31','..',
'..','..','..','..','..','..','..','..','..','32','33','34','35',
'..','..','..','..','..','..','..','..','..','..','36','37','..',
'..','..','..','..','..','..','..','..','..','38','39','..','..',
'..','..','..','..','..','..','..','..','..','40','41','..','..',
'..','..','..','..','..','..','..','..','42','43','..','..','..',
'..','..','..','..','..','..','..','..','44','45','..','..','..',
'..','..','..','..','48','49','..','46','47','..','..','..','..',
'..','..','..','..','..','50','..','..','..','..','..','..','..',
'..','..','..','51','52','53','..','..','..','..','..','..','..',
'..','..','..','..','54','55','..','..','..','..','..','..','..',
'..','..','..','56','57','..','..','..','..','..','..','..','..',
'..','..','..','58','..','..','..','..','..','..','..','..','..',
'..','..','59','..','..','..','..','..','..','..','..','..','..',
'..','..','60','61','..','..','..','..','..','..','..','..','..',
'..','62','..','..','..','..','..','..','..','..','..','..','..',
'..','63','..','..','..','..','..','..','..','..','..','..','..'
];
var colors = {
'': '#fff',
'National Party': '#0776A0',
'Labour Party': '#FF2C00',
'ACT New Zealand': '#444',//'#FF8500',
'United Future': '#444'//'#CD0074'
};
//svg sizes and margins
var margin = {
top: 0,
right: 0,
bottom: 0,
left: 0
},
width = 1200,
height = 2300;
//width = 960,
//height = 800;
//The number of columns and rows of the cartogram
var MapColumns = 13, MapRows = 30;
//The maximum radius the hexagons can have to still fit the screen
var hexRadius = d3.min([width/((MapColumns + 0.5) * Math.sqrt(3)),
height/((MapRows + 1/3) * 1.5)]);
//Calculate the center positions of each hexagon
var points = [];
for (var r = 0; r < MapRows; r++) {
for (var c = 0; c < MapColumns; c++) {
points.push([hexRadius * c * 1.75, hexRadius * r * 1.5]);
}//for c
}//for r
//Create SVG element
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
//Set the hexagon radius
var hexbin = d3.hexbin()
.radius(hexRadius);
var radius = d3.scale.sqrt()
.domain([1, electorates.max_turnout])
.range([1, hexRadius]);
//Draw the hexagons
var hex = svg.selectAll(".hexagon")
.data(hexbin(points))
.enter().append("path")
.attr("class", "hexagon")
.attr("d", function(d, i) {
if (i<mapdata.length) {
electorate = electorates.results[mapdata[i]];
if ("total_votes_cast" in electorate) { return hexbin.hexagon(radius(electorate.total_votes_cast)); }
}
return hexbin.hexagon(radius(2000));
})
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.style("stroke", function (d, i) {
if (i<mapdata.length) {
electorate = electorates.results[mapdata[i]];
if (electorate.party != '') {
return colors[electorate.party]; };
}
return '#fff';
})
.style("stroke-width", "1px")
.style("stroke-opacity", "0.5")
.style("fill-opacity", function (d,i) {
if (i>=mapdata.length) {return 1;};
electorate = electorates.results[mapdata[i]];
if (electorate.party == '') {return 0;}
per = electorate.percentage_of_elected_candidate_votes_cast_in_electorate.replace('%', '');
per = parseFloat(per);
if (per > 60) {return 1;}
else if (per > 50) {return 0.75;}
else if (per > 40) {return 0.5}
else {return 0.25};
})
.style("fill", function (d, i) {
if (i<mapdata.length) {
electorate = electorates.results[mapdata[i]];
return colors[electorate.party];
}
return '#fff';
});
//a second layer of hexagons for labels
var labels = svg.selectAll(".labels")
.data(hexbin(points))
.enter()
.append("foreignObject");
//label box scale factor
var sf = 1.75;
var labelAttributes = labels
.attr('width', hexRadius*sf)
.attr('height', hexRadius*sf)
.attr("x", function (d) { return d.x - hexRadius*sf/2; })
.attr("y", function (d) { return d.y - hexRadius*sf/2; })
.append("xhtml:body")
.html(function(d, i) {
if (i<mapdata.length) {
electorate = electorates.results[mapdata[i]];
if (electorate.party == '') {return '';};
per = electorate.percentage_of_elected_candidate_votes_cast_in_electorate.replace('%', '');
per = parseInt(per);
return '<div class="hex-wrapper"><div class="hex-label">'
+ electorate.electoral_district + '<br/>'
+ '<small>' + electorate.party.substring(0,3) + ' ' + per + '%<small>'
+ '</div></div>';
}
});
//jquery hack to set the label wrapper heights
$('.hex-wrapper').height( hexRadius*sf );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment