Commit 1158d063 authored by olau@iola.dk's avatar olau@iola.dk

Fix a bug with axis range margins not being set in the same way

(patch by Paul Kienzle), and fix snap to ticks so it works correctly
with max ticks


git-svn-id: https://flot.googlecode.com/svn/trunk@195 1e0a6537-2640-0410-bfb7-f154510ff394
parent 322a8d5d
...@@ -693,9 +693,10 @@ ...@@ -693,9 +693,10 @@
function setRange(axis, axisOptions) { function setRange(axis, axisOptions) {
var min = +(axisOptions.min != null ? axisOptions.min : axis.datamin), var min = +(axisOptions.min != null ? axisOptions.min : axis.datamin),
max = +(axisOptions.max != null ? axisOptions.max : axis.datamax); max = +(axisOptions.max != null ? axisOptions.max : axis.datamax),
delta = max - min;
if (max - min == 0.0) { if (delta == 0.0) {
// degenerate case // degenerate case
var widen = max == 0 ? 1 : 0.01; var widen = max == 0 ? 1 : 0.01;
...@@ -711,14 +712,14 @@ ...@@ -711,14 +712,14 @@
var margin = axisOptions.autoscaleMargin; var margin = axisOptions.autoscaleMargin;
if (margin != null) { if (margin != null) {
if (axisOptions.min == null) { if (axisOptions.min == null) {
min -= (max - min) * margin; min -= delta * margin;
// make sure we don't go below zero if all values // make sure we don't go below zero if all values
// are positive // are positive
if (min < 0 && axis.datamin != null && axis.datamin >= 0) if (min < 0 && axis.datamin != null && axis.datamin >= 0)
min = 0; min = 0;
} }
if (axisOptions.max == null) { if (axisOptions.max == null) {
max += (max - min) * margin; max += delta * margin;
if (max > 0 && axis.datamax != null && axis.datamax <= 0) if (max > 0 && axis.datamax != null && axis.datamax <= 0)
max = 0; max = 0;
} }
...@@ -1009,7 +1010,7 @@ ...@@ -1009,7 +1010,7 @@
if (axisOptions.min == null) if (axisOptions.min == null)
axis.min = Math.min(axis.min, axis.ticks[0].v); axis.min = Math.min(axis.min, axis.ticks[0].v);
if (axisOptions.max == null && axis.ticks.length > 1) if (axisOptions.max == null && axis.ticks.length > 1)
axis.max = Math.min(axis.max, axis.ticks[axis.ticks.length - 1].v); axis.max = Math.max(axis.max, axis.ticks[axis.ticks.length - 1].v);
} }
} }
......
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