Commit 1f484ed2 authored by Mark Côté's avatar Mark Côté

Fix minTickSize for year units.

parent 24632ba1
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<p>Zoom to: <button id="whole">Whole period</button> <p>Zoom to: <button id="whole">Whole period</button>
<button id="nineties">1990-2000</button> <button id="nineties">1990-2000</button>
<button id="latenineties">1996-2000</button>
<button id="ninetynine">1999</button></p> <button id="ninetynine">1999</button></p>
<p>The timestamps must be specified as Javascript timestamps, as <p>The timestamps must be specified as Javascript timestamps, as
...@@ -55,6 +56,17 @@ $(function () { ...@@ -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 () { $("#ninetynine").click(function () {
$.plot($("#placeholder"), [d], { $.plot($("#placeholder"), [d], {
xaxis: { xaxis: {
......
...@@ -163,18 +163,28 @@ for details. ...@@ -163,18 +163,28 @@ for details.
// special-case the possibility of several years // special-case the possibility of several years
if (unit == "year") { if (unit == "year") {
var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10)); // if given a minTickSize in years, just use it,
var norm = (axis.delta / timeUnitSize.year) / magn; // ensuring that it's an integer
if (norm < 1.5) if (opts.minTickSize != null && opts.minTickSize[1] == "year") {
size = 1; size = Math.floor(opts.minTickSize[0]);
else if (norm < 3) } else {
size = 2; var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10));
else if (norm < 7.5) var norm = (axis.delta / timeUnitSize.year) / magn;
size = 5; if (norm < 1.5)
else size = 1;
size = 10; 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]; axis.tickSize = opts.tickSize || [size, unit];
......
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