Skip to content
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

Highcharts and Google Fonts #6782

Closed
nedimg opened this issue May 31, 2017 · 8 comments
Closed

Highcharts and Google Fonts #6782

nedimg opened this issue May 31, 2017 · 8 comments
Labels
Status: Stale This issue hasn't had any activity for a while, and will be auto-closed if no further updates occur. Type: Bug

Comments

@nedimg
Copy link

nedimg commented May 31, 2017

Expected behaviour

Text (axis labels, data labels etc), measured and positioned properly after chart.style.fontFamily update.

Actual behaviour

Chart Y axis labels (probably other labels too) cut off due to fontFamily change. A ugly hack is needed to fix issue...

Live demo with steps to reproduce

JSFiddle

Affected browser(s)

All

@pawelfus
Copy link
Contributor

pawelfus commented Jun 1, 2017

Thank you for reporting!

@nedimg
Copy link
Author

nedimg commented Jun 2, 2017

Hi @pawelfus,
here is an update on this issue. It seems to me that the problem is in the rendering cache. The fontFamily update does not clear cached label bounding boxes (label.getBBox()) so the text measures for the updated fontFamily are wrong.

Here is a fixed version of the example i sent in my first post. As you will see, I clear the renderer.cache before update of fontFamily and the issue is gone. Chart is rendered as expected.

A possible solution would be to include fontFamily in the cacheKey. Here is a link to the source file&line. Another solution could be to make an dedicated method like setFontFamily which would clear the cache internally. Hope this will help you and a fix will come soon. Bye

@nedimg
Copy link
Author

nedimg commented Jul 3, 2017

Hi, its me again. Statement in line is the source off this issue. Numbers are not monospaced, at least not for most font families. It makes the renderer treat 10, 20 or 80 labels as same (width and height) but obviuosly that's not the case for non monospaced fonts. Renderer will measure the first two-digit label (in this case its 10) and cache its dimesions for all other two-digit labels (20 and 80) and there you have it. 20 and 80 will be cut off.

Should I make a PR to fix this issue (basically remove the cachekey alternation with regex)? Would it be helpful for your team?
Bye

@pawelfus
Copy link
Contributor

pawelfus commented Jul 7, 2017

Thank you for sharing @nedimg ! Unfortunately it doesn't seem to fix the issue you reported, please take a look: http://jsfiddle.net/zf5z2j1b/

@TorsteinHonsi
Copy link
Collaborator

Also the first option, of adding renderer.style.fontFamily to the cacheKey, seems to fail in the example. I assume this has to do with the fonts loading async, so at the time Highcharts computes the bounding boxes, the new font isn't actually applied yet.

@mszbot
Copy link

mszbot commented Oct 29, 2018

Any updates on this? Is there a workaround?

@TorsteinHonsi
Copy link
Collaborator

Workaround

So there are two problems here: First, the Highcharts bounding box cache is not cleared. Second, the chart is updated before the web fonts are loaded, thereby applying a premature bounding box.

It seems like the first problem is fixed by @nedimg's workaround above, white the second one can be fixed by using the Web Font Loader library.

See it in action: http://jsfiddle.net/highcharts/9rLpd1y1/7/

@stale
Copy link

stale bot commented Apr 28, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

@stale stale bot added the Status: Stale This issue hasn't had any activity for a while, and will be auto-closed if no further updates occur. label Apr 28, 2020
@highsoft-bot highsoft-bot added this to To do in Development-Flow via automation Apr 28, 2020
@stale stale bot closed this as completed May 5, 2020
Development-Flow automation moved this from To do to Done May 5, 2020
@Izothep Izothep removed this from Done in Development-Flow Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale This issue hasn't had any activity for a while, and will be auto-closed if no further updates occur. Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants