Skip to content

Allow viewport units for font.size? #3420

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

Closed
RickAhlf opened this issue Jan 8, 2019 · 5 comments
Closed

Allow viewport units for font.size? #3420

RickAhlf opened this issue Jan 8, 2019 · 5 comments

Comments

@RickAhlf
Copy link

RickAhlf commented Jan 8, 2019

Currently I can set a header such as html.H1('Test', style={'font-size': '2vw'}), etc. to scale with the viewport width. However, when I attempt to do the same with a dcc.Graph annotation, I receive the following error:

ValueError: Invalid element(s) received for the ‘size’ property of scatter.textfont Invalid elements include: [‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’, ‘1vw’]

The 'size' property is a number and may be specified as:
  - An int or float in the interval [1, inf]
  - A tuple, list, or one-dimensional numpy array of the above

Is there a plan to implement viewport units as a valid option? Or is there a current acceptable work-around for this implementation? When I scale my viewport down to half my screen (width-wise), my text annotations tend to dominate my graphs, which is not desirable.

Here is the associated SO question I've posted: https://stackoverflow.com/q/53951814/8146556
Here is the associated Plotly-Dash forum question I've posted: https://community.plot.ly/t/font-size-for-dcc-graph-annotations-do-not-accept-viewport-units/17423?u=rahlf23

@etpinard etpinard changed the title Font-size for dcc.Graph annotations do not accept viewport units Allow viewport units for font.size? Jan 11, 2019
@antoinerg
Copy link
Contributor

antoinerg commented May 28, 2019

I think a very useful unit for font.size would be relative to the size of the figure itself. The SVG way of achieving this is to add a viewBox attribute to the svg element and let the renderer scale everything on resizing. Unfortunately, as discussed in issue #2711, this won't be easy to do and will break various things. I think we will have to compute ourselves the absolute values of font size based on the current size of the figure.

viewBox in action: https://codepen.io/antoinerg/pen/Ezpdmz

@dougdenn
Copy link

Would agree with @antoinerg and just add my vote as this is currently the most difficult thing about working with Plotly for me. I have a requirement to be able to resize Plotly within a div, so viewport units will not work for my case and font that scales to the actual size of the plot would be awesome.

Right now I'm working around this by listening to the div resize event and manually rescaling the font, but it's pretty inefficient because it requires a lot of rerendering of an expensive element.

@joshrabinowitz
Copy link

I had to implement this in javascript too, both for font sizes and for line widths.
It would be great if plotly js supported scaling/resizing line widths and font sizes dynamically as the viewport resized.

@myaleks
Copy link

myaleks commented Oct 13, 2020

hi joshrabinowitz
could you please elaborate how do you do this (scaling/resizing line widths and font sizes dynamically as the viewport resized)

@gvwilson
Copy link
Contributor

Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants