From 4b5dc00d995c46ec54a50b373ee1575e75b447a3 Mon Sep 17 00:00:00 2001 From: "olau@iola.dk" Date: Wed, 12 Mar 2008 13:52:15 +0000 Subject: [PATCH] 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 --- NEWS.txt | 4 +++- jquery.flot.js | 25 +++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 6710f6f..4bab315 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -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 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 diff --git a/jquery.flot.js b/jquery.flot.js index 1c088f1..44a6cf1 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -220,8 +220,11 @@ } function processData() { - xaxis.datamin = yaxis.datamin = Number.MAX_VALUE; - xaxis.datamax = yaxis.datamax = Number.MIN_VALUE; + var top_sentry = Number.POSITIVE_INFINITY, + 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) { var data = series[i].data; @@ -248,13 +251,13 @@ } } - if (xaxis.datamin == Number.MAX_VALUE) + if (xaxis.datamin == top_sentry) xaxis.datamin = 0; - if (yaxis.datamin == Number.MAX_VALUE) + if (yaxis.datamin == top_sentry) yaxis.datamin = 0; - if (xaxis.datamax == Number.MIN_VALUE) + if (xaxis.datamax == bottom_sentry) xaxis.datamax = 1; - if (yaxis.datamax == Number.MIN_VALUE) + if (yaxis.datamax == bottom_sentry) yaxis.datamax = 1; } @@ -501,8 +504,9 @@ d.setMonth(0); - var carry = 0, v; + var carry = 0, v = Number.NaN, prev; do { + prev = v; v = d.getTime(); ticks.push({ v: v, label: axis.tickFormatter(v, axis) }); if (unit == "month") { @@ -526,7 +530,7 @@ } else d.setTime(v + step); - } while (v < axis.max); + } while (v < axis.max && v != prev); return ticks; }; @@ -602,12 +606,13 @@ var ticks = []; var start = floorInBase(axis.min, axis.tickSize); // then spew out all possible ticks - var i = 0, v; + var i = 0, v = Number.NaN, prev; do { + prev = v; v = start + i * axis.tickSize; ticks.push({ v: v, label: axis.tickFormatter(v, axis) }); ++i; - } while (v < axis.max); + } while (v < axis.max && v != prev); return ticks; };