Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 2016 Presidential Poll Tracker

This project uses an API from the Huffington Post that provides polling information for
primaries, elections, and various topics. It focuses on the Republican (GOP) candidates for the
2016 Presidential Election.

When the application loads, it retrieves a list of the GOP candidates and uses a data
visualization library called D3.js to plot a bar graph of each candidate�s standing in the polls.

#### Tools used:
* jQuery 1.12.0 http://jquery.com/download/
* D3.js https://github.com/mbostock/d3
* Huffington Post Pollster API http://elections.huffingtonpost.com/pollster/api
13 changes: 10 additions & 3 deletions app.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
body {
background-color: #EEE;
}
#graph .choice {

#GOPgraph .choice, #DEMgraph .choice {
float: left;
font-family: arial;
font-size: 1.5em;
min-width: 200px;
text-align: right;
margin: 8px 5px;
}
#graph .bar {

#GOPgraph .bar, #DEMgraph .bar {
width: 0;
height: 35px;
background-color: coral;
background-color: red;
margin: 5px;
float: left;
}

#DEMgraph .bar {
background-color: blue;
}

.group:after {
content: "";
display: table;
Expand Down
34 changes: 32 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>

<div id="graph"></div>
<div id="GOPgraph"></div>

<script>

Expand All @@ -20,7 +20,37 @@
cache: true,
success: function(data) {

var candidateBar = d3.select("#graph").selectAll("div").data(data.estimates),
var candidateBar = d3.select("#GOPgraph").selectAll("div").data(data.estimates),
candidateWrapper = candidateBar.enter().append("div").classed("group", true);

candidateWrapper.append("div")
.classed("choice", true)
.text(function(candidate) {
return candidate.choice + " " + candidate.value + "%";
});

candidateWrapper.append("div")
.classed("bar", true)
.transition()
.duration(1000)
.style("width", function(candidate) {
return candidate.value * 10 + "px";
});
}
});
</script>

<div id="DEMgraph"></div>

<script>
var url = "http://elections.huffingtonpost.com/pollster/api/charts/2016-national-democratic-primary";
$.ajax(url, {
dataType: "jsonp",
jsonpCallback: "pollsterCallback",
cache: true,
success: function(data) {

var candidateBar = d3.select("#DEMgraph").selectAll("div").data(data.estimates),
candidateWrapper = candidateBar.enter().append("div").classed("group", true);

candidateWrapper.append("div")
Expand Down