Skip to content

Commit

Permalink
fixed labels being squished together for non-stacked graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestv committed Sep 20, 2013
1 parent b142f30 commit 84c4dfc
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions web-static/graphs.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ <h2>Memory Usage</h2>
d3.max(lines, function(line) { return d3.max(line.data, itemgetter(1)); } )
]).range([h - margin_v, margin_v]);

var y_abs = d3.scale.linear().domain([0, 1]).range([h - margin_v, margin_v]);

g.selectAll().data(lines).enter().append("svg:path")
.attr("d", function(line) {
return d3.svg.line()
Expand All @@ -301,32 +303,40 @@ <h2>Memory Usage</h2>
.style("stroke", function(line) { return line.color })
.attr("class", "plotline");

lines.sort(function(a, b) { return get_area_mean(a.data).mean > get_area_mean(b.data).mean; });

for(var i = 0; i < lines.length; ++i) {
var line = lines[i];
var stats = get_area_mean(line.data);
if(stats.mean != null) {
g.append("svg:line")
.style("stroke", line.color)
.attr("x1", w - margin_h + 3)
.attr("y1", y(stats.mean))
.attr("x2", w - margin_h + 10)
.attr("y2", y_abs(i/lines.length));
g.append("svg:text")
.text(line.label)
.attr("text-anchor", "start")
.attr("dominant-baseline", "central")
.attr("fill", line.color)
.attr("x", w - margin_h + 10)
.attr("y", y(stats.mean) - 12);
.attr("y", y_abs(i/lines.length) - 12);
g.append("svg:text")
.text("-Mean: " + d3.format(".3s")(stats.mean) + unit)
.text("Mean: " + d3.format(".3s")(stats.mean) + unit)
.attr("text-anchor", "start")
.attr("dominant-baseline", "central")
.attr("fill", line.color)
.attr("x", w - margin_h)
.attr("y", y(stats.mean));
.attr("x", w - margin_h + 10)
.attr("y", y_abs(i/lines.length));
if(total_unit != null)
g.append("svg:text")
.text("Area: " + d3.format(".3s")(stats.area) + total_unit)
.attr("text-anchor", "start")
.attr("dominant-baseline", "central")
.attr("fill", line.color)
.attr("x", w - margin_h + 10)
.attr("y", y(stats.mean) + 12);
.attr("y", y_abs(i/lines.length) + 12);
}
}
}
Expand Down

0 comments on commit 84c4dfc

Please sign in to comment.