Skip to content

Instantly share code, notes, and snippets.

@techieshark
Forked from mbostock/.block
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techieshark/87c0c5e3dc65b949f62e to your computer and use it in GitHub Desktop.
Save techieshark/87c0c5e3dc65b949f62e to your computer and use it in GitHub Desktop.
Contributions by size and day to Scott Wiener's 2010 SF Campaign

Data retrieved Aug 9th, 2014 at the SF Ethics / Campaign Finance hackathon.

I did little to this visualization other than changing the data from that used in the original gist.

Original gist's description: This example demonstrates loading of CSV data, which is then quantized into a diverging color scale. The values are visualized as colored cells per day. Days are arranged into columns by week, then grouped by month and years. Colors by Cynthia Brewer. Layout inspired by Rick Wicklin and Robert Allison.

Date Donation
2009-08-13 500
2009-09-12 500
2009-11-12 125
2009-12-16 250
2009-09-15 500
2009-11-12 250
2009-11-12 500
2009-10-10 100
2009-08-07 500
2009-09-12 500
2009-11-14 125
2009-09-15 500
2009-11-12 300
2009-11-22 125
2009-12-28 125
2009-12-29 100
2009-11-04 125
2009-09-09 500
2009-12-09 500
2009-12-09 500
2009-09-23 125
2009-09-27 500
2009-09-15 500
2009-09-01 500
2009-11-04 200
2009-08-22 100
2009-08-09 100
2009-10-26 500
2009-09-13 500
2009-12-31 250
2009-11-12 250
2009-10-07 125
2009-11-12 100
2009-11-12 100
2009-08-24 500
2009-11-05 125
2009-08-09 100
2009-09-08 500
2009-10-10 100
2009-08-29 500
2009-11-12 250
2009-09-19 100
2009-12-19 150
2009-09-12 250
2009-09-15 500
2009-11-03 500
2009-11-12 250
2009-12-27 100
2009-09-10 250
2009-08-09 100
2009-09-11 500
2009-09-12 400
2009-09-12 125
2009-09-17 250
2009-08-26 125
2009-10-19 250
2009-11-12 100
2009-08-09 250
2009-09-29 100
2009-12-30 200
2009-10-18 150
2009-09-14 500
2009-09-01 150
2009-09-29 500
2009-09-12 500
2009-12-22 125
2009-11-12 100
2009-09-13 250
2009-09-01 500
2009-11-12 100
2009-12-08 200
2009-10-27 250
2009-12-16 250
2009-08-09 100
2009-11-12 80
2009-08-28 500
2009-08-24 500
2009-10-20 250
2009-10-14 500
2009-11-12 500
2009-09-12 125
2009-09-08 500
2009-09-15 250
2009-12-02 200
2009-08-27 500
2009-08-21 500
2009-11-12 250
2009-12-24 250
2009-10-29 100
2009-12-29 200
2009-09-26 300
2009-11-16 250
2009-08-08 250
2009-09-11 250
2009-09-15 500
2009-09-30 500
2009-11-12 250
2009-07-21 100
2009-09-15 500
2009-10-14 250
2009-12-09 250
2009-11-12 125
2009-12-23 250
2009-08-09 250
2009-12-07 250
2009-10-18 200
2009-09-15 500
2009-10-18 125
2009-09-08 500
2009-11-05 125
2009-09-11 500
2009-12-12 125
2009-09-10 125
2009-09-04 500
2009-10-05 500
2009-09-15 100
2009-12-22 125
2009-11-12 250
2009-12-16 500
2009-12-31 500
2009-08-26 500
2009-07-17 125
2009-09-15 125
2009-08-18 250
2009-09-15 500
2009-11-12 150
2009-09-09 500
2009-10-19 500
2009-08-29 500
2009-11-02 125
2009-09-14 500
2009-08-09 100
2009-10-18 500
2009-09-13 250
2009-09-29 500
2009-12-15 100
2009-11-03 125
2009-09-12 250
2009-12-31 250
2009-08-31 500
2009-09-27 125
2009-08-17 125
2009-10-14 250
2009-09-04 500
2009-10-03 250
2009-07-25 250
2009-11-12 500
2009-09-14 500
2009-08-09 200
2009-09-22 100
2009-09-29 500
2009-12-18 250
2009-09-14 500
2010-10-25 125
2010-10-19 125
2010-12-06 100
2010-12-06 250
2010-12-07 150
2010-10-18 500
2010-12-18 250
2010-10-19 125
2010-10-29 500
2010-11-04 500
2010-10-29 500
2010-10-29 500
2010-10-19 150
2010-11-02 500
2010-11-03 200
2010-10-25 200
2010-10-21 250
2010-10-21 250
2010-10-18 125
2010-12-06 75
2010-10-23 100
2010-10-23 100
2010-11-02 375
2010-10-29 100
2010-10-29 100
2010-11-02 125
2010-10-21 500
2010-10-23 100
2010-10-27 100
2010-10-21 500
2010-10-29 500
2010-11-02 125
2010-10-29 125
2010-12-06 200
2010-10-30 200
2010-12-06 250
2010-10-25 125
2010-10-21 100
2010-10-29 250
2010-12-06 250
2010-10-30 500
2010-12-06 250
2010-10-20 100
2010-10-19 250
2010-10-19 100
2010-10-27 125
2010-12-20 250
2010-12-18 500
2010-10-23 250
2010-10-23 375
2010-10-27 500
2010-10-27 500
2010-10-27 500
2010-10-26 250
2010-10-23 500
2010-12-10 500
2010-10-19 500
2010-10-19 500
2010-12-06 100
2010-10-30 250
2010-12-03 250
2010-10-23 500
2010-11-01 250
2010-12-17 500
2010-12-07 250
2010-10-23 250
2010-10-17 100
2010-10-27 500
2010-11-02 125
2010-12-10 500
2010-12-10 250
2010-12-14 100
2010-11-02 250
2010-10-29 200
2010-12-06 500
2010-10-09 100
2010-10-16 150
2010-10-06 250
2010-10-16 250
2010-10-16 250
2010-10-06 200
2010-10-16 125
2010-10-11 100
2010-10-02 500
2010-10-01 200
2010-10-15 100
2010-10-04 125
2010-10-05 100
2010-10-09 100
2010-10-05 200
2010-10-08 500
2010-10-04 250
2010-10-01 100
2010-10-02 500
2010-10-02 500
2010-10-06 100
2010-10-08 200
2010-10-16 350
2010-10-11 100
2010-10-02 500
2010-10-09 125
2010-10-09 500
2010-10-16 100
2010-10-02 200
2010-10-16 500
2010-10-15 500
2010-10-15 500
2010-10-15 500
2010-10-15 100
2010-10-02 100
2010-10-16 125
2010-10-16 500
2010-10-16 125
2010-09-21 250
2010-09-21 500
2010-08-21 250
2010-08-31 250
2010-09-22 100
2010-09-24 500
2010-09-15 250
2010-09-15 100
2010-09-24 500
2010-09-30 200
2010-08-04 500
2010-08-26 500
2010-08-21 100
2010-09-23 125
2010-08-28 100
2010-09-21 125
2010-09-28 500
2010-08-17 200
2010-09-21 200
2010-09-23 250
2010-09-21 250
2010-09-15 500
2010-09-24 200
2010-09-15 125
2010-08-07 250
2010-09-15 100
2010-09-30 250
2010-09-18 100
2010-09-17 500
2010-09-21 500
2010-09-09 100
2010-09-23 500
2010-09-23 500
2010-08-11 250
2010-09-23 250
2010-09-12 100
2010-09-23 250
2010-09-23 125
2010-09-28 250
2010-08-22 100
2010-09-15 125
2010-09-15 100
2010-09-03 250
2010-09-21 500
2010-09-07 500
2010-09-21 400
2010-09-02 100
2010-09-15 100
2010-09-17 500
2010-08-17 250
2010-07-20 500
2010-09-24 100
2010-09-01 500
2010-07-28 125
2010-09-21 250
2010-08-30 500
2010-07-02 250
2010-08-31 200
2010-09-23 200
2010-09-21 500
2010-09-24 500
2010-09-15 100
2010-08-26 500
2010-09-15 100
2010-09-29 250
2010-09-21 500
2010-07-22 500
2010-09-12 75
2010-09-28 250
2010-09-27 150
2010-08-17 500
2010-07-14 100
2010-09-15 500
2010-08-26 500
2010-08-04 500
2010-09-15 100
2010-09-27 120
2010-09-12 100
2010-08-31 250
2010-09-21 100
2010-07-17 250
2010-08-26 100
2010-09-23 100
2010-09-21 100
2010-09-30 500
2010-09-17 100
2010-08-17 250
2010-09-15 200
2010-07-07 100
2010-07-23 250
2010-09-29 500
2010-09-28 250
2010-07-31 500
2010-09-17 500
2010-08-26 500
2010-09-25 100
2010-09-21 500
2010-08-14 200
2010-09-21 250
2010-08-14 200
2010-08-16 150
2010-09-21 500
2010-08-31 250
2010-09-21 250
2010-08-14 125
2010-09-21 250
2010-09-08 250
2010-08-26 500
2010-08-24 500
2010-09-20 50
2010-09-11 100
2010-09-12 500
2010-09-27 150
2010-09-18 125
2010-08-26 500
2010-09-12 250
2010-08-13 150
2010-08-26 500
2010-08-26 500
2010-09-25 500
2010-09-12 500
2010-09-21 350
2010-08-26 500
2010-09-18 125
2010-08-28 500
2010-09-01 500
2010-09-17 100
2010-09-12 250
2010-08-05 50
2010-08-31 250
2010-08-26 500
2010-09-22 250
2010-09-22 125
2010-09-25 250
2010-09-23 500
2010-09-29 100
2010-08-11 250
2010-08-19 100
2010-09-21 100
2010-07-17 125
2010-08-01 250
2010-08-14 200
2010-08-26 500
2010-08-26 500
2010-07-24 100
2010-09-15 500
2010-09-21 500
2010-09-10 500
2010-08-05 125
2010-08-05 125
2010-07-17 500
2010-09-12 125
2010-08-31 250
2010-08-01 500
2010-08-15 125
2010-09-10 150
2010-08-31 500
2010-09-12 200
2010-07-17 100
2010-08-31 250
2010-09-21 250
2010-09-24 250
2010-07-24 200
2010-09-08 125
2010-08-03 250
2010-09-23 500
2010-07-17 100
2010-09-22 500
2010-08-25 125
2010-08-17 500
2010-08-17 500
2010-09-18 250
2010-09-15 500
2010-09-30 125
2010-08-14 350
2010-09-21 500
2010-08-26 500
2010-09-02 50
2010-09-21 500
2010-09-21 250
2010-08-17 150
2010-07-22 500
2010-08-17 200
2010-09-12 125
2010-08-26 500
2010-08-14 250
2010-05-24 200
2010-05-28 250
2010-05-28 200
2010-06-18 100
2010-06-22 200
2010-06-17 125
2010-06-27 100
2010-05-26 250
2010-05-25 200
2010-06-03 125
2010-06-05 250
2010-06-05 250
2010-06-22 100
2010-05-25 250
2010-05-25 100
2010-06-11 250
2010-06-25 125
2010-06-17 250
2010-06-07 500
2010-06-29 500
2010-06-28 100
2010-06-05 500
2010-05-28 250
2010-05-26 250
2010-06-05 250
2010-06-10 100
2010-06-18 250
2010-06-05 250
2010-05-28 500
2010-06-26 500
2010-06-05 100
2010-05-22 500
2010-05-22 100
2010-05-16 200
2010-05-22 100
2010-05-22 250
2010-04-10 250
2010-04-07 200
2010-05-22 500
2010-03-21 150
2010-04-09 100
2010-04-05 100
2010-05-13 125
2010-04-20 125
2010-04-26 100
2010-05-22 125
2010-04-27 500
2010-04-24 100
2010-04-03 200
2010-05-17 300
2010-05-22 125
2010-04-26 250
2010-05-20 200
2010-03-30 125
2010-04-24 125
2010-04-10 125
2010-04-13 250
2010-05-22 125
2010-05-22 100
2010-05-16 250
2010-05-22 100
2010-05-16 500
2010-05-22 250
2010-04-24 100
2010-05-05 250
2010-03-22 250
2010-04-17 100
2010-04-10 125
2010-05-22 250
2010-05-01 250
2010-04-27 125
2010-04-02 100
2010-05-20 100
2010-03-21 250
2010-05-22 100
2010-04-12 500
2010-05-20 200
2010-03-27 500
2010-04-24 101
2010-05-20 300
2010-05-22 100
2010-05-22 500
2010-04-03 200
2010-05-12 125
2010-05-15 100
2010-04-24 100
2010-05-16 100
2010-05-04 500
2010-05-03 200
2010-05-05 100
2010-04-28 200
2010-04-27 250
2010-04-10 250
2010-05-22 200
2010-03-21 125
2010-05-22 100
2010-05-16 150
2010-03-23 500
2010-04-22 125
2010-04-24 125
2010-05-03 100
2010-04-24 125
2010-05-04 250
2010-03-27 50
2010-04-18 250
2010-04-24 150
2010-05-20 500
2010-03-22 100
2010-05-03 100
2010-04-06 100
2010-04-27 500
2010-04-18 100
2010-01-31 250
2010-01-31 75
2010-03-17 250
2010-03-16 250
2010-03-17 250
2010-02-01 125
2010-01-25 250
2010-01-23 100
2010-01-31 100
2010-01-17 100
2010-01-31 125
2010-01-31 125
2010-01-18 250
2010-02-06 125
2010-01-31 275
2010-01-20 125
2010-02-05 100
2010-02-03 125
2010-01-31 125
2010-01-31 150
2010-03-08 100
2010-02-11 250
2010-02-23 250
2010-01-04 150
2010-01-27 200
2010-02-10 150
2010-02-02 375
2010-02-26 500
2010-01-04 125
2010-01-14 100
2010-01-27 375
2010-01-31 125
2010-01-31 75
2010-02-27 100
2010-01-14 500
2010-03-13 250
2010-01-14 125
2010-01-31 100
2010-01-14 100
2010-02-03 125
2010-02-01 150
2010-03-01 100
2011-07-15 500
2011-01-06 200
2011-01-06 200
2011-02-10 500
2011-01-06 200
2011-02-10 200
2011-02-24 250
2011-03-25 500
2011-02-10 500
2011-01-06 125
2011-02-10 200
2011-01-06 125
2011-01-06 125
2011-01-06 100
2011-02-10 500
2011-01-06 100
2011-02-10 100
2011-02-10 500
2011-01-06 125
2011-01-11 500
2011-02-10 250
2011-01-06 500
2011-02-04 100
2011-01-06 200
2011-01-06 500
2011-01-22 500
2011-01-06 250
2011-01-06 250
2011-02-10 500
2011-01-13 500
2011-01-06 125
2011-02-10 200
2011-02-10 250
2011-02-04 250
2011-01-06 100
2011-02-19 500
2011-02-10 200
2011-01-06 200
2011-01-06 200
2011-02-10 500
2011-02-10 500
2011-01-06 100
2011-01-06 100
2011-02-10 200
2011-01-06 150
2011-01-01 500
2011-02-10 500
2011-01-13 500
2011-01-06 100
2011-01-27 500
2011-02-10 500
2011-01-06 250
2011-01-06 500
2011-01-06 150
2011-01-06 150
2011-01-06 125
2011-03-25 500
2011-01-07 500
2011-04-20 500
2011-01-05 500
2011-02-10 200
2011-03-25 500
2011-01-06 100
2011-02-10 100
2012-08-10 375
2012-08-30 -375
// get contributions from mongoDB
db.schA.find({'filer_naml': /Wiener.*Supervisor.*2010/}, {filer_naml: 1, tran_date: 1, tran_amt1: 1})
//then do some array mapping to return:
//Date,Donation
//tran_date + "," + tran_amt1
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
shape-rendering: crispEdges;
}
.day {
fill: #fff;
stroke: #ccc;
}
.month {
fill: none;
stroke: #000;
stroke-width: 2px;
}
.RdYlGn .q0-11{fill:rgb(165,0,38)}
.RdYlGn .q1-11{fill:rgb(215,48,39)}
.RdYlGn .q2-11{fill:rgb(244,109,67)}
.RdYlGn .q3-11{fill:rgb(253,174,97)}
.RdYlGn .q4-11{fill:rgb(254,224,139)}
.RdYlGn .q5-11{fill:rgb(255,255,191)}
.RdYlGn .q6-11{fill:rgb(217,239,139)}
.RdYlGn .q7-11{fill:rgb(166,217,106)}
.RdYlGn .q8-11{fill:rgb(102,189,99)}
.RdYlGn .q9-11{fill:rgb(26,152,80)}
.RdYlGn .q10-11{fill:rgb(0,104,55)}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="./main.js"></script>
var width = 960,
height = 136,
cellSize = 17; // cell size
var day = d3.time.format("%w"),
week = d3.time.format("%U"),
percent = d3.format(".1%"),
format = d3.time.format("%Y-%m-%d");
var color = d3.scale.quantize()
.domain([-.05, .05])
.range(d3.range(11).map(function(d) { return "q" + d + "-11"; }));
var svg = d3.select("body").selectAll("svg")
.data(d3.range(2008, 2014))
.enter().append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "RdYlGn")
.append("g")
.attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");
svg.append("text")
.attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
.style("text-anchor", "middle")
.text(function(d) { return d; });
var rect = svg.selectAll(".day")
.data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("rect")
.attr("class", "day")
.attr("width", cellSize)
.attr("height", cellSize)
.attr("x", function(d) { return week(d) * cellSize; })
.attr("y", function(d) { return day(d) * cellSize; })
.datum(format);
rect.append("title")
.text(function(d) { return d; });
svg.selectAll(".month")
.data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("path")
.attr("class", "month")
.attr("d", monthPath);
d3.csv("contributions.csv", function(error, csv) {
var donations = csv.map(function(row) { return parseInt(row.Donation) })
// var min = d3.min(donations)
// var max = d3.max(donations)
var sum = d3.sum(donations)
var data = d3.nest()
.key(function(d) { return d.Date; })
.rollup(function(d) { return d3.sum(d, function(element) { return element.Donation; }) / sum;})
.map(csv);
rect.filter(function(d) { return d in data; })
.attr("class", function(d) { return "day " + color(data[d]); })
.select("title")
.text(function(d) { return d + ": " + percent(data[d]); });
});
function monthPath(t0) {
var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
d0 = +day(t0), w0 = +week(t0),
d1 = +day(t1), w1 = +week(t1);
return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize
+ "H" + w0 * cellSize + "V" + 7 * cellSize
+ "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize
+ "H" + (w1 + 1) * cellSize + "V" + 0
+ "H" + (w0 + 1) * cellSize + "Z";
}
d3.select(self.frameElement).style("height", "2910px");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment