Skip to content

Instantly share code, notes, and snippets.

@jarib
Forked from mbostock/.block
Last active December 19, 2015 05:18
Show Gist options
  • Save jarib/5902829 to your computer and use it in GitHub Desktop.
Save jarib/5902829 to your computer and use it in GitHub Desktop.
Forslag behandlet på Stortinget 2009-2013

Oversikten viser antall forslag behandlet per dag gjennom stortingsperioden.

<!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;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 136,
cellSize = 17; // cell size
var day = d3.time.format("%w"),
week = d3.time.format("%U"),
format = d3.time.format("%Y-%m-%d");
var color = d3.scale.linear()
.domain([0,420])
.range(['#ffb', 'red']);
var svg = d3.select("body").selectAll("svg")
.data(d3.range(2009, 2014))
.enter().append("svg")
.attr("width", width)
.attr("height", height)
.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("props.csv", function(error, csv) {
var data = d3.nest()
.key(function(d) { return d.Date; })
.rollup(function(d) { return d[0].Propositions; })
.map(csv);
rect.filter(function(d) { return d in data; })
.attr("class", function(d) { return "day " })
.attr('style', function(d) { return 'fill:' + color(data[d]) })
.select("title")
.text(function(d) { return d + ": " + 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", (height * 6) + "px");
</script>
Date Propositions
2009-10-07 1
2009-10-12 5
2009-10-21 1
2009-10-22 12
2009-11-05 1
2009-11-10 3
2009-11-17 11
2009-11-19 5
2009-11-26 160
2009-11-27 6
2009-12-03 35
2009-12-04 2
2009-12-07 31
2009-12-08 99
2009-12-09 58
2009-12-10 58
2009-12-11 48
2009-12-14 59
2009-12-15 63
2009-12-17 15
2010-01-07 2
2010-01-12 8
2010-01-14 1
2010-02-02 1
2010-02-04 8
2010-02-09 1
2010-02-11 12
2010-02-16 4
2010-02-18 8
2010-03-02 27
2010-03-04 19
2010-03-05 43
2010-03-09 38
2010-03-11 16
2010-03-18 7
2010-03-19 19
2010-03-22 18
2010-03-23 14
2010-03-25 21
2010-03-26 3
2010-04-19 15
2010-04-20 12
2010-04-27 24
2010-04-29 10
2010-05-03 2
2010-05-04 8
2010-05-06 8
2010-05-10 20
2010-05-11 19
2010-05-25 29
2010-05-26 1
2010-05-27 19
2010-05-31 2
2010-06-02 6
2010-06-03 7
2010-06-04 4
2010-06-07 18
2010-06-08 30
2010-06-09 10
2010-06-10 40
2010-06-11 13
2010-06-14 64
2010-06-15 47
2010-06-16 20
2010-06-17 38
2010-06-18 82
2010-10-05 8
2010-10-11 1
2010-10-12 3
2010-10-13 5
2010-10-28 11
2010-10-29 11
2010-11-11 18
2010-11-12 4
2010-11-16 38
2010-11-18 11
2010-11-19 17
2010-11-23 24
2010-11-26 224
2010-11-30 24
2010-12-02 12
2010-12-03 53
2010-12-06 51
2010-12-07 65
2010-12-08 134
2010-12-09 47
2010-12-10 52
2010-12-13 109
2010-12-14 53
2010-12-15 105
2010-12-16 32
2010-12-17 31
2011-01-11 9
2011-01-17 1
2011-02-01 5
2011-02-03 2
2011-02-08 6
2011-02-10 28
2011-02-15 7
2011-02-17 5
2011-02-22 33
2011-02-24 20
2011-03-10 23
2011-03-11 2
2011-03-14 10
2011-03-15 30
2011-03-21 16
2011-03-22 8
2011-03-28 8
2011-03-29 13
2011-04-04 8
2011-04-05 90
2011-04-11 17
2011-04-12 29
2011-04-14 55
2011-04-26 18
2011-04-28 2
2011-05-02 24
2011-05-03 5
2011-05-05 15
2011-05-09 1
2011-05-10 2
2011-05-19 15
2011-05-23 22
2011-05-24 14
2011-05-26 17
2011-05-27 10
2011-05-30 6
2011-05-31 19
2011-06-06 27
2011-06-07 36
2011-06-08 22
2011-06-09 72
2011-06-10 12
2011-06-14 112
2011-06-15 36
2011-06-17 213
2011-10-05 13
2011-10-11 2
2011-10-12 4
2011-10-27 3
2011-11-10 33
2011-11-11 6
2011-11-15 5
2011-11-17 5
2011-11-18 12
2011-11-22 9
2011-11-25 212
2011-11-28 12
2011-11-29 10
2011-12-01 39
2011-12-02 12
2011-12-05 46
2011-12-06 46
2011-12-07 128
2011-12-08 35
2011-12-09 44
2011-12-12 78
2011-12-13 59
2011-12-14 72
2011-12-15 80
2011-12-16 17
2011-12-19 36
2011-12-20 25
2012-01-09 23
2012-01-10 3
2012-01-12 6
2012-01-31 8
2012-02-07 25
2012-02-09 5
2012-02-16 6
2012-02-28 3
2012-03-01 79
2012-03-06 2
2012-03-08 27
2012-03-19 30
2012-03-20 23
2012-03-22 20
2012-03-26 8
2012-03-27 7
2012-03-29 41
2012-04-12 29
2012-04-16 2
2012-04-17 2
2012-04-24 2
2012-04-26 2
2012-05-03 22
2012-05-07 11
2012-05-08 4
2012-05-10 22
2012-05-14 8
2012-05-15 26
2012-05-21 16
2012-05-22 6
2012-05-24 18
2012-05-29 19
2012-05-30 3
2012-05-31 29
2012-06-04 26
2012-06-05 27
2012-06-06 7
2012-06-07 54
2012-06-12 191
2012-06-13 30
2012-06-14 75
2012-06-15 79
2012-10-05 269
2012-10-09 8
2012-10-11 8
2012-10-16 9
2012-10-25 11
2012-11-08 7
2012-11-15 230
2012-11-20 31
2012-11-22 17
2012-11-28 419
2012-11-29 66
2012-11-30 13
2012-12-04 48
2012-12-05 71
2012-12-06 211
2012-12-07 53
2012-12-10 78
2012-12-11 110
2012-12-12 54
2012-12-13 87
2012-12-14 36
2012-12-17 42
2012-12-18 46
2013-01-10 2
2013-01-17 3
2013-01-22 18
2013-01-24 8
2013-02-05 5
2013-02-07 10
2013-02-12 24
2013-02-14 130
2013-02-19 32
2013-02-21 1
2013-03-05 4
2013-03-07 19
2013-03-18 76
2013-03-19 47
2013-03-21 78
2013-04-02 16
2013-04-04 2
2013-04-09 2
2013-04-16 9
2013-04-23 32
2013-04-29 25
2013-04-30 7
2013-05-07 14
2013-05-14 19
2013-05-16 10
2013-05-21 5
2013-05-27 46
2013-05-28 27
2013-05-30 34
2013-06-03 16
2013-06-04 67
2013-06-06 75
2013-06-07 46
2013-06-11 181
2013-06-12 13
2013-06-13 88
2013-06-14 52
2013-06-17 87
2013-06-18 89
2013-06-19 381
2013-06-20 76
2013-06-21 73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment