Skip to content

Commit 119bd96

Browse files
authored
Merge pull request #3177 from ControlSystemStudio/autoscale_hyst
Plot: Add hysteresis to autoscale
2 parents dd1ebc7 + fb30dcf commit 119bd96

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2014-2023 Oak Ridge National Laboratory.
2+
* Copyright (c) 2014-2024 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -497,7 +497,6 @@ public void autoscale()
497497
Pair<Double, Double> adjustedRange = axis.ticks.adjustRange(low, high);
498498
low = adjustedRange.getKey();
499499
high = adjustedRange.getValue();
500-
501500
}
502501
else {
503502
final ValueRange rounded = roundValueRange(low, high);
@@ -511,16 +510,31 @@ public void autoscale()
511510
high += headroom;
512511
}
513512

514-
// Autoscale happens 'all the time'.
515-
// Do not use undo, but notify listeners.
516513
if (low != high)
517514
{
518515
final AxisRange<Double> orig = axis.getValueRange();
519516
final boolean normal = orig.getLow() < orig.getHigh();
520-
final boolean changed = normal ? axis.setValueRange(low, high)
521-
: axis.setValueRange(high, low);
522-
if (changed)
523-
plot.fireYAxisChange(axis);
517+
final double span = Math.abs(high - low);
518+
if (span > 0)
519+
{
520+
boolean changed = false;
521+
if (normal)
522+
{ // Hysteresis: Did low..high change beyond headroom?
523+
if (Math.abs(orig.getLow() - low) / span > 0.05 ||
524+
Math.abs(orig.getHigh() - high) / span > 0.05)
525+
changed = axis.setValueRange(low, high);
526+
}
527+
else
528+
{ // Hysteresis for inverted high...low range
529+
if (Math.abs(orig.getLow() - high) / span > 0.05 ||
530+
Math.abs(orig.getHigh() - low) / span > 0.05)
531+
changed = axis.setValueRange(high, low);
532+
}
533+
// Autoscale happens 'all the time'.
534+
// Do not use undo, but notify listeners.
535+
if (changed)
536+
plot.fireYAxisChange(axis);
537+
}
524538
}
525539
}
526540
catch (Exception ex)

0 commit comments

Comments
 (0)