Skip to content

Instantly share code, notes, and snippets.

@soyeonjeong
Last active June 4, 2018 16:33
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 soyeonjeong/e45f5d3fe4dc47dd9affdded11c29dce to your computer and use it in GitHub Desktop.
Save soyeonjeong/e45f5d3fe4dc47dd9affdded11c29dce to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<body>
<h1>Press Conferences</h1>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var width = 960,
height = 136,
cellSize = 17;
// var color = d3.scaleQuantize()
// .domain([-0.05, 0.05])
// .range(["purple", "grey"]);
var svg = d3.select("body")
.selectAll("svg")
.data(d3.range(2017, 2011, -1))
.enter().append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");
var g = svg.append("g")
g.append("text")
.attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("text-anchor", "middle")
.text(function(d) { return d; });
// var days = ["S", "M", "T", "W", "T", "F", "S"];
var rect = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#ccc")
.selectAll("rect")
.data(function(d) { return d3.timeDays(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("rect")
.attr("width", cellSize)
.attr("height", cellSize)
.attr("x", function(d) { return d3.timeWeek.count(d3.timeYear(d), d) * cellSize; })
.attr("y", function(d) { return d.getDay() * cellSize; })
.datum(d3.timeFormat("%Y-%m-%d"));
// rect.append("text")
// .text(function(d, i))
var month = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#000")
.selectAll("path")
.data(function(d) { return d3.timeMonths(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("path")
.attr("d", pathMonth);
var listMonths = ["JAN.", "FEB.", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUG.", "SEPT.", "OCT.", "NOV.", "DEC."];
month.append("text")
// .text(listMonths.forEach(function(d, i) {
// return listMonths[i];
// }))
d3.tsv("pc-dates.tsv", function(error, data) {
if (error) throw error;
var parseTime = d3.timeParse("%m/%d/%y");
var formatTime = d3.timeFormat("%Y-%m-%d");
data.forEach(function(d) {
d.parsed = parseTime(d.date_c);
d.formatted = formatTime(d.parsed);
});
console.log(data)
var data = d3.nest()
.key(function(d) { return d.formatted; })
.object(data);
rect.filter(function(d) { return d in data; })
.attr("fill", "lightgrey")
});
function pathMonth(t0) {
var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
d0 = t0.getDay(), w0 = d3.timeWeek.count(d3.timeYear(t0), t0),
d1 = t1.getDay(), w1 = d3.timeWeek.count(d3.timeYear(t1), 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";
}
</script>
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
date_c
6/6/17
4/27/17
4/26/17
4/25/17
4/24/17
4/13/17
4/11/17
3/23/17
3/21/17
3/20/17
3/16/17
3/15/17
3/14/17
3/13/17
3/9/17
3/8/17
3/7/17
1/19/17
1/17/17
1/13/17
1/12/17
1/10/17
1/9/17
1/6/17
1/4/17
1/3/17
12/27/16
12/22/16
12/21/16
12/20/16
12/19/16
12/15/16
12/14/16
12/13/16
12/12/16
12/9/16
12/8/16
12/7/16
12/6/16
12/5/16
12/2/16
12/1/16
11/30/16
11/29/16
11/28/16
11/22/16
11/21/16
11/18/16
11/17/16
11/16/16
11/15/16
11/14/16
11/10/16
11/9/16
11/7/16
11/4/16
11/3/16
11/2/16
11/1/16
10/31/16
10/28/16
10/27/16
10/26/16
10/25/16
10/24/16
10/21/16
10/20/16
10/18/16
10/17/16
10/14/16
10/13/16
10/12/16
10/11/16
10/7/16
10/6/16
10/5/16
10/4/16
10/3/16
9/30/16
9/29/16
9/28/16
9/27/16
9/26/16
9/16/16
9/15/16
9/14/16
9/13/16
9/12/16
9/9/16
9/8/16
9/7/16
9/6/16
9/1/16
8/31/16
8/30/16
8/29/16
8/25/16
8/24/16
8/23/16
8/22/16
8/18/16
8/17/16
8/16/16
8/15/16
8/11/16
8/10/16
8/9/16
8/8/16
8/4/16
8/3/16
8/2/16
7/29/16
7/28/16
7/27/16
7/26/16
7/25/16
7/22/16
7/21/16
7/19/16
7/18/16
7/15/16
7/14/16
7/13/16
7/12/16
7/11/16
7/8/16
7/7/16
7/6/16
7/5/16
7/1/16
6/30/16
6/29/16
6/28/16
6/27/16
6/24/16
6/23/16
6/22/16
6/21/16
6/20/16
6/17/16
6/16/16
6/15/16
6/14/16
6/13/16
6/10/16
6/9/16
6/8/16
6/7/16
6/6/16
6/3/16
6/2/16
6/1/16
5/31/16
5/27/16
5/26/16
5/25/16
5/24/16
5/23/16
5/19/16
5/18/16
5/17/16
5/16/16
5/13/16
5/12/16
5/11/16
5/10/16
5/9/16
5/6/16
5/5/16
5/4/16
5/3/16
5/2/16
4/29/16
4/28/16
4/27/16
4/26/16
4/25/16
4/22/16
4/21/16
4/20/16
4/19/16
4/18/16
4/15/16
4/14/16
4/12/16
4/11/16
4/8/16
4/7/16
4/6/16
4/5/16
4/4/16
4/1/16
3/30/16
3/29/16
3/28/16
3/24/16
3/23/16
3/22/16
3/21/16
3/18/16
3/17/16
3/16/16
3/15/16
3/14/16
3/11/16
3/10/16
3/9/16
3/8/16
3/7/16
3/4/16
3/3/16
3/2/16
3/1/16
2/29/16
2/26/16
2/22/16
2/19/16
2/18/16
2/17/16
2/16/16
2/12/16
2/11/16
2/10/16
2/9/16
2/8/16
2/5/16
2/4/16
2/3/16
2/2/16
2/1/16
1/29/16
1/28/16
1/27/16
1/21/16
1/20/16
1/19/16
1/15/16
1/14/16
1/13/16
1/11/16
1/8/16
1/7/16
1/6/16
1/5/16
1/4/16
12/29/15
12/28/15
12/22/15
12/21/15
12/17/15
12/16/15
12/15/15
12/14/15
12/11/15
12/10/15
12/9/15
12/8/15
12/7/15
12/4/15
12/3/15
12/2/15
12/1/15
11/30/15
11/24/15
11/23/15
11/20/15
11/19/15
11/18/15
11/17/15
11/16/15
11/13/15
11/10/15
11/9/15
11/6/15
11/5/15
11/4/15
11/3/15
11/2/15
10/30/15
10/29/15
10/28/15
10/27/15
10/26/15
10/23/15
10/22/15
10/21/15
10/20/15
10/19/15
10/16/15
10/15/15
10/14/15
10/13/15
10/9/15
10/8/15
10/7/15
10/6/15
10/5/15
9/24/15
9/22/15
9/21/15
9/18/15
9/17/15
9/16/15
9/15/15
9/14/15
9/11/15
9/10/15
9/9/15
9/8/15
9/3/15
9/1/15
8/31/15
8/27/15
8/26/15
8/25/15
8/24/15
8/20/15
8/19/15
8/18/15
8/17/15
8/13/15
8/12/15
8/11/15
8/10/15
8/6/15
8/5/15
8/4/15
8/3/15
7/31/15
7/30/15
7/27/15
7/24/15
7/22/15
7/21/15
7/17/15
7/16/15
7/15/15
7/13/15
7/10/15
7/9/15
7/8/15
7/7/15
7/6/15
7/2/15
7/1/15
6/30/15
6/29/15
6/26/15
6/25/15
6/23/15
6/22/15
6/19/15
6/18/15
6/17/15
6/16/15
6/15/15
6/12/15
6/11/15
6/10/15
6/9/15
6/8/15
6/5/15
6/4/15
6/3/15
6/2/15
6/1/15
5/29/15
5/28/15
5/27/15
5/26/15
5/22/15
5/21/15
5/20/15
5/19/15
5/18/15
5/15/15
5/14/15
5/13/15
5/12/15
5/11/15
5/8/15
5/7/15
5/6/15
5/5/15
5/4/15
5/1/15
4/30/15
4/29/15
4/28/15
4/27/15
4/24/15
4/23/15
4/22/15
4/21/15
4/20/15
4/17/15
4/16/15
4/15/15
4/14/15
4/13/15
4/10/15
4/9/15
4/8/15
4/7/15
4/6/15
4/3/15
3/30/15
3/27/15
3/26/15
3/25/15
3/24/15
3/23/15
3/20/15
3/19/15
3/18/15
3/17/15
3/16/15
3/13/15
3/12/15
3/10/15
3/9/15
3/6/15
3/4/15
3/3/15
3/2/15
2/27/15
2/26/15
2/23/15
2/20/15
2/19/15
2/18/15
2/17/15
2/13/15
2/12/15
2/11/15
2/10/15
2/9/15
2/6/15
2/5/15
2/4/15
2/2/15
1/30/15
1/26/15
1/23/15
1/22/15
1/21/15
1/16/15
1/15/15
1/14/15
1/13/15
1/12/15
1/9/15
1/8/15
1/7/15
1/6/15
1/5/15
12/30/14
12/23/14
12/22/14
12/19/14
12/18/14
12/17/14
12/16/14
12/12/14
12/11/14
12/10/14
12/8/14
12/5/14
12/4/14
12/3/14
12/2/14
12/1/14
11/25/14
11/24/14
11/21/14
11/20/14
11/19/14
11/18/14
11/17/14
11/14/14
11/13/14
11/12/14
11/10/14
11/7/14
11/6/14
11/4/14
11/3/14
10/31/14
10/30/14
10/29/14
10/28/14
10/27/14
10/24/14
10/23/14
10/22/14
10/21/14
10/20/14
10/17/14
10/16/14
10/15/14
10/14/14
10/10/14
10/9/14
10/8/14
10/7/14
10/6/14
10/3/14
10/2/14
10/1/14
9/30/14
9/29/14
9/19/14
9/16/14
9/15/14
9/12/14
9/11/14
9/10/14
9/9/14
9/8/14
9/5/14
9/4/14
9/3/14
9/2/14
8/28/14
8/27/14
8/26/14
8/25/14
8/21/14
8/20/14
8/19/14
8/18/14
8/14/14
8/13/14
8/11/14
8/11/14
8/8/14
8/7/14
8/5/14
8/4/14
7/31/14
7/30/14
7/29/14
7/28/14
7/25/14
7/24/14
7/23/14
7/22/14
7/21/14
7/18/14
7/17/14
7/16/14
7/15/14
7/10/14
7/9/14
7/8/14
7/7/14
7/2/14
7/1/14
6/30/14
6/27/14
6/26/14
6/25/14
6/24/14
6/23/14
6/20/14
6/18/14
6/17/14
6/16/14
6/13/14
6/12/14
6/11/14
6/10/14
6/9/14
6/6/14
6/5/14
6/4/14
6/3/14
6/2/14
5/30/14
5/29/14
5/27/14
5/23/14
5/22/14
5/21/14
5/20/14
5/19/14
5/15/14
5/13/14
5/12/14
5/9/14
5/8/14
5/7/14
5/6/14
5/5/14
5/2/14
5/1/14
4/30/14
4/29/14
4/28/14
4/25/14
4/24/14
4/23/14
4/22/14
4/21/14
4/18/14
4/17/14
4/16/14
4/15/14
4/14/14
4/11/14
4/10/14
4/9/14
4/7/14
4/4/14
4/3/14
4/2/14
4/1/14
3/31/14
3/28/14
3/27/14
3/26/14
3/25/14
3/24/14
3/21/14
3/20/14
3/19/14
3/18/14
3/17/14
3/14/14
3/11/14
3/10/14
3/7/14
3/6/14
3/5/14
3/4/14
3/3/14
2/28/14
2/27/14
2/26/14
2/25/14
2/24/14
2/21/14
2/19/14
2/14/14
2/13/14
2/12/14
2/11/14
2/10/14
2/7/14
2/6/14
2/5/14
2/4/14
2/3/14
1/31/14
1/30/14
1/29/14
1/27/14
1/24/14
1/23/14
1/22/14
1/21/14
1/16/14
1/15/14
1/14/14
1/14/14
1/13/14
1/10/14
1/9/14
1/8/14
1/7/14
1/6/14
1/3/14
1/2/14
12/30/13
12/20/13
12/19/13
12/18/13
12/17/13
12/16/13
12/13/13
12/12/13
12/11/13
12/9/13
12/5/13
12/5/13
12/4/13
12/3/13
12/2/13
11/27/13
11/26/13
11/22/13
11/21/13
11/20/13
11/19/13
11/18/13
11/15/13
11/14/13
11/13/13
11/12/13
11/5/13
11/4/13
11/1/13
10/31/13
10/30/13
10/29/13
10/28/13
10/25/13
10/24/13
10/23/13
10/22/13
10/21/13
10/18/13
10/17/13
10/16/13
10/15/13
10/11/13
10/10/13
10/9/13
10/8/13
10/7/13
10/4/13
10/3/13
10/2/13
10/1/13
9/30/13
9/20/13
9/19/13
9/18/13
9/17/13
9/16/13
9/13/13
9/12/13
9/11/13
9/9/13
9/6/13
9/5/13
8/29/13
8/28/13
8/27/13
8/26/13
8/22/13
8/21/13
8/20/13
8/19/13
8/15/13
8/14/13
8/13/13
8/12/13
8/8/13
8/7/13
8/6/13
8/5/13
8/1/13
7/31/13
7/30/13
7/29/13
7/26/13
7/25/13
7/24/13
7/23/13
7/22/13
7/19/13
7/18/13
7/17/13
7/16/13
7/15/13
7/12/13
7/11/13
7/10/13
7/9/13
7/8/13
7/3/13
7/2/13
7/1/13
6/28/13
6/27/13
6/26/13
6/25/13
6/24/13
6/21/13
6/20/13
6/19/13
6/18/13
6/17/13
6/14/13
6/13/13
6/12/13
6/11/13
6/10/13
6/7/13
6/6/13
6/5/13
6/4/13
6/3/13
5/31/13
5/30/13
5/29/13
5/28/13
5/23/13
5/22/13
5/20/13
5/17/13
5/16/13
5/15/13
5/14/13
5/13/13
5/10/13
5/9/13
5/8/13
5/6/13
5/3/13
5/2/13
5/1/13
4/30/13
4/29/13
4/26/13
4/25/13
4/24/13
4/23/13
4/22/13
4/16/13
4/15/13
4/12/13
4/10/13
4/9/13
4/8/13
4/5/13
4/4/13
4/3/13
4/2/13
4/1/13
3/28/13
3/27/13
3/26/13
3/25/13
3/22/13
3/19/13
3/18/13
3/15/13
3/14/13
3/13/13
3/12/13
3/11/13
3/8/13
3/7/13
3/5/13
3/4/13
3/1/13
2/28/13
2/27/13
2/26/13
2/25/13
2/22/13
2/21/13
2/19/13
2/15/13
2/14/13
2/13/13
2/12/13
2/11/13
2/8/13
2/7/13
2/6/13
2/5/13
2/4/13
2/1/13
1/30/13
1/28/13
1/25/13
1/22/13
1/18/13
1/17/13
1/16/13
1/15/13
1/14/13
1/11/13
1/10/13
1/9/13
1/8/13
1/7/13
1/4/13
1/3/13
1/2/13
12/21/12
12/18/12
12/17/12
12/14/12
12/13/12
12/12/12
12/11/12
12/10/12
12/7/12
12/6/12
12/5/12
12/4/12
12/3/12
11/30/12
11/29/12
11/28/12
11/27/12
11/26/12
11/21/12
11/20/12
11/19/12
11/16/12
11/15/12
11/13/12
11/9/12
11/8/12
11/7/12
11/5/12
11/2/12
11/1/12
10/31/12
10/26/12
10/25/12
10/24/12
10/23/12
10/22/12
10/19/12
10/18/12
10/17/12
10/15/12
10/12/12
10/11/12
10/9/12
10/5/12
10/4/12
10/3/12
10/2/12
10/1/12
9/21/12
9/20/12
9/19/12
9/18/12
9/17/12
9/14/12
9/13/12
9/11/12
9/10/12
9/7/12
9/6/12
9/5/12
9/4/12
8/30/12
8/29/12
8/28/12
8/27/12
8/23/12
8/22/12
8/21/12
8/20/12
8/16/12
8/15/12
8/14/12
8/13/12
8/9/12
8/8/12
8/7/12
8/6/12
8/2/12
8/1/12
7/31/12
7/30/12
7/26/12
7/25/12
7/24/12
7/23/12
7/19/12
7/18/12
7/17/12
7/16/12
7/12/12
7/11/12
7/10/12
7/9/12
7/5/12
7/3/12
7/2/12
6/28/12
6/27/12
6/26/12
6/25/12
6/22/12
6/21/12
6/20/12
6/19/12
6/18/12
6/15/12
6/14/12
6/13/12
6/12/12
6/11/12
6/8/12
6/7/12
6/6/12
6/5/12
6/4/12
6/1/12
5/31/12
5/30/12
5/29/12
5/25/12
5/24/12
5/23/12
5/22/12
5/18/12
5/17/12
5/16/12
5/15/12
5/14/12
5/11/12
5/10/12
5/9/12
5/8/12
5/7/12
5/4/12
5/3/12
5/2/12
5/1/12
4/30/12
4/27/12
4/26/12
4/25/12
4/24/12
4/23/12
4/20/12
4/19/12
4/18/12
4/17/12
4/16/12
4/13/12
4/11/12
4/10/12
4/9/12
4/5/12
4/4/12
4/3/12
4/2/12
3/30/12
3/28/12
3/28/12
3/27/12
3/26/12
3/23/12
3/22/12
3/21/12
3/20/12
3/19/12
3/16/12
3/15/12
3/14/12
3/13/12
3/12/12
3/9/12
3/8/12
3/7/12
3/5/12
3/2/12
3/1/12
2/27/12
2/24/12
2/23/12
2/22/12
2/21/12
2/17/12
2/16/12
2/15/12
2/14/12
2/13/12
2/10/12
2/9/12
2/8/12
2/7/12
2/6/12
2/3/12
2/2/12
2/1/12
1/31/12
1/30/12
1/27/12
1/26/12
1/25/12
1/24/12
1/23/12
1/20/12
1/19/12
1/18/12
1/17/12
1/13/12
1/12/12
1/11/12
1/10/12
1/9/12
1/6/12
1/5/12
1/4/12
1/3/12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment