Skip to content

Instantly share code, notes, and snippets.

@gelicia
Created July 10, 2013 17:21
Show Gist options
  • Save gelicia/5968242 to your computer and use it in GitHub Desktop.
Save gelicia/5968242 to your computer and use it in GitHub Desktop.
helping OrenBochman
{"description":"helping OrenBochman","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/YbPjUkP.png"}
var width = 960,
height = 136,
cellSize = 17; // cell size
var data =[[2001,3,27,5],[2001,3,28,7],[2001,3,30,2],[2001,4,2,1],[2001,4,4,1],[2001,4,12,1],[2001,4,18,1],[2001,4,19,1],[2001,4,25,1],[2001,5,11,1],[2001,6,4,1],[2001,8,29,1],[2001,8,30,2],[2001,9,2,1],[2001,9,6,1],[2001,9,11,3],[2001,9,12,2],[2001,9,25,1],[2001,9,28,2],[2001,9,30,2],[2001,10,1,2],[2001,10,2,1],[2001,10,3,1],[2001,10,4,8],[2001,10,5,1],[2001,10,7,1],[2001,10,9,9],[2001,10,10,5],[2001,10,11,2],[2001,10,12,1],[2001,10,13,1],[2001,10,15,3],[2001,10,16,1],[2001,10,17,3],[2001,10,18,1],[2001,10,19,2],[2001,10,20,2],[2001,10,26,5],[2001,10,27,4],[2001,10,28,1],[2001,10,29,1],[2001,11,2,1],[2001,11,5,2],[2001,11,9,1],[2001,11,14,3],[2001,11,20,1],[2001,11,27,3],[2001,11,28,2],[2001,11,29,8],[2001,11,30,5],[2001,12,4,5],[2001,12,5,1],[2001,12,6,6],[2001,12,7,32],[2001,12,8,27],[2001,12,10,20],[2001,12,11,23],[2001,12,12,5],[2001,12,13,3],[2001,12,14,1],[2001,12,19,7],[2001,12,21,2],[2001,12,24,3],[2001,12,30,21]];
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.selectAll("svg").selectAll("svg")
.data(d3.range(2001, 2002)) //todo, make it for more than one year
.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);
var data2 = d3.nest()
.key(function(d) { return new Date(d[0], d[1], d[2]); })
.rollup(function(d) { return d[3] })
.map(data);
rect.filter(function(d) { return d in data2; })
.select("title")
.text(function(d) { return d + ": " + percent(data2[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";
}
body {
padding-top: 60px;
padding-bottom: 40px;
shape-rendering: crispEdges;
}
.sidebar-nav {
padding: 9px 0;
}
@media ( max-width : 980px) { /* Enable use of floated navbar text */
.navbar-text.pull-right {
float: none;
padding-left: 5px;
padding-right: 5px;
}
}
legend {
border: none;
font-size: 95%;
padding: 0.5em;
width: auto;
margin-bottom: 1px;
line-height: 0 px;
}
fieldset {
border: 1px solid rgb(47, 111, 171);
margin: 1em 0px;
padding: 0px 1em 1em;
line-height: 1.5em;
}
.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)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment