Round log scale limits (#24151)

This commit is contained in:
Petar Petrov 2025-02-10 11:12:12 +02:00 committed by GitHub
parent f3d55447ca
commit b0b06a2787
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View File

@ -222,14 +222,14 @@ export class StateHistoryChartLine extends LitElement {
minYAxis = ({ min }) => Math.min(min, this.minYAxis!); minYAxis = ({ min }) => Math.min(min, this.minYAxis!);
} }
} else if (this.logarithmicScale) { } else if (this.logarithmicScale) {
minYAxis = ({ min }) => (min > 0 ? min * 0.95 : min * 1.05); minYAxis = ({ min }) => Math.floor(min > 0 ? min * 0.95 : min * 1.05);
} }
if (typeof maxYAxis === "number") { if (typeof maxYAxis === "number") {
if (this.fitYData) { if (this.fitYData) {
maxYAxis = ({ max }) => Math.max(max, this.maxYAxis!); maxYAxis = ({ max }) => Math.max(max, this.maxYAxis!);
} }
} else if (this.logarithmicScale) { } else if (this.logarithmicScale) {
maxYAxis = ({ max }) => (max > 0 ? max * 1.05 : max * 0.95); maxYAxis = ({ max }) => Math.ceil(max > 0 ? max * 1.05 : max * 0.95);
} }
this._chartOptions = { this._chartOptions = {
xAxis: { xAxis: {

View File

@ -237,14 +237,14 @@ export class StatisticsChart extends LitElement {
minYAxis = ({ min }) => Math.min(min, this.minYAxis!); minYAxis = ({ min }) => Math.min(min, this.minYAxis!);
} }
} else if (this.logarithmicScale) { } else if (this.logarithmicScale) {
minYAxis = ({ min }) => (min > 0 ? min * 0.95 : min * 1.05); minYAxis = ({ min }) => Math.floor(min > 0 ? min * 0.95 : min * 1.05);
} }
if (typeof maxYAxis === "number") { if (typeof maxYAxis === "number") {
if (this.fitYData) { if (this.fitYData) {
maxYAxis = ({ max }) => Math.max(max, this.maxYAxis!); maxYAxis = ({ max }) => Math.max(max, this.maxYAxis!);
} }
} else if (this.logarithmicScale) { } else if (this.logarithmicScale) {
maxYAxis = ({ max }) => (max > 0 ? max * 1.05 : max * 0.95); maxYAxis = ({ max }) => Math.ceil(max > 0 ? max * 1.05 : max * 0.95);
} }
const endTime = this.endTime ?? new Date(); const endTime = this.endTime ?? new Date();
let startTime = this.startTime; let startTime = this.startTime;
@ -290,7 +290,6 @@ export class StatisticsChart extends LitElement {
align: "left", align: "left",
}, },
position: computeRTL(this.hass) ? "right" : "left", position: computeRTL(this.hass) ? "right" : "left",
// @ts-ignore
scale: true, scale: true,
min: this._clampYAxis(minYAxis), min: this._clampYAxis(minYAxis),
max: this._clampYAxis(maxYAxis), max: this._clampYAxis(maxYAxis),