React-vis: make-vis-flexible does not work with grid

Created on 26 Dec 2018  路  5Comments  路  Source: uber/react-vis

The FlexibleXYPlot component does not resize correctly when using CSS grid. We suspect this is an issue within make-vis-flexible and the xy-plot component. There's an assumption that the parent component will always, and accurately, downsize "correctly". In the case of CSS grid, that isn't true.

The child component's explicitly set width will override any upstream re-flows and re-renders. In our specific case, that implies that our graph will only act responsively when the browser window is increased in size, not when it's decreased.

Unexpected behavior:

  1. use CSS grid
  2. load page
  3. make page smaller
  4. chart overflows in the x-axis

screen shot 2018-12-26 at 10 25 11 am

Internally set, explicit width:

screen shot 2018-12-26 at 10 07 47 am

Trivial example:

https://codepen.io/anon/pen/vvJBoM?editors=1100

Naive suggestions to fix:

There's likely context that we're missing, but it seems peculiar to have "two separate components" for flexible and non-flexible plots. IMHO all charts should be flexible, and their size should be constrained by their parent components only. Internally, they should always strive to expand to 100%.

Calculating the the width of the component and setting it via JS (in React) is prone to exactly this type of issue. We suspect this was for a reason. Likely due to the needs of internal calculations for plotting data, animations, etc. Ideally we'd love to see (and help!) with making this styling less JS-centric, more CSS-native, and possibly condensed into one component.

This is a lot to ask, and we're happy to help. We'll need feedback first.

Thanks!

Most helpful comment

Had this same issue with grid and <FlexibleXYPlot>. The plot width would only increase, and not decrease.

<AutoSizer> from react-virtualized seems to work well.

Pseudo code for the workaround I used:

import AutoSizer from 'react-virtualized-auto-sizer'

// ...

<AutoSizer>
  {({ width }) => (
    <div className="plot">
      <XYPlot
        height={150}
        width={width}
      >
        // .....
      </XYPlot>
    </div>
  )}
</AutoSizer>

All 5 comments

@originalhat Were you able to figure a workaround for this issue?

@bobics negative. It might be possible to create a listener on your parent component and pass the width explicitly to trigger a resize, but that feels a little too icky for us. We'd rather have the browser do browser things. Good luck!

make-vis-flexible isn't a great wrapper. When it was written it was fairly reliable but there's a number of occasions beyond this one when it doesn't deliver. Meanwhile there are great solutions outside of react-vis which are better maintained, such as AutoSizer from react-virtualized.
https://bvaughn.github.io/react-virtualized/#/components/AutoSizer

Great, I'll try out a different wrapper, thanks for chiming in!

Had this same issue with grid and <FlexibleXYPlot>. The plot width would only increase, and not decrease.

<AutoSizer> from react-virtualized seems to work well.

Pseudo code for the workaround I used:

import AutoSizer from 'react-virtualized-auto-sizer'

// ...

<AutoSizer>
  {({ width }) => (
    <div className="plot">
      <XYPlot
        height={150}
        width={width}
      >
        // .....
      </XYPlot>
    </div>
  )}
</AutoSizer>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

codewithsk picture codewithsk  路  5Comments

kbouaazzi-ds picture kbouaazzi-ds  路  3Comments

stroemdev picture stroemdev  路  4Comments

mcnuttandrew picture mcnuttandrew  路  5Comments

cang-afero picture cang-afero  路  4Comments