use of org.csstudio.javafx.rtplot.data.TimeDataSearch in project org.csstudio.display.builder by kasemir.
the class WaveformView method userMovedAnnotation.
private void userMovedAnnotation() {
if (waveform_annotation == null)
return;
for (AnnotationInfo annotation : model.getAnnotations()) {
// Locate the annotation for this waveform
if (annotation.isInternal() && annotation.getItemIndex() == waveform_annotation.getItemIndex() && annotation.getText().equals(waveform_annotation.getText())) {
// Locate index of sample for annotation's time stamp
final PlotSamples samples = model_item.getSamples();
final TimeDataSearch search = new TimeDataSearch();
final int idx;
samples.getLock().lock();
try {
idx = search.findClosestSample(samples, annotation.getTime());
} finally {
samples.getLock().unlock();
}
// Update waveform view for that sample on UI thread
sample_index.getDisplay().asyncExec(() -> {
sample_index.setSelection(idx);
showSelectedSample();
});
return;
}
}
}
use of org.csstudio.javafx.rtplot.data.TimeDataSearch in project org.csstudio.display.builder by kasemir.
the class TraceAnalyzerTest method testFindSample.
@Test
public void testFindSample() throws Exception {
final ArrayPlotDataProvider<Instant> data = new ArrayPlotDataProvider<>();
for (int i = 0; i <= 10; ++i) data.add(new SimpleDataItem<Instant>(Instant.ofEpochSecond(10 * i), 10.0 * i - 50));
for (int i = 0; i < data.size(); ++i) System.out.println(data.get(i));
TimeDataSearch search = new TimeDataSearch();
int index = search.findClosestSample(data, Instant.ofEpochSecond(39));
assertThat(index, not(equalTo(-1)));
PlotDataItem<Instant> sample = data.get(index);
assertThat(sample.getPosition().getEpochSecond(), equalTo(40L));
assertThat(sample.getValue(), equalTo(-10.0));
index = search.findClosestSample(data, Instant.ofEpochSecond(32));
assertThat(index, not(equalTo(-1)));
sample = data.get(index);
assertThat(sample.getPosition().getEpochSecond(), equalTo(30L));
assertThat(sample.getValue(), equalTo(-20.0));
}
Aggregations