Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created October 23, 2013 18:17
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 enjalot/7123788 to your computer and use it in GitHub Desktop.
Save enjalot/7123788 to your computer and use it in GitHub Desktop.
html5devconf time
{"description":"html5devconf time","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"survey.csv":{"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":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/4R4ZMtU.png"}
//this is using data from twitter survey
//http://bit.ly/advd3presurvey
var results = tributary.survey;
results.forEach(function(d) {
d.evil = +d.evil;
d.passion = +d.passion;
d.age = +d.age || 0;
d.exp = +d.exp;
d.oj = d.oj.replace(/ /g, '-');
d.toothpaste = d.toothpaste.replace(/ /g, '-');
d.time = new Date(d.time);
})
//console.log(results);
var qmap = {
time: {q: "Timestamp"},
pb: {q: "What type of peanut butter do you prefer?", a: ["Crunchy", "Smooth"]},
toothpaste: {q:"Where do you squeeze the toothpaste from?", a: ["Top-of-the-tube", "Bottom-of-the-tube"]},
cv: {q:"Vanilla or Chocolate?", a: ["Chocolate", "Vanilla"]},
tp: {q:"What direction does toilet paper go on the holder thingy?", a: ["Over", "Under"]},
oj: {q:"Do you prefer pulp or no pulp in your orange juice?", a: ["Pulp", "No-pulp"]},
evil: {q:"Where do you sit on the good vs. evil scale?"},
age: {q:"How old are you?"},
passion: {q:"How passionate of a person are you?"},
exp: {q:"How many years have you been building for the web?"}
}
//time,pb,toothpaste,cv,tp,oj,evil,passion,exp,age
var questions = [
"pb", "toothpaste", "cv", "tp", "oj"
]
var field = questions[4]
results.sort(function(a,b) {
return b[field] < a[field] ? 1 : -1
})
var colorScale = d3.scale.ordinal()
.domain(qmap[field].a)
.range(["#fff", "#000"])
var extent = d3.extent(results, function(d) { return d.evil })
var linearScale = d3.scale.linear()
.domain(extent)
.range([10, 294])
var timeScale = d3.time.scale()
.domain(d3.extent(results, function(d) { return d.time }))
.range([0, 401])
var svg = d3.select("svg")
var ppl = svg.selectAll("rect.person")
.data(results)
ppl.enter().append("rect").classed("person", true)
ppl.attr({
width: 2,
height: function(d,i) { return linearScale(d.evil) },
x: function(d,i) { return 100 + timeScale(d.time) },
y: function(d,i) { return 420 - linearScale(d.evil) }
})
.style("fill-opacity", 0.5)
var format = d3.time.format("%m/%d %H:%M");
var axis = d3.svg.axis()
.scale(timeScale)
.orient("bottom") //left, right, top
.ticks(10) //best guess
.tickFormat(format)
//.tickValues([20, 25, 30]) //specify exact values
var g = svg.append("g")
axis(g)
g.attr("transform", "translate(100, 435)")
g.selectAll("path")
.style({ fill: "none", stroke: "#000"})
g.selectAll("line")
.style({ stroke: "#000"})
g.selectAll(".tick text")
.attr("transform", "rotate(45)translate(59, -10)")
var scale = d3.scale.linear()
.domain([20, 30])
.range([10, 300])
var brush = d3.svg.brush()
brush.x(timeScale)
var g = svg.append("g")
brush(g)
g.attr("transform", "translate(100, 65)")
g.selectAll("rect").attr("height", 30)
g.selectAll(".background")
.style({fill: "#4B9E9E", visibility: "visible"})
g.selectAll(".extent")
.style({fill: "#78C5C5", visibility: "visible"})
g.selectAll(".resize rect")
.style({fill: "#276C86", visibility: "visible"})
brush.on("brush", function() {
var ext = brush.extent()
ppl.style("fill", "#000")
ppl.filter(function(d,i) {
return d.time > ext[0] && d.time < ext[1]
}).style("fill", "#ff0000")
})
.legend {
float:left;
clear:left;
}
time pb toothpaste cv tp oj evil passion exp age
10/23/2013 10:31:36 Smooth Bottom Vanilla Over No pulp 2 3 10 39
10/23/2013 10:35:52 Smooth Bottom Chocolate Over Pulp 3 2 8 29
10/23/2013 10:36:33 Crunchy Top Chocolate Over Pulp 3 6 2 31
10/23/2013 10:36:33 Crunchy Bottom Chocolate Over Pulp 1 7 15 34
10/23/2013 10:36:39 Crunchy Top Chocolate Over Pulp 4 3 1 27
10/23/2013 10:36:39 Crunchy Bottom Vanilla Over Pulp 2 6 2 36
10/23/2013 10:36:43 Smooth Bottom Vanilla Over Pulp 3 3 5 23
10/23/2013 10:36:51 Smooth Bottom Vanilla Over Pulp 9 1 0 22
10/23/2013 10:36:54 Crunchy Bottom Vanilla Over Pulp 3 3 16 36
10/23/2013 10:36:55 Crunchy Bottom Chocolate Over Pulp 7 8 10 30
10/23/2013 10:37:02 Smooth Bottom Chocolate Over Pulp 10 4 15 29
10/23/2013 10:37:16 Crunchy Bottom Vanilla Over Pulp 3 5 5 35
10/23/2013 10:37:17 Smooth Bottom Vanilla Over No pulp 1 1 15 39
10/23/2013 10:37:18 Crunchy Top Chocolate Over Pulp 3 3 13 32
10/23/2013 10:37:23 Smooth Bottom Chocolate Over Pulp 2 3 16 43
10/23/2013 10:37:23 Crunchy Top Chocolate Over Pulp 4 4 5 25
10/23/2013 10:37:28 Crunchy Bottom Vanilla Over No pulp 4 3 13 28
10/23/2013 10:37:29 Smooth Bottom Chocolate Over Pulp 3 3 3 24
10/23/2013 10:37:31 Crunchy Bottom Chocolate Over Pulp 7 5 15 38
10/23/2013 10:37:38 Smooth Bottom Chocolate Over Pulp 8 6 9 37
10/23/2013 10:37:38 Crunchy Bottom Chocolate Over Pulp 4 3 4 24
10/23/2013 10:37:38 Crunchy Bottom Vanilla Over No pulp 4 5 11 26
10/23/2013 10:37:41 Smooth Top Chocolate Over Pulp 3 1 5 26
10/23/2013 10:37:44 Crunchy Bottom Chocolate Over Pulp 5 6 10 34
10/23/2013 10:37:55 Crunchy Top Chocolate Over Pulp 3 2 10 27
10/23/2013 10:38:00 Smooth Bottom Chocolate Over No pulp 3 2 8 37
10/23/2013 10:38:13 Smooth Bottom Chocolate Over Pulp 1 2 13 27
10/23/2013 10:38:16 Crunchy Bottom Vanilla Under No pulp 3 3 12 40
10/23/2013 10:38:19 Crunchy Bottom Vanilla Over No pulp 5 3 12 29
10/23/2013 10:38:21 Crunchy Top Vanilla Over Pulp 3 3 0 32
10/23/2013 10:38:30 Smooth Bottom Vanilla Over Pulp 2 1 15 23
10/23/2013 10:38:34 Crunchy Top Chocolate Over Pulp 1 8 10 50
10/23/2013 10:38:42 Crunchy Bottom Chocolate Over Pulp 3 4 5 45
10/23/2013 10:38:55 Crunchy Bottom Vanilla Over Pulp 6 5 3 30
10/23/2013 10:39:14 Smooth Bottom Vanilla Over No pulp 6 7 6 35
10/23/2013 10:39:15 Crunchy Top Chocolate Over Pulp 3 2 20 53
10/23/2013 10:39:18 Crunchy Bottom Chocolate Over Pulp 1 1 1 22
10/23/2013 10:39:30 Crunchy Top Vanilla Over Pulp 3 6 1 22
10/23/2013 10:39:44 Crunchy Bottom Chocolate Over Pulp 2 5 18 42
10/23/2013 10:39:46 Smooth Bottom Chocolate Over No pulp 7 1 1 36
10/23/2013 10:39:51 Crunchy Bottom Vanilla Over Pulp 1 1 20 63
10/23/2013 10:39:55 Smooth Bottom Vanilla Over No pulp 3 3 2 24
10/23/2013 10:39:55 Smooth Top Chocolate Over No pulp 3 6 4 26
10/23/2013 10:39:56 Smooth Bottom Chocolate Under Pulp 8 1 15 34
10/23/2013 10:40:07 Crunchy Bottom Chocolate Over Pulp 3 4 15 42
10/23/2013 10:40:23 Crunchy Bottom Vanilla Over No pulp 8 3 6 32
10/23/2013 10:40:24 Crunchy Bottom Chocolate Over Pulp 1 5 10
10/23/2013 10:40:24 Smooth Top Chocolate Over No pulp 3 3 10
10/23/2013 10:40:25 Crunchy Top Chocolate Over Pulp 5 1 12 35
10/23/2013 10:40:25 Crunchy Top Chocolate Under No pulp 5 1 10 40
10/23/2013 10:40:28 Smooth Top Vanilla Over No pulp 7 2 9 27
10/23/2013 10:40:41 Smooth Top Vanilla Over Pulp 3 4 7 22
10/23/2013 10:41:30 Smooth Bottom Vanilla Over Pulp 4 6 4 43
10/23/2013 10:42:58 Smooth Bottom Vanilla Over No pulp 2 6 13
10/23/2013 10:43:30 Smooth Top Chocolate Over Pulp 7 2 5 47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment