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.
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
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).
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?