Commit 4b5dc00d authored by olau@iola.dk's avatar olau@iola.dk

Fix Number.MIN_VALUE bug and prevent the possibility of eternal looping in tick calculations

git-svn-id: https://flot.googlecode.com/svn/trunk@63 1e0a6537-2640-0410-bfb7-f154510ff394
parent 5dab68dd
...@@ -5,7 +5,9 @@ Added support for specifying the size of tick labels (axis.labelWidth, ...@@ -5,7 +5,9 @@ Added support for specifying the size of tick labels (axis.labelWidth,
axis.labelHeight). Useful for specifying a max label size to keep axis.labelHeight). Useful for specifying a max label size to keep
multiple plots aligned. multiple plots aligned.
Fixed a bug in calculating spacing around the plot (reported by timothytoe). Fixed a bug in calculating spacing around the plot (reported by
timothytoe). Fixed a bug in finding max values for all-negative data
sets. Prevent the possibility of eternal looping in tick calculations.
Flot 0.4 Flot 0.4
......
...@@ -220,8 +220,11 @@ ...@@ -220,8 +220,11 @@
} }
function processData() { function processData() {
xaxis.datamin = yaxis.datamin = Number.MAX_VALUE; var top_sentry = Number.POSITIVE_INFINITY,
xaxis.datamax = yaxis.datamax = Number.MIN_VALUE; bottom_sentry = Number.NEGATIVE_INFINITY;
xaxis.datamin = yaxis.datamin = top_sentry;
xaxis.datamax = yaxis.datamax = bottom_sentry;
for (var i = 0; i < series.length; ++i) { for (var i = 0; i < series.length; ++i) {
var data = series[i].data; var data = series[i].data;
...@@ -248,13 +251,13 @@ ...@@ -248,13 +251,13 @@
} }
} }
if (xaxis.datamin == Number.MAX_VALUE) if (xaxis.datamin == top_sentry)
xaxis.datamin = 0; xaxis.datamin = 0;
if (yaxis.datamin == Number.MAX_VALUE) if (yaxis.datamin == top_sentry)
yaxis.datamin = 0; yaxis.datamin = 0;
if (xaxis.datamax == Number.MIN_VALUE) if (xaxis.datamax == bottom_sentry)
xaxis.datamax = 1; xaxis.datamax = 1;
if (yaxis.datamax == Number.MIN_VALUE) if (yaxis.datamax == bottom_sentry)
yaxis.datamax = 1; yaxis.datamax = 1;
} }
...@@ -501,8 +504,9 @@ ...@@ -501,8 +504,9 @@
d.setMonth(0); d.setMonth(0);
var carry = 0, v; var carry = 0, v = Number.NaN, prev;
do { do {
prev = v;
v = d.getTime(); v = d.getTime();
ticks.push({ v: v, label: axis.tickFormatter(v, axis) }); ticks.push({ v: v, label: axis.tickFormatter(v, axis) });
if (unit == "month") { if (unit == "month") {
...@@ -526,7 +530,7 @@ ...@@ -526,7 +530,7 @@
} }
else else
d.setTime(v + step); d.setTime(v + step);
} while (v < axis.max); } while (v < axis.max && v != prev);
return ticks; return ticks;
}; };
...@@ -602,12 +606,13 @@ ...@@ -602,12 +606,13 @@
var ticks = []; var ticks = [];
var start = floorInBase(axis.min, axis.tickSize); var start = floorInBase(axis.min, axis.tickSize);
// then spew out all possible ticks // then spew out all possible ticks
var i = 0, v; var i = 0, v = Number.NaN, prev;
do { do {
prev = v;
v = start + i * axis.tickSize; v = start + i * axis.tickSize;
ticks.push({ v: v, label: axis.tickFormatter(v, axis) }); ticks.push({ v: v, label: axis.tickFormatter(v, axis) });
++i; ++i;
} while (v < axis.max); } while (v < axis.max && v != prev);
return ticks; return ticks;
}; };
......
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