labelsKMG2: false,
showLabelsOnHighlight: true,
- yValueFormatter: function(x) { return Dygraph.round_(x, 2); },
+ yValueFormatter: function(a,b) { return Dygraph.numberFormatter(a,b); },
+ digitsAfterDecimal: 2,
+ maxNumberWidth: 6,
strokeWidth: 1.0,
if (sepLines) html += "<br/>";
var c = new RGBColor(this.plotter_.colors[pt.name]);
- var yval = fmtFunc(pt.yval);
+ var yval = fmtFunc(pt.yval, this);
// TODO(danvk): use a template string here and make it an attribute.
html += " <b><font color='" + c.toHex() + "'>"
+ pt.name + "</font></b>:"
}
}
return -1;
-}
+};
Dygraph.zeropad = function(x) {
if (x < 10) return "0" + x; else return "" + x;
-}
+};
+
+/**
+ * Return a string version of a number. This respects the digitsAfterDecimal
+ * and maxNumberWidth options.
+ * @param {Number} x The number to be formatted
+ * @param {Dygraph} g The dygraph object
+ */
+Dygraph.numberFormatter = function(x, g) {
+ var digits = g.attr_('digitsAfterDecimal');
+ var maxNumberWidth = g.attr_('maxNumberWidth');
+
+ if (Math.abs(x) >= Math.pow(10, maxNumberWidth) ||
+ Math.abs(x) < Math.pow(10, -digits)) {
+ // switch to scientific notation.
+ } else {
+ return '' + Dygraph.round_(x, digits);
+ }
+};
/**
* Return a string version of the hours, minutes and seconds portion of a date.
} else {
return zeropad(d.getHours()) + ":" + zeropad(d.getMinutes());
}
-}
+};
/**
* Convert a JS date to a string appropriate to display on an axis that
return Dygraph.hmsString_(date.getTime());
}
}
-}
+};
/**
* Convert a JS date (millis since epoch) to YYYY/MM/DD
if (ticks[i].label !== undefined) continue; // Use current label.
var tickV = ticks[i].v;
var absTickV = Math.abs(tickV);
- var label = (formatter !== undefined) ?
- formatter(tickV) : Dygraph.round_(tickV, 2);
+ var label = formatter(tickV, self);
if (k_labels.length > 0) {
// Round up to an appropriate unit.
var n = k*k*k*k;