amcharts / dataloader

Apache License 2.0
25 stars 25 forks source link

Allowing reload of a single dataSet #14

Open markedmondson opened 8 years ago

markedmondson commented 8 years ago

I think it'd be really useful to be able to call onload for only one of the dataSet indexes instead of reloading them all. Similar to #9.

Simply enhancing loadData to take an argument which only loads that index would be enough. The current problem with loadData is it reloads all remote sources.

A use case of this is if you have a dataSetSelector and large number of remote dataSets, onload automatically calls when the chart is rendered, this causes all of these URL's to be requested and their graphs to be rendered. To support a use case where these are only load on select or compare (using a the dataSetSelector listener) would allow for the remote sources to be requested on change and not all once.

Something like:

{
    dataSets: [
      {
        id: 1,
        dataLoader: {}
      },
      {
        id: 2,
        dataLoader: {}
      }
   ]
}

chart.dataSetSelector.addListener("dataSetSelected", function(event) {
  dataSet = event.dataSet

  if (dataSet.dataProvider.length)
    return;

  dataSet.dataLoader = {url: '/path/to/json/" + dataSet.id) }
  chart.dataLoader.loadData(dataSet.id); // Takes ID or dataSet index
  chart.validateData();
});
martynasma commented 8 years ago

Good point. Thanks.

I think, event better approach would be to implement a "lazy load" parameter. Meaning that the data set would only load when it's actually used - either it is selected as main data set or compared.

I'll investigate about including this feature.

Thanks!

markedmondson commented 8 years ago

You're right, there'd need to be a lazier initializer setting otherwise it'd get a bit gross adding the dataloader to each dataSet on dataSelectorChange to bypass the call to l.loadData (https://github.com/amcharts/dataloader/blob/master/dataloader.js#L174).

Happy to take a basic stab at this, I see there are outstanding PR's, do you guys accept external submissions?

martynasma commented 8 years ago

We do selectively accept PRs for plugins.

But give me a few days to tinker with it myself. Cool?

alexanderhorn6720 commented 6 years ago

I echo this request, has this been defined now elsewhere? Defining new datasets with dataloader on the fly after stockchart is initialized and other sets have been loaded already - do not want to load everything on each addition of new dataset.