Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New regions are not rendered when updating props #18

Open
myktra opened this issue Mar 9, 2017 · 4 comments
Open

New regions are not rendered when updating props #18

myktra opened this issue Mar 9, 2017 · 4 comments

Comments

@myktra
Copy link

myktra commented Mar 9, 2017

Seems like unlike properties like axis and grid, changing regions neither removes any previous regions that were drawn the first time the C3Chart component was rendered nor renders the new ones.

Adding this.chart.regions.remove() to componentWillUpdateProps removes the regions but then new regions that are specified are not redrawn when C3Chart is re-rendered.

In a perhaps related observation, passing the unloadBeforeLoad prop doesn't seem to work for me...rendering seems unpredictable.

@myktra
Copy link
Author

myktra commented Mar 9, 2017

Potentially related to c3js/c3#1527.

@nels-o
Copy link

nels-o commented Mar 20, 2017

I found a quick workaround for a demo. Until c3 fixes this on their end, this will at least cause the regions to update as expected.

updateChart(config) {
    if (!this.chart) {
      this.chart = this.generateChart(findDOMNode(this), config);
    }

    if (config.unloadBeforeLoad) {
        this.unloadData();
    }
    
    // If there are regions in the config, update them.
    // If there are regions on the chart, and the config specifies none 
    // then delete the existing regions.
    if (config.regions) {
        this.chart.regions(config.regions);
    } else if (this.chart.regions && !config.regions){
        this.chart.regions([]);
    }

    this.loadNewData(config.data);
  }

nels-o pushed a commit to nels-o/react-c3js that referenced this issue Mar 20, 2017
@andreasheim
Copy link

The c3 docs state that calling unload just before load will not work properly, as it will occur in the midst of the animation.

http://c3js.org/reference.html#api-unload

If you call load API soon after/before unload, unload param of load should be used. Otherwise chart will not be rendered properly because of cancel of animation.

I haven't tested this yet, but I think what should be done instead is pass unload: true when loading:

http://c3js.org/reference.html#api-load

If unload given, data will be unloaded before loading new data. If true given, all of data will be unloaded.

Hence it should work like this:

  updateChart(config) {
    if (!this.chart) {
      this.chart = this.generateChart(findDOMNode(this), config);
    }

    let data = config.data;
    if (config.unloadBeforeLoad) {
      data = { ...data, unload: true };
    }
    this.loadNewData(data);
  }

@andreasheim
Copy link

I'm not using regions, so I'm not sure if my changes fix that. However I did verify that using load with unload: true does fix my issue with data not updating properly. Potentially both changes may be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants