Skip to content

Commit 2098f64

Browse files
committed
CSSTUDIO-1928 Improve autoscale of logarithmic axes.
1 parent 77f98ef commit 2098f64

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

app/rtplot/src/main/java/org/csstudio/javafx/rtplot/internal/PlotProcessor.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.TimeoutException;
2020
import java.util.logging.Level;
2121

22+
import javafx.util.Pair;
2223
import org.csstudio.javafx.rtplot.Axis;
2324
import org.csstudio.javafx.rtplot.AxisRange;
2425
import org.csstudio.javafx.rtplot.Messages;
@@ -490,32 +491,26 @@ public void autoscale()
490491
}
491492
}
492493
if (axis.isLogarithmic())
493-
{ // Perform adjustment in log space.
494-
// But first, refuse to deal with <= 0
495-
if (low <= 0.0)
496-
low = 1;
497-
if (high <= low)
498-
high = low * 100.0;
499-
low = Log10.log10(low);
500-
high = Log10.log10(high);
501-
}
502-
final ValueRange rounded = roundValueRange(low, high);
503-
low = rounded.getLow();
504-
high = rounded.getHigh();
505-
if (axis.isLogarithmic())
506494
{
507-
low = Log10.pow10(low);
508-
high = Log10.pow10(high);
495+
low = Log10.pow10(Math.floor(Log10.log10(low))); // Note: may set "low" to 0.0.
496+
high = Log10.pow10(Math.ceil(Log10.log10(high)));
497+
Pair<Double, Double> adjustedRange = axis.ticks.adjustRange(low, high);
498+
low = adjustedRange.getKey();
499+
high = adjustedRange.getValue();
500+
509501
}
510-
else
511-
{ // Stretch range a little bit
502+
else {
503+
final ValueRange rounded = roundValueRange(low, high);
504+
low = rounded.getLow();
505+
high = rounded.getHigh();
506+
// Stretch range a little bit
512507
// (but not for log scale, where low just above 0
513508
// could be stretched to <= 0)
514509
final double headroom = (high - low) * 0.05;
515510
low -= headroom;
516511
high += headroom;
517-
518512
}
513+
519514
// Autoscale happens 'all the time'.
520515
// Do not use undo, but notify listeners.
521516
if (low != high)

0 commit comments

Comments
 (0)