esnet / react-timeseries-charts

Declarative and modular timeseries charting components for React
http://software.es.net/react-timeseries-charts
Other
859 stars 283 forks source link

Chart container does not appear within Display Flex Container #431

Open zbayoff opened 4 years ago

zbayoff commented 4 years ago

🐛Bug report

Describe the bug When a <ChartContainer>, wrapped in the <Resizable> component is within a display: flex container, the chart will not appear in the DOM

To Reproduce Steps to reproduce the behavior: I have created a test repo here: https://github.com/zbayoff/react-timeseries-charts-example using the Simple Bar Chart Example. The test repo is created with the Create React App code.

Clone the repo, npm install and yarn run start.

Expected behavior The bar chart should show in the DOM. Setting the row class to display: block and the bar chart will appear. It is necessary, in my app, however, that the container is display: flex.

Desktop (please complete the following information):

pjm17971 commented 4 years ago

That seems to be bootstrap code. I'm not sure, but does it need a column div, you only have a row containing no column span. Maybe wrap the Resizable in something like <div className="col-md-12">

zbayoff commented 4 years ago

@pjm17971 I removed the Bootstrap classes, but I still get the issue if I set the container to display: flex. I've updated my test repo.

pjm17971 commented 4 years ago

Yeah it seems like the Resizable code isn't working with flexbox parents, and it also seems like this is a general problem. In general the chart code just expects a width prop passed into it. What the Resizable component does is tries to measure its parent and inject that width into the ChartContainer below it. So the question is how to measure the parent when it's a flexbox 🤔

Thanks for the report. I'm not sure what the solution is unfortunately.

BennettDixon commented 3 years ago

I have encountered the same issue with failing to render in flex-boxes. I have resolved it by wrapping the <Resizable /> container in a containing div and setting the height & width to 100%:

<div style={{ height: '100%', width: '100%' }}>
  <Resizable>
    <ChartContainer {...chartContainerProps} >
      <ChartRow height={CHART_HEIGHT}>
        <YAxis {...yAxisProps} />
        <Charts>{charts}</Charts>
      </ChartRow>
    </ChartContainer>
  </Resizable>
</div>