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

fix(html/common): correct BreakdownTable tooltip height calculation #4140

Merged

Conversation

jeclrsg
Copy link
Contributor

@jeclrsg jeclrsg commented Nov 2, 2023

Checklist:

  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit message includes a "fixes" reference if appropriate.
    • The commit is signed.
  • The change has been fully tested:
    • I have viewed all related gallery items
    • I have viewed all related dermatology items
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised new issues to address them separately

Testing:

@jeclrsg jeclrsg requested a review from GordonSmith November 2, 2023 19:39
@jeclrsg jeclrsg force-pushed the BreakdownTable-tooltip-height branch from cb60419 to c73fb2a Compare November 3, 2023 16:14
@jeclrsg jeclrsg changed the title fix(comms): correct BreakdownTable tooltip height calculation fix(html/common): correct BreakdownTable tooltip height calculation Nov 3, 2023
height: fontSize * text.length
height: Math.max(...text.map(t => {
const textMeasurement = g_fontSizeContext.measureText("" + t);
return textMeasurement.fontBoundingBoxDescent + textMeasurement.fontBoundingBoxAscent;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The result still needs to be multiplied by text.length
  2. (optional) The calculation for width and height could be moved into a single text.reduce function.

Copy link
Contributor Author

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.

height: fontSize * text.length
height: Math.max(...text.map(t => {
const textMeasurement = g_fontSizeContext.measureText("" + t);
return textMeasurement.fontBoundingBoxDescent + textMeasurement.fontBoundingBoxAscent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The result still needs to be multiplied by text.length
  2. (optional) The calculation for width and height could be moved into a single text.reduce function.

@jeclrsg jeclrsg force-pushed the BreakdownTable-tooltip-height branch 2 times, most recently from 6c79ae6 to 8ddf098 Compare November 6, 2023 15:34
@@ -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 };
Copy link
Member

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...

packages/common/src/Utility.ts Show resolved Hide resolved
@GordonSmith GordonSmith merged commit c587154 into hpcc-systems:trunk Nov 8, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants