From f50d5d79a43e2cfb2b84dc57f6017ce70f7ee568 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Sun, 22 Jun 2025 13:11:29 +0300 Subject: [PATCH] Another fix for history chart axis rounding (#25852) --- .../chart/state-history-chart-line.ts | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/components/chart/state-history-chart-line.ts b/src/components/chart/state-history-chart-line.ts index f8f7689539..10ba4dcb50 100644 --- a/src/components/chart/state-history-chart-line.ts +++ b/src/components/chart/state-history-chart-line.ts @@ -729,20 +729,17 @@ export class StateHistoryChartLine extends LitElement { } private _formatYAxisLabel = (value: number) => { - const formatOptions = - value >= 1 || value <= -1 - ? undefined - : { - // show the first significant digit for tiny values - maximumFractionDigits: Math.max( - 2, - // use the difference to the previous value to determine the number of significant digits #25526 - -Math.floor( - Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1)) - ) - ), - }; - const label = formatNumber(value, this.hass.locale, formatOptions); + // show the first significant digit for tiny values + const maximumFractionDigits = Math.max( + 1, + // use the difference to the previous value to determine the number of significant digits #25526 + -Math.floor( + Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1)) + ) + ); + const label = formatNumber(value, this.hass.locale, { + maximumFractionDigits, + }); const width = measureTextWidth(label, 12) + 5; if (width > this._yWidth) { this._yWidth = width;