Commit bedf4fb2 authored by olau@iola.dk's avatar olau@iola.dk

Cleaned up findDataRanges, fix bug in date handling that I just introduced

git-svn-id: https://flot.googlecode.com/svn/trunk@50 1e0a6537-2640-0410-bfb7-f154510ff394
parent ad3f6a73
...@@ -191,42 +191,40 @@ ...@@ -191,42 +191,40 @@
} }
function findDataRanges() { function findDataRanges() {
yaxis.datamin = xaxis.datamin = 0; xaxis.datamin = yaxis.datamin = Number.MAX_VALUE;
xaxis.datamax = yaxis.datamax = 1; xaxis.datamax = yaxis.datamax = Number.MIN_VALUE;
if (series.length == 0) for (var i = 0; i < series.length; ++i) {
return;
// get datamin, datamax start values
var i, found = false;
for (i = 0; i < series.length; ++i) {
if (series[i].data.length > 0) {
xaxis.datamin = xaxis.datamax = series[i].data[0][0];
yaxis.datamin = yaxis.datamax = series[i].data[0][1];
found = true;
break;
}
}
if (!found)
return;
// then find real datamin, datamax
for (i = 0; i < series.length; ++i) {
var data = series[i].data; var data = series[i].data;
for (var j = 0; j < data.length; ++j) { for (var j = 0; j < data.length; ++j) {
if (data[j] == null)
continue;
var x = data[j][0]; var x = data[j][0];
var y = data[j][1]; var y = data[j][1];
if (x == null || isNaN(x) || y == null || isNaN(y))
continue;
if (x < xaxis.datamin) if (x < xaxis.datamin)
xaxis.datamin = x; xaxis.datamin = x;
else if (x > xaxis.datamax) if (x > xaxis.datamax)
xaxis.datamax = x; xaxis.datamax = x;
if (y < yaxis.datamin) if (y < yaxis.datamin)
yaxis.datamin = y; yaxis.datamin = y;
else if (y > yaxis.datamax) if (y > yaxis.datamax)
yaxis.datamax = y; yaxis.datamax = y;
} }
} }
if (xaxis.datamin == Number.MAX_VALUE)
xaxis.datamin = 0;
if (yaxis.datamin == Number.MAX_VALUE)
yaxis.datamin = 0;
if (xaxis.datamax == Number.MIN_VALUE)
xaxis.datamax = 1;
if (yaxis.datamax == Number.MIN_VALUE)
yaxis.datamax = 1;
} }
function setRange(axis, axisOptions) { function setRange(axis, axisOptions) {
...@@ -415,9 +413,9 @@ ...@@ -415,9 +413,9 @@
d.setMonth(0); d.setMonth(0);
var carry = 0; var carry = 0, v;
var v = d.getTime();
do { do {
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") {
if (tickSize < 1) { if (tickSize < 1) {
...@@ -447,7 +445,7 @@ ...@@ -447,7 +445,7 @@
formatter = function (v, axis) { formatter = function (v, axis) {
var d = new Date(v); var d = new Date(v);
// first check global format // first check global format
if (axisOptions.timeformat != null) if (axisOptions.timeformat != null)
return formatDate(d, axisOptions.timeformat, axisOptions.monthNames); return formatDate(d, axisOptions.timeformat, axisOptions.monthNames);
...@@ -516,7 +514,7 @@ ...@@ -516,7 +514,7 @@
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
i = 0; var i = 0, v;
do { do {
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) });
......
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