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

chart does not update on class change #88

Open
titaniumbones opened this issue Dec 20, 2019 · 0 comments
Open

chart does not update on class change #88

titaniumbones opened this issue Dec 20, 2019 · 0 comments

Comments

@titaniumbones
Copy link

I'm rewriting a vanilla HTML/js project in react, in which charts are hidden at time of creation and shown using a toggle button which adds a class to the parent of a <ChartistGraph/> ocmponent.

I'm having trouble forcing an update on the chart component when the display value of the component container changes from none to block.

in vanilla JS, I could trigger this update as follows:

  // trigger chartist update event on tab -- mostly for first click, otherwise it doesn't
  // know its size (b/c display:none on start. )
  document.querySelector(`#${tabName} figure`).__chartist__.update()

in React, I don't seem to be able to accomplish this. If I create the chart hwen its parent is displayed, it renders properly:
image
I can then hide it:
image
But when I go to redisplay it, the chart has been resized to width=height=0:
image

So, I guess the chart size is updated when I hide the component, but not when I re-show it. The parent component (code here) is clearly re-rendering when the display class changes. But I do not seem to be able to trigger an appropriate update of the chart myself.

I've tried adding a ref to the <ChartistGraph /> component, and then triggering chartist''s own update() function in the render:

    if (this.chartRef.current) {
      console.log('CHARTREF2', this.chartRef.current.chart.__chartist__.update)
      this.chartRef.current.chart.__chartist__.update(series)
    }

But this does not fix the problem for me as it did in the vanilla JS version.

I see there are a couple of possibly-related issues, e.g. #73, but I think this one is distinct and I would love to get some guidance. Thanks!

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

1 participant