From 1f484ed2931f598d89d47a06e38af32bc46b8e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20C=C3=B4t=C3=A9?= Date: Fri, 8 Jun 2012 11:35:26 -0400 Subject: [PATCH 1/2] Fix minTickSize for year units. --- examples/time.html | 12 ++++++++++++ jquery.flot.time.js | 32 +++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/examples/time.html b/examples/time.html index 31139cf..4a6e908 100644 --- a/examples/time.html +++ b/examples/time.html @@ -22,6 +22,7 @@

Zoom to: +

The timestamps must be specified as Javascript timestamps, as @@ -55,6 +56,17 @@ $(function () { }); }); + $("#latenineties").click(function () { + $.plot($("#placeholder"), [d], { + xaxis: { + mode: "time", + minTickSize: [1, "year"], + min: (new Date(1996, 1, 1)).getTime(), + max: (new Date(2000, 1, 1)).getTime() + } + }); + }); + $("#ninetynine").click(function () { $.plot($("#placeholder"), [d], { xaxis: { diff --git a/jquery.flot.time.js b/jquery.flot.time.js index e27f274..508be90 100644 --- a/jquery.flot.time.js +++ b/jquery.flot.time.js @@ -163,18 +163,28 @@ for details. // special-case the possibility of several years if (unit == "year") { - var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10)); - var norm = (axis.delta / timeUnitSize.year) / magn; - if (norm < 1.5) - size = 1; - else if (norm < 3) - size = 2; - else if (norm < 7.5) - size = 5; - else - size = 10; + // if given a minTickSize in years, just use it, + // ensuring that it's an integer + if (opts.minTickSize != null && opts.minTickSize[1] == "year") { + size = Math.floor(opts.minTickSize[0]); + } else { + var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10)); + var norm = (axis.delta / timeUnitSize.year) / magn; + if (norm < 1.5) + size = 1; + else if (norm < 3) + size = 2; + else if (norm < 7.5) + size = 5; + else + size = 10; - size *= magn; + size *= magn; + } + + // minimum size for years is 1 + if (size < 1) + size = 1; } axis.tickSize = opts.tickSize || [size, unit]; From fd80908918fc538fc3cccbfadeba198e5c3f1bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20C=C3=B4t=C3=A9?= Date: Wed, 13 Jun 2012 08:41:52 -0400 Subject: [PATCH 2/2] Updated NEWS.txt for year-ticks fix. --- NEWS.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.txt b/NEWS.txt index e6c4b2a..6175ca3 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -29,6 +29,8 @@ and "flot-overlay" to prevent accidental clashes (issue 540). Changes: +- Fixed display of year ticks (patch by Mark Cote, issue 195). + - Support for time series moved to plugin (patch by Mark Cote). - Display time series in different time zones (patch by Knut Forkalsrud,