[ Launch: crossfilter for stoners ] 4700608 by enjalot
-
-
Save enjalot/4700608 to your computer and use it in GitHub Desktop.
crossfilter for stoners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"crossfilter for stoners","endpoint":"","display":"svg","public":true,"require":[{"name":"crossfilter (custom-filter)","url":"https://raw.github.com/enjalot/crossfilter/master/crossfilter.min.js"}],"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}},"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,"fullscreen":false,"thumbnail":"http://i.imgur.com/Snp6TV5.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select("svg"); | |
var xf = crossfilter(); | |
var visits = xf.dimension(function(d) { return d.visits }); | |
var forks = xf.dimension(function(d) { return d.nforks }); | |
var users = xf.dimension(function(d) { | |
if(!d.user) { | |
return "anon"; | |
} | |
return d.user.login | |
}); | |
var time = xf.dimension(function(d) { return new Date(d.createdAt) }); | |
var start = d3.time.day.offset(new Date(), -14); | |
var end = d3.time.day.offset(new Date(), 0); | |
function initData() { | |
xf.add(tributary.inlets); | |
//console.log(tributary.inlets[10]); | |
tributary.inlets.forEach(function(d) { | |
if(d.nforks > 0) { | |
console.log(d.forks); | |
} | |
}) | |
} | |
function render() { | |
//visits.filter([2, 342]) | |
//forks.filter([3, 15]) | |
time.filter([start, end]); | |
var userGroup = users.group().all().sort(function(a,b) { | |
return a.value < b.value ? 1 : -1 | |
}); | |
var barWidth = d3.scale.linear() | |
.domain(d3.extent(userGroup, function(d) { return d.value })) | |
.range([1, 200]); | |
var userSel = svg.selectAll("g.user") | |
.data(userGroup); | |
userSel.exit().remove(); | |
var userEnter = userSel.enter() | |
.append("g") | |
.classed("user", true); | |
userEnter.append("text").classed("name", true); | |
userEnter.append("rect"); | |
userEnter.append("text").classed("number", true); | |
userSel.attr({ | |
"transform": function(d,i) { | |
var x = 172; | |
var y = 36 + i * 22; | |
return "translate(" + [x,y] + ")"; | |
} | |
}) | |
userSel.select("text.name") | |
.text(function(d) { return d.key }) | |
.attr("alignment-baseline", "hanging") | |
.attr("y", 3) | |
userSel.select("rect") | |
.attr({ | |
width: function(d) { return barWidth(d.value) }, | |
height: 20, | |
x: 5 | |
}) | |
userSel.select("text.number") | |
.text(function(d) { return d.value }) | |
.attr("alignment-baseline", "hanging") | |
.attr("x", function(d) { return 9 + barWidth(d.value) }) | |
.attr("y", 3) | |
} | |
if(!tributary.inlets) { | |
d3.json("http://tributary.io/api/latest/created", function(err, response) { | |
tributary.inlets = response; | |
initData(); | |
render(); | |
}) | |
} else { | |
initData(); | |
render(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.user text { | |
alignment-baseline: hanging; | |
} | |
text.name { | |
text-anchor: end; | |
} | |
.user rect { | |
fill: #62AACC; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment