GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: Recalculate bounding boxes after fonts load by camdecoster · Pull Request #8094 · plotly/plotly.js Conversation
|
| Before | After |
|---|---|
![]() |
![]() |
// A new family and URL on every run, so the plot always draws before the font arrives const family = `JetBrainsMono${Date.now()}`; const face = new FontFace( family, `url(https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/files/jetbrains-mono-latin-400-normal.woff2?v=${Math.random()})` ); document.fonts.add(face); const gd = Tabs.fresh(); Plotly.newPlot( gd, [ { type: 'bar', x: ['NO', 'DE', 'CA'], y: [30, 12, 10], name: 'Gold: a test of sizes' }, { type: 'bar', x: ['NO', 'DE', 'CA'], y: [8, 10, 5], name: 'Silver: a second test of sizes' } ], { font: { family, size: 13 }, legend: { borderwidth: 1, x: 0.02, y: 0.98 }, width: 500, height: 300, annotations: [ { x: 1.02, y: 0, xref: 'paper', yref: 'paper', xanchor: 'left', yanchor: 'bottom', text: 'Source: official list', textangle: -90, showarrow: false, bgcolor: 'rgba(0,0,0,0.15)', borderwidth: 1 } ] } );
| Plots | First draw | Redraws after the font loads |
|---|---|---|
| 1 small bar chart | 18 ms | 21 ms |
| 20 small bar charts (3 runs) | 112-139 ms | 94-185 ms |
| 1 plot with a 50,000-point SVG scatter | 596 ms | 593 ms |
| 20 plots with a 5,000-point SVG scatter each | 1.6 s | 1.3 s |
plotly_beforeplot and plotly_afterplot againawait document.fonts.load('12px "Open Sans"'); await Plotly.newPlot(gd, data, layout);
document.fonts.ready does not work for this, because ready does not start the load of a font that no text uses yetloadingdone event on the document fontsgl-axes3d caches each label mesh by font family for the life of the page, so gl3d labels keep the fallback font after the redraw.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| */ | ||
| async function redrawAfterFontLoads(gd, unloadedFaces) { | ||
| // The draw started these loads, or they finished during the draw | ||
| const faces = unloadedFaces.filter((face) => ['loaded', 'loading'].includes(face.status)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
So the other options apparently are unloaded and error (or possibly failed, MDN is inconsistent about this). Makes sense to ignore errors at this point, as there's nothing more to wait for. Can we be confident that every relevant font will have been transitioned from unloaded to loading synchronously? I guess we have to assume this, as looking at an existing site I see various fonts staying indefinitely in the unloaded state, presumably because it was declared but never used on the page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think we can be confident in this. That's why my testing showed. If real world use tells a different story, we can tweak the check (or force the fonts to load ourselves).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[BUG]: Text extents are not recomputed after web font loading
There was an error while loading. Please reload this page.