diff --git a/packages/common/src/Utility.ts b/packages/common/src/Utility.ts index b0f41af31a..78b9725de4 100644 --- a/packages/common/src/Utility.ts +++ b/packages/common/src/Utility.ts @@ -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) { + retVal = { width: 0, height: 0 }; 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 - }; + text.forEach(line => { + const textMeasurement = g_fontSizeContext.measureText("" + line); + const width = textMeasurement.width; + const height = (textMeasurement.fontBoundingBoxDescent + textMeasurement.fontBoundingBoxAscent) * text.length; + g_fontSizeContextCache[hash] = retVal = { + width: width > retVal.width ? width : retVal.width, + height: height > retVal.height ? height : retVal.height + }; + }); } return retVal; } diff --git a/packages/html/src/BreakdownTable.ts b/packages/html/src/BreakdownTable.ts index 9055793050..73f27851db 100644 --- a/packages/html/src/BreakdownTable.ts +++ b/packages/html/src/BreakdownTable.ts @@ -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); @@ -65,13 +65,13 @@ export class BreakdownTable extends StyledTable { return `
${ - otherData.map(row => `
${otherData.map(row => + `
${row[0]}: ${row[1]}
` - ).join("") + ).join("") }
`; }) ;