Skip to content

Commit

Permalink
sorting displays of parties/candidates on provinsi and dapil pages by…
Browse files Browse the repository at this point in the history
… number of votes received by winning candidates
  • Loading branch information
tmaybe committed Jun 26, 2014
1 parent 226dbb6 commit 59a3543
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions map/js/PetaCaleg.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@
d.feature.provinsi = d;
});

// xxx (setting up data for listing provinces)
// XXX (setting up data for listing provinces)

if (context.lembaga === "DPD") {
// nest candidates by province
Expand Down Expand Up @@ -714,7 +714,7 @@
*
* {
* partai: <the party object>,
* caleg: <an Array or elected candidates>,
* caleg: <an Array of elected candidates>,
* votes: <the total number of votes for elected candidates>
* }
*/
Expand Down Expand Up @@ -875,26 +875,29 @@
return ""; // :TODO: list contained kab/kota, kecamatan, kelurahan here
});

// xxx (listing Dapil)
// XXX (listing Dapil)

// add a preview list of elected candidates
var title = body.append("ul")
.attr("class", "party-peek");

var partyList = title.selectAll("ul.partai")
.data(function(d) {
// caleg is an array (parties) of arrays of objects (candidates)
return d.caleg;
// partaiRank is an array (parties) of objects with caleg properties pointing to arrays of candidates
// only display parties with elected candidates
return d.partaiRank.filter(function(d) {
return (d.votes > 0);
});
})
.enter()
.append("li")
.attr("class", function(d) {
return "partai-" + d[0].partai.id;
return "partai-" + d.partai.id;
});

var calegList = partyList.selectAll("span.caleg")
.data(function(d) {
return d;
return d.caleg;
})
.enter()
.append("span")
Expand Down Expand Up @@ -1121,7 +1124,7 @@
body = items.append("div")
.attr("class", "media-body");

// xxx (listing Partai)
// XXX (listing Partai)

// add a preview list of elected candidates
var title = body.append("ul")
Expand Down Expand Up @@ -1204,7 +1207,7 @@
body = items.append("div")
.attr("class", "media-body");

// xxx (listing Provinsi)
// XXX (listing Provinsi)

var title = body.append("ul");

Expand Down Expand Up @@ -1236,20 +1239,24 @@
// party-peek class for listing candidates organized by party
title.attr("class", "party-peek");

// xxxx
var partyList = title.selectAll("ul.partai")
.data(function(d) {
// caleg is an array (parties) of arrays of objects (candidates)
return d.caleg;
// partaiRank is an array (parties) of objects with caleg properties pointing to arrays of candidates
// only display parties with elected candidates
return d.partaiRank.filter(function(d) {
return (d.votes > 0);
});
})
.enter()
.append("li")
.attr("class", function(d) {
return "partai-" + d[0].partai.id;
return "partai-" + d.partai.id;
});

var calegList = partyList.selectAll("span.caleg")
.data(function(d) {
return d;
return d.caleg;
})
.enter()
.append("span")
Expand Down

0 comments on commit 59a3543

Please sign in to comment.