mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Handle tiny values in a log chart (#25727)
This commit is contained in:
parent
5ce5f9a189
commit
2589e1a49f
@ -229,14 +229,20 @@ 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 }) => Math.floor(min > 0 ? min * 0.95 : min * 1.05);
|
minYAxis = ({ min }) => {
|
||||||
|
const value = min > 0 ? min * 0.95 : min * 1.05;
|
||||||
|
return Math.abs(value) < 1 ? value : Math.floor(value);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
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 }) => Math.ceil(max > 0 ? max * 1.05 : max * 0.95);
|
maxYAxis = ({ max }) => {
|
||||||
|
const value = max > 0 ? max * 1.05 : max * 0.95;
|
||||||
|
return Math.abs(value) < 1 ? value : Math.ceil(value);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
this._chartOptions = {
|
this._chartOptions = {
|
||||||
xAxis: {
|
xAxis: {
|
||||||
@ -753,10 +759,10 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
if (this.logarithmicScale) {
|
if (this.logarithmicScale) {
|
||||||
// log(0) is -Infinity, so we need to set a minimum value
|
// log(0) is -Infinity, so we need to set a minimum value
|
||||||
if (typeof value === "number") {
|
if (typeof value === "number") {
|
||||||
return Math.max(value, 0.1);
|
return Math.max(value, Number.EPSILON);
|
||||||
}
|
}
|
||||||
if (typeof value === "function") {
|
if (typeof value === "function") {
|
||||||
return (values: any) => Math.max(value(values), 0.1);
|
return (values: any) => Math.max(value(values), Number.EPSILON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -241,14 +241,20 @@ 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 }) => Math.floor(min > 0 ? min * 0.95 : min * 1.05);
|
minYAxis = ({ min }) => {
|
||||||
|
const value = min > 0 ? min * 0.95 : min * 1.05;
|
||||||
|
return Math.abs(value) < 1 ? value : Math.floor(value);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
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 }) => Math.ceil(max > 0 ? max * 1.05 : max * 0.95);
|
maxYAxis = ({ max }) => {
|
||||||
|
const value = max > 0 ? max * 1.05 : max * 0.95;
|
||||||
|
return Math.abs(value) < 1 ? value : Math.ceil(value);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const endTime = this.endTime ?? new Date();
|
const endTime = this.endTime ?? new Date();
|
||||||
let startTime = this.startTime;
|
let startTime = this.startTime;
|
||||||
@ -619,10 +625,10 @@ export class StatisticsChart extends LitElement {
|
|||||||
if (this.logarithmicScale) {
|
if (this.logarithmicScale) {
|
||||||
// log(0) is -Infinity, so we need to set a minimum value
|
// log(0) is -Infinity, so we need to set a minimum value
|
||||||
if (typeof value === "number") {
|
if (typeof value === "number") {
|
||||||
return Math.max(value, 0.1);
|
return Math.max(value, Number.EPSILON);
|
||||||
}
|
}
|
||||||
if (typeof value === "function") {
|
if (typeof value === "function") {
|
||||||
return (values: any) => Math.max(value(values), 0.1);
|
return (values: any) => Math.max(value(values), Number.EPSILON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user