Skip to content

Commit eea5f74

Browse files
author
Mateusz Nabywaniec
committed
Alternate between less-or-equal and greater-or-equal sample searches
That is possibly easier solution - instead of searching closest sample every update call we first search for less-or-equal sample and then greater-or-equal. Thanks to that we should keep more or less the same position as in the beginning.
1 parent 0dcb7c6 commit eea5f74

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class AnnotationImpl<XTYPE extends Comparable<XTYPE>> extends Annotation<
4343

4444
private static final Stroke DASH = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 3f, 3f }, 1.0f);
4545

46+
private boolean searchLessOrEqual;
47+
4648
/** What part of this annotation has been selected by the mouse? */
4749
public static enum Selection
4850
{ /** Nothing */
@@ -65,6 +67,7 @@ public static enum Selection
6567
public AnnotationImpl(final boolean internal, final Trace<XTYPE> trace, final XTYPE position, final double value, final Point2D offset, final String text)
6668
{
6769
super(internal, trace, position, value, offset, text);
70+
searchLessOrEqual = true;
6871
}
6972

7073
/** Set to new position
@@ -179,7 +182,15 @@ boolean updateValue(final XTYPE location) throws Exception
179182
throw new TimeoutException("Cannot update annotation, no lock on " + data);
180183
try
181184
{
182-
final int index = search.findClosestSample(data, location);
185+
final int index;
186+
if (searchLessOrEqual){
187+
index = search.findSampleLessOrEqual(data, location);
188+
}
189+
else{
190+
index = search.findSampleGreaterOrEqual(data, location);
191+
}
192+
searchLessOrEqual = !searchLessOrEqual;
193+
183194
if (index < 0)
184195
return false;
185196
final PlotDataItem<XTYPE> sample = data.get(index);

0 commit comments

Comments
 (0)