runet-censorship-bypass/pac-performance-analyses/chart/src/index.html
2016-05-08 21:14:08 +05:00

182 lines
4.2 KiB
HTML
Executable File

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 12px Tahoma;
}
.y.axisRight text {
fill: orange;
}
.y.axisLeft text {
fill: steelblue;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.timeMiss {
fill: red;
}
.memMiss {
fill: blue;
}
.timeHit {
fill: orange;
}
.memHit {
fill: steelblue;
}
.x.axis path {
display: none;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 80, right: 80, bottom: 80, left: 80},
width = 1000 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y0 = d3.scale.linear().domain([0, 400]).range([height, 0]);
var y1 = d3.scale.linear().domain([0, 6000000]).range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
// create left yAxis
var yAxisLeft = d3.svg.axis().scale(y0).ticks(4).orient("left");
// create right yAxis
var yAxisRight = d3.svg.axis().scale(y1).ticks(6).orient("right");
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("class", "graph")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
function type(d) {
d.memMiss = +d.memMiss;
return d;
}
d3.tsv("data.tsv", type, function(error, data) {
x.domain(data.map( d => d.approach ));
//y0.domain([0, d3.max(data, d => Math.max(d.memHit, d.memMiss) )]);
//y1.domain([0, d3.max(data, d => Math.max(d.timeHit, d.timeMiss) )]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis axisLeft")
.attr("transform", "translate(0,0)")
.call(yAxisLeft)
.append("text")
.attr("y", 6)
.attr("dy", "-2em")
.attr("dx", "-2em")
.style("text-anchor", "right")
.text("bytes per request");
svg.append("g")
.attr("class", "y axis axisRight")
.attr("transform", "translate(" + (width) + ",0)")
.call(yAxisRight)
.append("text")
.attr("y", 6)
.attr("dy", "-2em")
.attr("dx", "-1em")
.style("text-anchor", "start")
.text("ns per request");
bars = svg.selectAll(".bar").data(data).enter();
bars.append("rect")
.attr("class", "memHit")
.attr("width", x.rangeBand()*0.25*0.5 )
.attr("x", d => x(d.approach) + x.rangeBand()*0.25 )
.attr("y", d => y0(d.memHit) )
.attr("height", (d,i,j) => height - y0(d.memHit) );
bars.append("rect")
.attr("class", "timeHit")
.attr("x", d => x(d.approach) + x.rangeBand()*0.25*1.5 )
.attr("width", x.rangeBand()*0.25*0.5 )
.attr("y", d => y1(d.timeHit) )
.attr("height", (d,i,j) => height - y1(d.timeHit) );
bars.append("rect")
.attr("class", "memMiss")
.attr("x", d => x(d.approach) + x.rangeBand()*0.25*2 )
.attr("width", x.rangeBand()*0.25*0.5 )
.attr("y", d => y0(d.memMiss) )
.attr("height", (d,i,j) => height - y0(d.memMiss) );
bars.append("rect")
.attr("class", "timeMiss")
.attr("x", d => x(d.approach) + x.rangeBand()*0.25*2.5 )
.attr("width", x.rangeBand()*0.25*0.5 )
.attr("y", d => y1(d.timeMiss) )
.attr("height", (d,i,j) => height - y1(d.timeMiss) );
// add legend
var color_hash = {
0 : ["Time / Miss", "red"],
1 : ["Memory / Miss", "blue"],
2 : ["Time / Hit", "orange"],
3 : ["Memory / Hit", "steelblue"]
}
var legend = svg.append("g")
.attr("class", "legend")
.attr("x", width - 65)
.attr("y", 25)
.attr("height", 100)
.attr("width", 100);
legend.selectAll('g')
.data(data)
.enter()
.append('g')
.each(function(d, i) {
if(i > 3)
return; // Approach.
var g = d3.select(this);
g.append("rect")
.attr("x", width - x.rangeBand()*3.5 - 15)
.attr("y", i*25)
.attr("width", 10)
.attr("height", 10)
.style("fill", color_hash[i][1]);
g.append("text")
.attr("x", width - x.rangeBand()*3.5)
.attr("y", i * 25 + 8)
.attr("height",30)
.attr("width",100)
.style("fill", color_hash[i][1])
.text(color_hash[i][0]);
});
});
</script>