Commits

Bryan O'Sullivan  committed bc7b65b

Display units on the first one or two ticks on an axis.

  • Participants
  • Parent commits 387e8f5

Comments (0)

Files changed (2)

File templates/js/jquery.criterion.js

     return x.toString().substring(0,prec) + " " + t[1];
   };
 
+  $.unitFormatter = function(units) {
+    var ticked = 0;
+    return function(val,axis) {
+        var s = val.toFixed(axis.tickDecimals);
+	if (ticked > 1)
+	  return s;
+        else {
+          ticked++;
+	  return s + ' ' + units;
+	}
+    };
+  };
+
   $.addTooltip = function(name, renderText) {
     function showTooltip(x, y, contents) {
 	$('<div id="tooltip">' + contents + '</div>').css( {

File templates/report.tpl

     ts = ts[0];
     var kq = $("#kde" + number);
     var k = $.plot(kq,
-           [{ label: name + " time densities (" + units + ")",
+           [{ label: name + " time densities",
               data: $.zip(kdetimes, kdepdf),
               }],
-           { yaxis: { ticks: false },
+           { xaxis: { $.unitFormatter(units) },
+             yaxis: { ticks: false },
              grid: { hoverable: true, markings: [ { color: '#6fd3fb',
                      lineWidth: 1.5, xaxis: { from: mean, to: mean } } ] },
            });
     for (var i = 0; i < ts.length; i++)
       timepairs[i] = [ts[i],i];
     $.plot($("#time" + number),
-           [{ label: name + " times (" + units + ")",
+           [{ label: name + " times",
               data: timepairs }],
            { points: { show: true },
              grid: { hoverable: true },
-             xaxis: { min: kdetimes[0], max: kdetimes[kdetimes.length-1] },
+             xaxis: { min: kdetimes[0], max: kdetimes[kdetimes.length-1],
+                      tickFormatter: $.unitFormatter(units) },
              yaxis: { ticks: false },
            });
     $.addTooltip("#kde" + number, function(x,y) { return x + ' ' + units; });