Skip to content

Commit

Permalink
fix(html/common): correct BreakdownTable tooltip height calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Clements <[email protected]>
  • Loading branch information
jeclrsg committed Nov 3, 2023
1 parent 3d813a0 commit c73fb2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/common/src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,10 @@ export function textSize(_text: string | string[], fontName: string = "Verdana",
g_fontSizeContext.font = `${bold ? "bold " : ""}${fontSize}px ${fontName}`;
g_fontSizeContextCache[hash] = retVal = {
width: Math.max(...text.map(t => g_fontSizeContext.measureText("" + t).width)),
height: fontSize * text.length
height: Math.max(...text.map(t => {
const textMeasurement = g_fontSizeContext.measureText("" + t);
return textMeasurement.fontBoundingBoxDescent + textMeasurement.fontBoundingBoxAscent;
}))
};
}
return retVal;
Expand Down
12 changes: 6 additions & 6 deletions packages/html/src/BreakdownTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class BreakdownTable extends StyledTable {
this._tooltip
.tooltipHTML(data => {
const rowCount = this.useCalculatedRowCount() ? this.calculateRowCount() : this.rowCount();
const rowHeight = this.fontSize();
const widestLabel = Math.max(...data.map(row => this.textSize(row[0], "Verdana", this.fontSize()).width));
const rowHeight = Math.max(...data.map(row => this.textSize(row[0], this.fontFamily(), this.fontSize()).height)) ?? this.fontSize();
const widestLabel = Math.max(...data.map(row => this.textSize(row[0], this.fontFamily(), this.fontSize()).width));
const widestPerc = 30;
const colCount = 2;
const w = colCount * (widestLabel + widestPerc) + (this._tooltip.padding() * 2);
Expand All @@ -65,13 +65,13 @@ export class BreakdownTable extends StyledTable {
return `<div style="
width: 100%;
height: 100%;
font-size: ${this.fontSize()}px
">${
otherData.map(row => `<div style="
font-size: ${this.fontSize()}px;
">${otherData.map(row =>
`<div style="
float:left;
width:${Math.floor(99 / colCount)}%;
">${row[0]}: ${row[1]}</div>`
).join("")
).join("")
}</div>`;
})
;
Expand Down

0 comments on commit c73fb2a

Please sign in to comment.