From 49c7dad6eb257c067e9182d75583beb8fefeca89 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Fri, 8 Aug 2025 09:43:59 +0300 Subject: [PATCH] Font improvements for Sankey chart (#26438) * Use theme vars for sankey chart font * improve font size calculation --- src/components/chart/ha-chart-base.ts | 7 +++++++ src/components/chart/ha-sankey-chart.ts | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index 9c12fb904c..3d5ae876b5 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -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 }, diff --git a/src/components/chart/ha-sankey-chart.ts b/src/components/chart/ha-sankey-chart.ts index 67ba9a4f12..b10e3c19e2 100644 --- a/src/components/chart/ha-sankey-chart.ts +++ b/src/components/chart/ha-sankey-chart.ts @@ -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 {