Skip to content

Instantly share code, notes, and snippets.

@poezn
Created November 28, 2012 02:54
Show Gist options
  • Select an option

  • Save poezn/4158743 to your computer and use it in GitHub Desktop.

Select an option

Save poezn/4158743 to your computer and use it in GitHub Desktop.
Another Inlet
{"description":"Another Inlet","endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.7,"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}
{
"population": {
"filter_matches": 63
},
"message_features": [
{
"id": "weekdays",
"label": "Weekdays",
"data": [
{
"label": "Monday",
"weight": 20
},
{
"label": "Tuesday",
"weight": 300
},
{
"label": "Wednesday",
"weight": -200
},
{
"label": "Thursday",
"weight": -445
},
{
"label": "Friday",
"weight": 200
},
{
"label": "Saturday",
"weight": -2000
},
{
"label": "Sunday",
"weight": -500
}
]
},
{
"id": "message_length",
"label": "Message Length",
"data": [
{
"label": "<20chars",
"weight": 20
},
{
"label": "20-40chars",
"weight": 300
},
{
"label": "40-60chars",
"weight": -200
},
{
"label": "60-80chars",
"weight": -445
},
{
"label": ">80chars",
"weight": 200
}
]
},
{
"id": "has_shares",
"label": "Has Shares",
"data": [
{
"weight": 20
}
]
},
{
"id": "has_exclamation_mark",
"label": "Has Exclamation Mark",
"data": [
{
"weight": 20
}
]
},
{
"id": "all_caps",
"label": "All Caps",
"data": [
{
"weight": 20
}
]
}
],
"age": [
{"age": 0,"count": 208724},
{"age": 1,"count": 210343},
{"age": 2,"count": 218748},
{"age": 3,"count": 219358},
{"age": 4,"count": 216333},
{"age": 5,"count": 214755},
{"age": 6,"count": 213117},
{"age": 7,"count": 212671},
{"age": 8,"count": 216159},
{"age": 9,"count": 223553},
{"age": 10,"count": 226247},
{"age": 11,"count": 224386},
{"age": 12,"count": 224856},
{"age": 13,"count": 226434},
{"age": 14,"count": 228924},
{"age": 15,"count": 233436},
{"age": 16,"count": 239403},
{"age": 17,"count": 244644},
{"age": 18,"count": 252316},
{"age": 19,"count": 258583},
{"age": 20,"count": 258030},
{"age": 21,"count": 248602},
{"age": 22,"count": 242776},
{"age": 23,"count": 238801},
{"age": 24,"count": 240549},
{"age": 25,"count": 241493},
{"age": 26,"count": 234206},
{"age": 27,"count": 237130},
{"age": 28,"count": 234529},
{"age": 29,"count": 231869},
{"age": 30,"count": 235967},
{"age": 31,"count": 218188},
{"age": 32,"count": 222223},
{"age": 33,"count": 217361},
{"age": 34,"count": 216579},
{"age": 35,"count": 224195},
{"age": 36,"count": 220091},
{"age": 37,"count": 231703},
{"age": 38,"count": 245110},
{"age": 39,"count": 257368},
{"age": 40,"count": 258397},
{"age": 41,"count": 242529},
{"age": 42,"count": 243647},
{"age": 43,"count": 249726},
{"age": 44,"count": 258488},
{"age": 45,"count": 279371},
{"age": 46,"count": 281099},
{"age": 47,"count": 280373},
{"age": 48,"count": 278886},
{"age": 49,"count": 281473},
{"age": 50,"count": 281752},
{"age": 51,"count": 268739},
{"age": 52,"count": 269545},
{"age": 53,"count": 263182},
{"age": 54,"count": 257073},
{"age": 55,"count": 255079},
{"age": 56,"count": 244935},
{"age": 57,"count": 239387},
{"age": 58,"count": 234036},
{"age": 59,"count": 228981},
{"age": 60,"count": 229853},
{"age": 61,"count": 228898},
{"age": 62,"count": 240171},
{"age": 63,"count": 243335},
{"age": 64,"count": 192993},
{"age": 65,"count": 197758},
{"age": 66,"count": 200159},
{"age": 67,"count": 207127},
{"age": 68,"count": 182935},
{"age": 69,"count": 171254},
{"age": 70,"count": 166329},
{"age": 71,"count": 160388},
{"age": 72,"count": 154914},
{"age": 73,"count": 146374},
{"age": 74,"count": 140702},
{"age": 75,"count": 135042},
{"age": 76,"count": 122986},
{"age": 77,"count": 122678},
{"age": 78,"count": 118504},
{"age": 79,"count": 116304},
{"age": 80,"count": 110200},
{"age": 81,"count": 103346},
{"age": 82,"count": 97636},
{"age": 83,"count": 89885},
{"age": 84,"count": 80956},
{"age": 85,"count": 74349},
{"age": 86,"count": 66017},
{"age": 87,"count": 57490},
{"age": 88,"count": 50664},
{"age": 89,"count": 42362},
{"age": 90,"count": 33769},
{"age": 91,"count": 26733},
{"age": 92,"count": 21593},
{"age": 93,"count": 16515},
{"age": 94,"count": 12867},
{"age": 95,"count": 9849},
{"age": 96,"count": 6991},
{"age": 97,"count": 5107},
{"age": 98,"count": 3403},
{"age": 99,"count": 2326},
{"age": 100,"count": 3766},
{"age": 105,"count": 297},
{"age": 110,"count": 27}
]
}
var data = tb['data'];
var width = 821,
height = 307;
var x = d3.scale.linear()
.domain([
0,
100
])
.range([10, 10 + width]);
var hist = d3.layout.histogram()
.bins(function(d, i) {
return d3.range(0, 100, 5);
})
.value(function(d, i) {
return d.age;
})
(_.filter(data.age, function(d, i) {return d.age <= 100}));
_.map(hist, function(d, i) {
d.sum = d3.sum(d, function(d, i) { return d.count});
})
var y = d3.scale.linear()
.domain([0, d3.max(
hist, function(d, i) {
return d.sum;
})])
.range([height + 10, 10]);
console.log(hist);
g.selectAll('rect.bin')
.data(hist)
.enter().append('rect')
.attr({
class: 'bin',
width: function(d, i) {
console.log(d.dx, x(d.dx), d)
return (x(d.dx) - x(0));
},
height: function(d, i) {
return y(0) - y(d.sum);
},
x: function(d, i) {
return x(d.x);
},
y: function(d, i) {
return y(d.sum);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment