-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Make layout height & width understand viewport and percentage sizes #106
Comments
plotly.js only understands fixed This tutorial https://plot.ly/javascript/responsive-fluid-layout/ shows you how to make responsive/fluid plotly.js graphs. Personally, I really like the idea of making Changing the issue title to reflect a feature request. |
Any progress on this? ps. I have already see this: Thank you. |
Here's a function that can convert any valid absolute or relative css length to pixels:
|
also broken for me. any pointers how to make graphs be 100% of their parent container? |
@chriddyp Can you elaborate on the use case for this feature? Currently, without specifying a It is my understanding that viewport and percentage sizes only make sense in the context of a page. In my opinion, this presentation logic should be CSS' business so I am not sure plotly.js should deal with those explicitly. Is there a use case I am not seeing or can we close this issue? |
It appears that you can change the height on resize, but not the width as the width is always dependent on the height you set. You should be able to set a minWidth and a scroll bar because the charts are completely illegible on mobile. |
Hello @pdfabbro and thank you for commenting on this issue!
I'm not sure I understand what you mean by this. It seems to me that the width does change on resizing as shown in this codepen https://codepen.io/antoinerg/full/NLboJw. Can you elaborate or better yet send me a Codepen highlighting the issue?
At the moment, this can be accomplished using CSS as shown in this codepen https://codepen.io/antoinerg/pen/JaZEOQ. Please let us know whether this solution makes sense and is doable in your context. Thank you again :) |
Hi Antoine, Thanks very much for the quick response! Yes, for me the width does change, but I can't actually set it to a specific value whereas I can set the height to a specific value. If I don't set the height, then it goes back to its default of 450px. What I'd like to be able to do is set the height AND width to specific values, but right now it seems to only take in my height and then adjust the width accordingly. As for the minWidth and scroll, I am doing something very similar to what you have, but it isn't working. I am calculating width, height, and minWidth in a resize function similar to the eponym's code from here: https://community.plot.ly/t/plot-sizing-problems/1620/13 I'll have to take a closer look at yours and see what's different than mine. Thanks again. |
I just noticed you have a property in a config object "responsive:true". I don't see that property in the reference: https://plot.ly/javascript/reference/ or the config reference: https://plot.ly/javascript/configuration-options/ |
I think I see what I'm doing wrong in terms of the scrollbar issue which would mean I no longer care about explicitly setting both height and width (in terms of pixels), so this should resolve my issue. Thanks very much! I'd still be curious why I can't explicitly set both height and width though, but perhaps I am setting that on the wrong div as I noticed eponym's code is setting the svg-container, whereas you are setting the width on the container that is passed to Plotly.plot. |
Yup, I was on the wrong div... sorry for the spam, looks like I was trying to combine eponym's answer and height and div property's incorrectly. I tried out your scroll solution and it works perfectly for me. Thank-you so much for taking the time to do that. |
Glad I could help @pdfabbro ! The config option |
For any future visitors, one issue that I've seen folks have with sizing is that the graph div doesn't inherit the parent's height. So, this "doesn't work" <div style="height: 60vh">
<div id="plot"/>
</div> but this will work: <div style="height: 60vh">
<div id="plot" style="height: inherit"/>
</div> This particular use case came up in Dash (see https://community.plot.ly/t/cant-seem-to-change-default-height-on-graph/6742/28?u=chriddyp and the previous comment). |
Thank you @chriddyp! One can also style the div#plot directly: <div id="plot" style="height: 50vh"/> This feels more natural to me. Can we do that easily from Dash? |
Yup, that works too! I originally mentioned that in the Dash forum (see https://community.plot.ly/t/cant-seem-to-change-default-height-on-graph/6742/14?u=chriddyp) but it seems like some folks were still getting tripped up by styling the containers for their graphs one further level up (the graph's parent). |
I think @antoinerg 's Closing, but please comment if you think there's more to the story. |
I have an issue where the map is overflowing out of the screen in a sort of carousel, every container div for the plot is width: 100%, however, the plot is defaulting to 100px so when it comes in it's 100px until I resize the screen. I've also done this https://plot.ly/javascript/responsive-fluid-layout/. |
Hello @Renkinjutsu ! In order to help you with your issue, we would need a Codepen reproducing the issue. Thanks! |
This is still an issue. Height of figures is 450px unless you set it explicitly using px or vh/vw. Spent an extraordinarily long time banging my head against the wall on this one. |
Can't change image height yet, just the width! |
Setting Parent Height to 100% with layeout ={resposnive : true} resolved the problem |
now that I am using columns in Dash, I am struggling with responsive chart widths. chart areas keep getting stretched or pushed off the page. it feels like i need %s that will adjust w the containers dimensions. could probably wrap it in a div or something |
@tdpetrou I was in the same situation until I found another maybe more "elegant" solution (Because responsive: true should be set by default... So I can't understand why set it to true should solve this) |
I didn't use Dash but Plotly in Python Flask directly. |
One more thing is that this is actually using the plotly-build-in CSS but not the CSS we normally use. I did try to use a div container in the original HTML file and tried to set the style but failed. THIS MUST BE DONE IN THE plotly-build-in div container. |
Use "inspect" in your browser to see the class names of the containers that plotly have made for your layout. then make a separate .css file and override your style for the identified classes. |
Hi, how can I set the width of the svg chart according to viewport width? I tried using
width: '80vw'
in layout, but plotly doesn't seem to parse thevw
units. Appreciate any help!The text was updated successfully, but these errors were encountered: