Font improvements for Sankey chart (#26438)

* Use theme vars for sankey chart font

* improve font size calculation
This commit is contained in:
Petar Petrov 2025-08-08 09:43:59 +03:00 committed by GitHub
parent 521c3d40b7
commit 49c7dad6eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -598,6 +598,13 @@ export class HaChartBase extends LitElement {
textBorderWidth: 2,
},
},
sankey: {
label: {
color: style.getPropertyValue("--primary-text-color"),
textBorderColor: style.getPropertyValue("--primary-background-color"),
textBorderWidth: 2,
},
},
categoryAxis: {
axisLine: { show: false },
axisTick: { show: false },

View File

@ -197,12 +197,9 @@ export class HaSankeyChart extends LitElement {
};
}
// estimate the number of lines after the label is wrapped
// this is a very rough estimate, but it works for now
const lineCount = Math.ceil(params.labelRect.width / labelSpace);
// `overflow: "break"` allows the label to overflow outside its height, so we need to account for that
const availableHeight = params.rect.height + 8; // account for the margin
const fontSize = Math.min(
(params.rect.height / lineCount) * FONT_SIZE,
(availableHeight / params.labelRect.height) * FONT_SIZE,
FONT_SIZE
);
return {