xxxxxxxxxx
<meta charset="utf-8">
<style>
body {
font: 12px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.line {
fill: none;
stroke: #bbb;
stroke-width: 1px;
opacity: .5;
}
.line.active {
stroke-width: 5px;
stroke: #444;
opacity: 1;
}
.quantile {
fill: green;
stroke: green;
}
.median {
fill: red;
stroke: red;
}
.info {
background-color: #D9EDF7;
border-color: #BCE8F1;
color: #3A87AD;
border: 1px solid rgba(0, 0, 0, 0);
border-radius: 4px;
margin-bottom: 20px;
padding: 15px;
position:absolute;
top:0;
left: 90px;
max-width: 350px;
}
</style>
<div id="chart"></div>
<div class="info">
Movement of <a href="https://volebnikalkulacka.cz">Volební kalkulačka</a>'s users between questions (sample of about 1000 weekend users, 2014-05-09 18:43:56 - 2014-05-11 16:42:11); 1st attempt only when multiple attempts.
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.6/d3.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.linear()
.range([0, width])
.domain([0,32]);
var y = d3.scale.linear()
.range([height, 0])
.domain([0,900]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("x", x(31))
.attr("dx", ".71em")
.style("text-anchor", "end")
.text("Question");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Time (seconds)");
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + width + ",0)")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Time (seconds)");
var line = d3.svg.line()
.x(function(d) { return x(d[1]); })
.y(function(d) { return y(d[0]); });
d3.json("page.json", function(error, data) {
i = 0;
pdata = [];
p30data = [];
$.each(data, function(index, d) {
if (i > 0 & i < 1100) {
svg.append("path")
.datum(d)
.attr("d",line)
.attr("class","line")
.attr("title",d.name)
.on("mouseover", function() {
d3.select(this)
.classed("active", true )
})
.on("mouseout", function() {
d3.select(this)
.classed("active", false)
});
pdata.push(d[d.length-1]);
}
$.each(d, function (ii,dd) {
if (dd[1] == 30)
p30data.push(dd[0]);
});
i++;
});
qd = [];
md = [];
md.push([d3.quantile(p30data.sort(function(a, b){return a-b}),0.5),30]);
qd.push([d3.quantile(p30data.sort(function(a, b){return a-b}),0.75),30]);
qd.push([d3.quantile(p30data.sort(function(a, b){return a-b}),0.25),30]);
svg.selectAll('.ends')
.data(pdata)
.enter().append('circle')
.attr("cx", function(d) {return x(d[1]) })
.attr("cy", function(d) {return y(d[0]) })
.attr("r", 1)
svg.selectAll('.quantile')
.data(qd)
.enter().append('circle')
.attr("cx", function(d) {return x(d[1]) })
.attr("cy", function(d) {return y(d[0]) })
.attr("class","quantile")
.attr("r", 4)
svg.selectAll('.median')
.data(md)
.enter().append('circle')
.attr("cx", function(d) {return x(d[1]) })
.attr("cy", function(d) {return y(d[0]) })
.attr("class","median")
.attr("r", 6)
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-8592359-13', 'ocks.org');
ga('send', 'pageview');
</script>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.6/d3.min.js
https://code.jquery.com/jquery-1.11.1.min.js