mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Round chart limits with fit_y_data (#25851)
This commit is contained in:
parent
5ac6781f7d
commit
e6fbe0d538
@ -226,22 +226,24 @@ export class StateHistoryChartLine extends LitElement {
|
||||
this.maxYAxis;
|
||||
if (typeof minYAxis === "number") {
|
||||
if (this.fitYData) {
|
||||
minYAxis = ({ min }) => Math.min(min, this.minYAxis!);
|
||||
minYAxis = ({ min }) =>
|
||||
Math.min(this._roundYAxis(min, Math.floor), this.minYAxis!);
|
||||
}
|
||||
} else if (this.logarithmicScale) {
|
||||
minYAxis = ({ min }) => {
|
||||
const value = min > 0 ? min * 0.95 : min * 1.05;
|
||||
return Math.abs(value) < 1 ? value : Math.floor(value);
|
||||
return this._roundYAxis(value, Math.floor);
|
||||
};
|
||||
}
|
||||
if (typeof maxYAxis === "number") {
|
||||
if (this.fitYData) {
|
||||
maxYAxis = ({ max }) => Math.max(max, this.maxYAxis!);
|
||||
maxYAxis = ({ max }) =>
|
||||
Math.max(this._roundYAxis(max, Math.ceil), this.maxYAxis!);
|
||||
}
|
||||
} else if (this.logarithmicScale) {
|
||||
maxYAxis = ({ max }) => {
|
||||
const value = max > 0 ? max * 1.05 : max * 0.95;
|
||||
return Math.abs(value) < 1 ? value : Math.ceil(value);
|
||||
return this._roundYAxis(value, Math.ceil);
|
||||
};
|
||||
}
|
||||
this._chartOptions = {
|
||||
@ -767,6 +769,10 @@ export class StateHistoryChartLine extends LitElement {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private _roundYAxis(value: number, roundingFn: (value: number) => number) {
|
||||
return Math.abs(value) < 1 ? value : roundingFn(value);
|
||||
}
|
||||
}
|
||||
customElements.define("state-history-chart-line", StateHistoryChartLine);
|
||||
|
||||
|
@ -238,22 +238,24 @@ export class StatisticsChart extends LitElement {
|
||||
this.maxYAxis;
|
||||
if (typeof minYAxis === "number") {
|
||||
if (this.fitYData) {
|
||||
minYAxis = ({ min }) => Math.min(min, this.minYAxis!);
|
||||
minYAxis = ({ min }) =>
|
||||
Math.min(this._roundYAxis(min, Math.floor), this.minYAxis!);
|
||||
}
|
||||
} else if (this.logarithmicScale) {
|
||||
minYAxis = ({ min }) => {
|
||||
const value = min > 0 ? min * 0.95 : min * 1.05;
|
||||
return Math.abs(value) < 1 ? value : Math.floor(value);
|
||||
return this._roundYAxis(value, Math.floor);
|
||||
};
|
||||
}
|
||||
if (typeof maxYAxis === "number") {
|
||||
if (this.fitYData) {
|
||||
maxYAxis = ({ max }) => Math.max(max, this.maxYAxis!);
|
||||
maxYAxis = ({ max }) =>
|
||||
Math.max(this._roundYAxis(max, Math.ceil), this.maxYAxis!);
|
||||
}
|
||||
} else if (this.logarithmicScale) {
|
||||
maxYAxis = ({ max }) => {
|
||||
const value = max > 0 ? max * 1.05 : max * 0.95;
|
||||
return Math.abs(value) < 1 ? value : Math.ceil(value);
|
||||
return this._roundYAxis(value, Math.ceil);
|
||||
};
|
||||
}
|
||||
const endTime = this.endTime ?? new Date();
|
||||
@ -634,6 +636,10 @@ export class StatisticsChart extends LitElement {
|
||||
return value;
|
||||
}
|
||||
|
||||
private _roundYAxis(value: number, roundingFn: (value: number) => number) {
|
||||
return Math.abs(value) < 1 ? value : roundingFn(value);
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: block;
|
||||
|
Loading…
x
Reference in New Issue
Block a user