plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
17.08k stars 1.87k forks source link

Range Slider flips mirror-like when viewport gets narrow #6493

Open GeorgeFlorian opened 1 year ago

GeorgeFlorian commented 1 year ago

I have encountered a strange behavior where, no matter what chart or data I am using, when the range slider doesn't have any space on the y axis, (this can happen when the y axis labels are wide) it flips like in a mirror:

In the first image the Year 2000 is the white dot on the left 1 In the second image the Year 2000 is the white dot on the right 2

I've modified the Adding Sliders to Animations in JavaScript example: https://codepen.io/bleah1/pen/dyqoaMQ and added responsive: true to config and a big margin of 400 to the layout to better see the flipping in action.

What now ? This obviously can't be used on narrow mobile screens.

alexcjohnson commented 1 year ago

Yep, looks like we simply don't check whether the right edge of the slider is actually farther right than its left edge. This one doesn't need responsive to make it happen, you can just set a small fixed width like 600 in that example.

So we could catch that, but there isn't much we could do at that point other than refuse to draw the slider. You already have the play and pause buttons taking up the space they take. All I can really suggest is to listen to the plotly_autosize event and modify the layout - put the slider below the buttons perhaps - if the width is too narrow. And vice versa, if you've gone from narrow to wide. I've tweaked your codepen to show the new width in that event handler. https://codepen.io/alexcjohnson/pen/NWLdLaG?editors=0010