From 22eb1489eb4752f0a47821bffe4edd560e9a1d94 Mon Sep 17 00:00:00 2001 From: "olau@iola.dk" Date: Wed, 19 Nov 2008 17:41:58 +0000 Subject: [PATCH] Added support for skipping points outside the specified range when autoscaling git-svn-id: https://flot.googlecode.com/svn/trunk@110 1e0a6537-2640-0410-bfb7-f154510ff394 --- API.txt | 7 +++++++ NEWS.txt | 3 +++ jquery.flot.js | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/API.txt b/API.txt index b7fb534..3d9b7f5 100644 --- a/API.txt +++ b/API.txt @@ -166,6 +166,7 @@ Customizing the axes min: null or number max: null or number autoscaleMargin: null or number + autoscaleSkipPointsOutside: boolean labelWidth: null or number labelHeight: null or number @@ -192,6 +193,12 @@ specified, the plot will furthermore extend the axis end-point to the nearest whole tick. The default value is "null" for the x axis and 0.02 for the y axis which seems appropriate for most cases. +If you set a range on an axis with min/max and then set +"autoscaleSkipPointsOutside" to true, the autoscale algorithm will +skip points that are outside this range when computing the scale for +the other axis. Otherwise all points input to Flot are always +considered. + "labelWidth" and "labelHeight" specifies the maximum size of the tick labels in pixels. They're useful in case you need to align several plots. diff --git a/NEWS.txt b/NEWS.txt index cc7b924..7b6c171 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -6,6 +6,9 @@ New features: - Added support for disabling interactivity for specific data series (request from Ronald Schouten and Steve Upton). +- Added support for having the autoscale algorithm skip points outside + an axis range (autoscaleSkipPointsOutside on an axis). + Bug fixes: diff --git a/jquery.flot.js b/jquery.flot.js index d0e1cf8..60f95c0 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -31,6 +31,7 @@ min: null, // min. value to show, null means set automatically max: null, // max. value to show, null means set automatically autoscaleMargin: null, // margin in % to add if auto-setting min/max + autoscaleSkipPointsOutside: null, ticks: null, // either [1, 3] or [[1, "a"], 3] or (fn: axis info -> ticks) or app. number of ticks for auto-ticks tickFormatter: null, // fn: number -> string labelWidth: null, // size of tick labels in pixels @@ -266,6 +267,9 @@ for (axis in axes) { axes[axis].datamin = topSentry; axes[axis].datamax = bottomSentry; + axes[axis].min = options[axis].min; + axes[axis].max = options[axis].max; + axes[axis].skipoutside = options[axis].autoscaleSkipPointsOutside; axes[axis].used = false; } @@ -280,7 +284,7 @@ mindelta = series[i].bars.align == "left" ? 0 : -series[i].bars.barWidth/2; maxdelta = mindelta + series[i].bars.barWidth; } - + axisx.used = axisy.used = true; for (var j = 0; j < data.length; ++j) { if (data[j] == null) @@ -290,6 +294,12 @@ // convert to number if (x != null && !isNaN(x = +x)) { + if (axisx.skipoutside && + ((axisx.min != null && x + mindelta < axisx.min) || + (axisx.max != null && x + maxdelta > axisx.max))) { + continue; + } + if (x + mindelta < axisx.datamin) axisx.datamin = x + mindelta; if (x + maxdelta > axisx.datamax) @@ -297,6 +307,11 @@ } if (y != null && !isNaN(y = +y)) { + if (axisy.skipoutside && + ((axisy.min != null && y < axisy.min) || + (axisy.max != null && y > axisy.max))) + continue; + if (y < axisy.datamin) axisy.datamin = y; if (y > axisy.datamax)