Search in sources :

Example 1 with TimeDataSearch

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;
        }
    }
}
Also used : TimeDataSearch(org.csstudio.javafx.rtplot.data.TimeDataSearch) AnnotationInfo(org.csstudio.trends.databrowser3.model.AnnotationInfo) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 2 with TimeDataSearch

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));
}
Also used : SimpleDataItem(org.csstudio.javafx.rtplot.data.SimpleDataItem) Instant(java.time.Instant) ArrayPlotDataProvider(org.csstudio.javafx.rtplot.data.ArrayPlotDataProvider) TimeDataSearch(org.csstudio.javafx.rtplot.data.TimeDataSearch) Test(org.junit.Test)

Aggregations

TimeDataSearch (org.csstudio.javafx.rtplot.data.TimeDataSearch)2 Instant (java.time.Instant)1 ArrayPlotDataProvider (org.csstudio.javafx.rtplot.data.ArrayPlotDataProvider)1 SimpleDataItem (org.csstudio.javafx.rtplot.data.SimpleDataItem)1 AnnotationInfo (org.csstudio.trends.databrowser3.model.AnnotationInfo)1 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)1 Test (org.junit.Test)1