Another fix for history chart axis rounding (#25852)

This commit is contained in:
Petar Petrov 2025-06-22 13:11:29 +03:00 committed by Bram Kragten
parent e6fbe0d538
commit 1a8ff83e2d

View File

@ -731,20 +731,17 @@ export class StateHistoryChartLine extends LitElement {
} }
private _formatYAxisLabel = (value: number) => { private _formatYAxisLabel = (value: number) => {
const formatOptions =
value >= 1 || value <= -1
? undefined
: {
// show the first significant digit for tiny values // show the first significant digit for tiny values
maximumFractionDigits: Math.max( const maximumFractionDigits = Math.max(
2, 1,
// use the difference to the previous value to determine the number of significant digits #25526 // use the difference to the previous value to determine the number of significant digits #25526
-Math.floor( -Math.floor(
Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1)) Math.log10(Math.abs(value - this._previousYAxisLabelValue || 1))
) )
), );
}; const label = formatNumber(value, this.hass.locale, {
const label = formatNumber(value, this.hass.locale, formatOptions); maximumFractionDigits,
});
const width = measureTextWidth(label, 12) + 5; const width = measureTextWidth(label, 12) + 5;
if (width > this._yWidth) { if (width > this._yWidth) {
this._yWidth = width; this._yWidth = width;