2

Problem Description

Context

I am trying to visualize a large dataset of X-Y values using Vaadin Charts. I would like to be able to load lazily the values that will be loaded since the dataset is large. This could be achieved by setting a fix window and allow the user to change the dates. So if user selects startDate and endDate through the RangeSelector only these values should be loaded.

Current Approach

Each point is modeled as:

public final class TimestampedDoubleValue{
         private final long timestampInMillis;
         private final long value; 

         public TimestampedDoubleValue(long timestampInMillis,long value){
            this.value=value;
            this.timestampInMillis=timestampInMillis;
         }

         public final long getTimestampInMillis {return timestampInMillis;}
         public final long getValue {return value;}

}

I try to follow an approach similar to the one used to implement lazy loading in a Vaadin Grid. https://vaadin.com/blog/lazy-loading-with-vaadin-8

In order to implement the Lazy Loading I create a DataProvider and a SeriesDataProvider that is based on the DataProvider.

However I could not find any documentation or examples regarding lazy loading in Charts. I found some notes on DataProvider and SeriesDataProvider but they do not mention lazy loading explicitly. The ListDataProvider shown in the examples is an in memory solution with no lazy loading. https://vaadin.com/docs/v8/charts/java-api/charts-getting-started.html

Furthermore I cannot determine if this approach can be used for lazy loading and if lazy loading is possible at all in Vaadin Charts Timeline using the java API.

For example the DataProviderSeries Javadoc specifically states the following:

Note that even if you use a lazy loading DataProvider, this series will work in an eager fashion and load all the data from the provider at once.

https://demo.vaadin.com/javadoc/com.vaadin/vaadin-charts/4.0.1/com/vaadin/addon/charts/model/DataProviderSeries.html

public class TimeseriesDataProvider<F> extends AbstractBackEndDataProvider<TimestampedDoubleValue, F> {

public final DataProviderSeries<TimestampedDoubleValue> getDataProviderSeries() {
    final DataProviderSeries<TimestampedDoubleValue> dataProviderSeries = new DataProviderSeries<>(this);
    dataProviderSeries.setX(TimestampedDoubleValue::getTimestampInMillis);
    dataProviderSeries.setY(TimestampedDoubleValue::getValue);
    dataProviderSeries.setAutomaticChartUpdateEnabled(true);

    return dataProviderSeries;
}

 /*
 * @see com.vaadin.data.provider.DataProvider#isInMemory()
 */
@Override
public final boolean isInMemory() {
    return false;
}

/*
 * @see com.vaadin.data.provider.AbstractBackEndDataProvider#fetchFromBackEnd(com.vaadin.data.provider.Query)
 */
@Override
protected Stream<TimestampedDoubleValue> fetchFromBackEnd(final Query<TimestampedDoubleValue, F> query) {
   return FetchService.streamResults();

}

/* 
 * @see com.vaadin.data.provider.AbstractBackEndDataProvider#sizeInBackEnd(com.vaadin.data.provider.Query)
 */
@Override
protected int sizeInBackEnd(final Query<TimestampedDoubleValue, F> query) {
            return FetchService.countInBackend();
}

}

Questions

  1. Is it possible to use lazy loading in a timeline, if yes how? The existence of DataProviderSeries and its connection with DataProvider suggests it is. However the Javadoc of DataProviderSeries suggest otherwise. (see above).

  2. In the DataProvider series there is a filter (type F in the code above) that is passed inside the query as an argument. How can the filter be introduced so that it is passed as an argument?

Spyros K
  • 2,480
  • 1
  • 20
  • 37
  • 1
    At https://vaadin.com/components/vaadin-charts it says "The special timeline chart supports lazy loading from a massive time-based dataset while zooming." But I was not able to find any further information on this. – Robert Mikes Jul 04 '18 at 17:17
  • This is very interesting finding, it gives some direction to look around the timeline. Perhaps with the release of Vaadin 10 there is an upgrade in the documentation that is gradually rolled out, which hopefully will include a lazy loading example for charts. – Spyros K Jul 06 '18 at 08:39

0 Answers0