Commit 6fa52420 authored by David Schnur's avatar David Schnur

Ensure that axes always have a tickGenerator.

Check whether an axis has a generator, rather than a mode. In most cases
this is functionally the same, but it also handles the case where an
axis mode plug-in specifies only the formatter, and expects to use the
default base-10 generator.
parent 8e237683
...@@ -1168,10 +1168,18 @@ ...@@ -1168,10 +1168,18 @@
axis.delta = (axis.max - axis.min) / noTicks; axis.delta = (axis.max - axis.min) / noTicks;
// special modes are handled by plug-ins, e.g. "time". The default // Time mode was moved to a plug-in in 0.8, but since so many people use this
// is base-10 numbers. // we'll add an especially friendly make sure they remembered to include it.
if (!opts.mode) {
// pretty rounding of base-10 numbers if (opts.mode == "time" && !axis.tickGenerator) {
throw new Error("Time mode requires the flot.time plugin.");
}
// Flot supports base-10 axes; any other mode else is handled by a plug-in,
// like flot.time.js.
if (!axis.tickGenerator) {
var maxDec = opts.tickDecimals; var maxDec = opts.tickDecimals;
var dec = -Math.floor(Math.log(axis.delta) / Math.LN10); var dec = -Math.floor(Math.log(axis.delta) / Math.LN10);
if (maxDec != null && dec > maxDec) if (maxDec != null && dec > maxDec)
...@@ -1193,8 +1201,7 @@ ...@@ -1193,8 +1201,7 @@
} }
else if (norm < 7.5) else if (norm < 7.5)
size = 5; size = 5;
else else size = 10;
size = 10;
size *= magn; size *= magn;
...@@ -1205,10 +1212,7 @@ ...@@ -1205,10 +1212,7 @@
axis.tickSize = opts.tickSize || size; axis.tickSize = opts.tickSize || size;
axis.tickGenerator = function (axis) { axis.tickGenerator = function (axis) {
var ticks = []; var ticks = [], start = floorInBase(axis.min, axis.tickSize),
// spew out all possible ticks
var start = floorInBase(axis.min, axis.tickSize),
i = 0, v = Number.NaN, prev; i = 0, v = Number.NaN, prev;
do { do {
prev = v; prev = v;
...@@ -1224,9 +1228,6 @@ ...@@ -1224,9 +1228,6 @@
return "" + Math.round(v * factor) / factor; return "" + Math.round(v * factor) / factor;
}; };
} }
else if (opts.mode == "time" && axis.tickGenerator == undefined) {
throw new Error("Time mode requires the flot.time plugin.");
}
if ($.isFunction(opts.tickFormatter)) if ($.isFunction(opts.tickFormatter))
axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); }; axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); };
......
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