question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

make-vis-flexible does not work with grid

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
rainecommented, Feb 23, 2019

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>
1reaction
jckrcommented, Jan 24, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does flexible grid loose its flexibility when container is ...
Here is a minimal example to illustrate the problem. Shrink the screen size once for max-width enabled and once for it disabled.
Read more >
How to make a flexible column with CSS Grid? - SitePoint
When I made the grid-items explicit by using grid-template-columns: 1fr 1fr , grid-column-end: -1 worked but its columns are now hard coded.
Read more >
react-vis | Yarn - Package Manager
d3-axis is no longer used, the rendering of axes and grids is made by react (and works faster). · The API of axes...
Read more >
<flex> - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The CSS data type denotes a flexible length within a grid container. It is used ... Report problems with this compatibility data on...
Read more >
Building a Flexible Grid System | CSS-Tricks
But this is not how custom properties work! In fact, the invalid --width-tablet variable will still be used in the flex-basis declaration. A ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found