-
-
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
layout→font→family: 'inherit' does not work as expected #3027
Comments
Interesting - yes, we set the top-level default font here: Line 3 in 4225f9e
And it's possible that we could simply remove that, as long as we have set the font consistently across all internal elements. I'm hesitant to do that though, as The other concern is layout: because this is SVG (rather than HTML which has a layout engine) we need to render text, measure it, then manually size boxes, margins, etc to fit the text. So if the user were to render the plot and then change the font upstream, everything would be sized wrong. There's also the case where the user initially renders the plot into a div that's not attached to the DOM, and only attaches it later when the user requests that content - in that case there is no inheritance chain. So while many cases could be accommodated one way or another, this poses enough problems that I think we had better leave it as is. |
@alexcjohnson Is there a way to specify the global font family that is hard coded? Possibly a "monkey patch", something like: `Plotly.prototype.css._base["font-family"] = "Helvetica;Arial;sans-serif" |
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 |
Enabling a custom global font-family in a
plotly.js
plot is today possible using layout → font → family, which has default value"Open Sans", verdana, arial, sans-serif
. See this pen for an example of including custom font.This works well in cases where you know the font-family to use up front. In some cases
plotly.js
is used for making a plot, and the output is placed in a framework/context where the user controls the font in use.Getting
plotly.js
output to inherit the font-family currently in use could maybe potentially be as simple aslayout: {font: {family: 'inherit'}}
, however this does not currently work as there seems to be a hard-coded value of"Open Sans", verdana, arial, sans-serif
still given byplotly.js
as style attribute higher in the DOM tree (which is then inherited by theplotly.js
-created elements actually havingfont-family: inherit
).This is a stack overflow post apparently facing the same issue.
There exist workarounds like
window.getComputedStyle(my_div_element,null).getPropertyValue("font-family");
and then getplotly.js
to use the dynamically computed font-family, but it would be easier ifplotly.js
could inherit directly.The text was updated successfully, but these errors were encountered: