Commit 0e993605 authored by David Schnur's avatar David Schnur

Fixed axis.tickDecimals that were broken by #50.

Pull request #50 inadvertently broke the behavior of axis.tickDecimals,
which previously added precision up to the given value.  The broken code
effectively ignored the setting for values with less precision.  This
fix brings back the old behavior.
parent 985cccae
......@@ -1290,9 +1290,23 @@
return ticks;
};
axis.tickFormatter = function (v, axis) {
var factor = Math.pow(10, axis.tickDecimals);
return "" + Math.round(v * factor) / factor;
axis.tickFormatter = function (value, axis) {
var factor = Math.pow(10, axis.tickDecimals);
var formatted = "" + Math.round(value * factor) / factor;
// If tickDecimals was specified, ensure that we have exactly that
// much precision; otherwise default to the value's own precision.
if (axis.tickDecimals != null) {
var decimal = formatted.indexOf(".");
var precision = decimal == -1 ? 0 : formatted.length - decimal - 1;
if (precision < axis.tickDecimals) {
return (precision ? formatted : formatted + ".") + ("" + factor).substr(1, axis.tickDecimals - precision);
}
}
return formatted;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment