-
Notifications
You must be signed in to change notification settings - Fork 22
Improved mini-table resource name truncation #3182
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
Open
benjaminleonard
wants to merge
13
commits into
main
Choose a base branch
from
fix-minitable-name-truncation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9fc620d
Improved mini-table resource name truncation
benjaminleonard 3c126af
Typefix
benjaminleonard 461fc51
Ue text width measurement for column widths
benjaminleonard 7514019
Fmt
benjaminleonard 6885f2a
Use `measureText` instead
benjaminleonard 148a9ac
Conditionally render tooltip if truncated
benjaminleonard 5823bf1
merge main, resolve ValueUnit conflicts
david-crespo 03f198b
cleaner mini-table column width props
david-crespo 9428517
refactor useColumnWidths so I can understand it
david-crespo a2f2241
whitespace-nowrap on cell
david-crespo 3d551d0
merge hoisted columns from main
david-crespo 31f73bb
lil code tweaks
david-crespo cffb818
Remove text width measurement cache
david-crespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
|
|
||
| let ctx: CanvasRenderingContext2D | null = null | ||
|
|
||
| function getContext(): CanvasRenderingContext2D { | ||
| if (!ctx) { | ||
| const canvas = document.createElement('canvas') | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- offscreen canvas always has 2d context | ||
| ctx = canvas.getContext('2d')! | ||
| } | ||
| return ctx | ||
| } | ||
|
|
||
| /** | ||
| * Measure the rendered pixel width of `text` using Canvas `measureText`. | ||
| * Accounts for font shaping, kerning, and letter-spacing. Reuses a single | ||
| * offscreen canvas context. | ||
| */ | ||
| export function textWidth(text: string, font: string, letterSpacing = '0px'): number { | ||
| const context = getContext() | ||
| context.font = font | ||
| context.letterSpacing = letterSpacing | ||
| return context.measureText(text).width | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is relatively quick, though you could certainly give up a meaningful chunk of the render cycle calculating a sufficiently large table (i mean on the order of, say, thousands of unique cells). realistically i'm not sure that's a reachable scale, but given the constraints on names (which are most of these columns), i'd wager that
text.lengthis a good-enough estimation that also eliminates the need for a cacheThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this specific use case ... perhaps. Though it depends very much on the character choice and combinations. For columns as narrow as these get that effect can be quite pronounced.
I mention it briefly here: #3182 (comment)
Would also say there's value in consistency beyond this use case. That's to say, rather than adding an exemption here and using string length, it's probably clearer to use text measurement everywhere (which is my recommendation for the
Truncatefunction).Mini-tables are mini, so we can safely say we're not going to be calculating significant numbers of cells.