From 421b548b527b40b83dd9a204e58bfc928de11e53 Mon Sep 17 00:00:00 2001 From: Igor Babuschkin Date: Sat, 2 Aug 2014 19:55:12 +0200 Subject: [PATCH] Add axis labels to histograms --- js/histogram.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/js/histogram.js b/js/histogram.js index 7671632..bdc9101 100644 --- a/js/histogram.js +++ b/js/histogram.js @@ -2,9 +2,9 @@ function draw_hist(ident, vals) { // A formatter for counts. - var formatCount = d3.format(",.0f"); + var formatCount = d3.format(",0d"); - var margin = {top: 10, right: 30, bottom: 30, left: 30}, + var margin = {top: 10, right: 30, bottom: 30, left: 40}, width = 200 - margin.left - margin.right, height = 100 - margin.top - margin.bottom; @@ -23,7 +23,7 @@ function draw_hist(ident, vals) { var xAxis = d3.svg.axis() .scale(x) - .ticks(5) + .ticks(3) .tickFormat(function(d) { return '';}) .orient("bottom"); @@ -90,11 +90,27 @@ function draw_hist(ident, vals) { .attr("transform", "translate(0," + (height ) + ")") .call(xAxis); + svg.append("text") + .attr("class", "x label") + .attr("text-anchor", "end") + .attr("x", width) + .attr("y", height + 20) + .text("m (GeV)"); + svg.append("g") .attr("class", "y axis") .attr("transform", "translate(0, 0)") .call(yAxis); + svg.append("text") + .attr("class", "y label") + .attr("text-anchor", "end") + .attr("y", -20) + .attr("dy", "-1em") + .attr("dx", "-0.5em") + .attr("transform", "rotate(-90)") + .text("events"); + return svg; }