runet-censorship-bypass/pac-performance-analyses/chart/src/index.html

182 lines
4.2 KiB
HTML
Raw Normal View History

2015-11-28 15:45:28 +03:00
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
2015-11-28 16:04:33 +03:00
font: 12px Tahoma;
2015-11-28 15:45:28 +03:00
}
.y.axisRight text {
fill: orange;
}
.y.axisLeft text {
fill: steelblue;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.timeMiss {
2015-11-28 16:04:33 +03:00
fill: red;
2015-11-28 15:45:28 +03:00
}
.memMiss {
2015-11-28 16:04:33 +03:00
fill: blue;
2015-11-28 15:45:28 +03:00
}
.timeHit {
2015-11-28 16:04:33 +03:00
fill: orange;
2015-11-28 15:45:28 +03:00
}
.memHit {
2015-11-28 16:04:33 +03:00
fill: steelblue;
2015-11-28 15:45:28 +03:00
}
.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")
2015-11-28 16:04:33 +03:00
.attr("dx", "-2em")
.style("text-anchor", "right")
2015-11-28 15:45:28 +03:00
.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")
2015-11-28 16:04:33 +03:00
.attr("dx", "-1em")
.style("text-anchor", "start")
2015-11-28 15:45:28 +03:00
.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
2015-11-28 16:04:33 +03:00
var color_hash = {
0 : ["Time / Miss", "red"],
1 : ["Memory / Miss", "blue"],
2 : ["Time / Hit", "orange"],
3 : ["Memory / Hit", "steelblue"]
}
2015-11-28 15:45:28 +03:00
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")
2015-11-28 16:04:33 +03:00
.attr("x", width - x.rangeBand()*3.5 - 15)
2015-11-28 15:45:28 +03:00
.attr("y", i*25)
.attr("width", 10)
.attr("height", 10)
.style("fill", color_hash[i][1]);
g.append("text")
2015-11-28 16:04:33 +03:00
.attr("x", width - x.rangeBand()*3.5)
2015-11-28 15:45:28 +03:00
.attr("y", i * 25 + 8)
.attr("height",30)
.attr("width",100)
.style("fill", color_hash[i][1])
.text(color_hash[i][0]);
});
});
</script>