-
Notifications
You must be signed in to change notification settings - Fork 62
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
fix(html/common): correct BreakdownTable tooltip height calculation #4140
fix(html/common): correct BreakdownTable tooltip height calculation #4140
Conversation
cb60419
to
c73fb2a
Compare
packages/common/src/Utility.ts
Outdated
height: fontSize * text.length | ||
height: Math.max(...text.map(t => { | ||
const textMeasurement = g_fontSizeContext.measureText("" + t); | ||
return textMeasurement.fontBoundingBoxDescent + textMeasurement.fontBoundingBoxAscent; |
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.
Based upon these docs https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics#examples
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.
- The result still needs to be multiplied by
text.length
- (optional) The calculation for width and height could be moved into a single
text.reduce
function.
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.
I couldn't think of a way to make text.reduce
work, because the type of the accumulator must that of the individual items in the array, rather than whatever you want, eg an object containing the dimensions.
packages/common/src/Utility.ts
Outdated
height: fontSize * text.length | ||
height: Math.max(...text.map(t => { | ||
const textMeasurement = g_fontSizeContext.measureText("" + t); | ||
return textMeasurement.fontBoundingBoxDescent + textMeasurement.fontBoundingBoxAscent; |
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.
- The result still needs to be multiplied by
text.length
- (optional) The calculation for width and height could be moved into a single
text.reduce
function.
6c79ae6
to
8ddf098
Compare
packages/common/src/Utility.ts
Outdated
@@ -736,11 +736,17 @@ export function textSize(_text: string | string[], fontName: string = "Verdana", | |||
const hash = `${bold}::${fontSize}::${fontName}::${text.join("::")}`; | |||
let retVal = g_fontSizeContextCache[hash]; | |||
if (!retVal) { | |||
let dimensions: TextSize = { width: 0, height: 0 }; |
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.
Change to retVal = { width: 0, height: 0 };
And then remove dimension below...
Signed-off-by: Jeremy Clements <[email protected]>
8ddf098
to
5c77723
Compare
Checklist:
Testing: