mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Echarts: fix Y scaling (#23988)
* Echarts: fix scaling of Y axis * fix fit logic to only extend the limits * handle invalid min for log scale
This commit is contained in:
parent
0197e32783
commit
6e39242ca3
@ -187,6 +187,11 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
) {
|
) {
|
||||||
const dayDifference = differenceInDays(this.endTime, this.startTime);
|
const dayDifference = differenceInDays(this.endTime, this.startTime);
|
||||||
const rtl = computeRTL(this.hass);
|
const rtl = computeRTL(this.hass);
|
||||||
|
const minYAxis =
|
||||||
|
// log(0) is -Infinity, so we need to set a minimum value
|
||||||
|
this.logarithmicScale && typeof this.minYAxis === "number"
|
||||||
|
? Math.max(this.minYAxis, 0.1)
|
||||||
|
: this.minYAxis;
|
||||||
this._chartOptions = {
|
this._chartOptions = {
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: "time",
|
type: "time",
|
||||||
@ -213,8 +218,14 @@ export class StateHistoryChartLine extends LitElement {
|
|||||||
yAxis: {
|
yAxis: {
|
||||||
type: this.logarithmicScale ? "log" : "value",
|
type: this.logarithmicScale ? "log" : "value",
|
||||||
name: this.unit,
|
name: this.unit,
|
||||||
min: this.fitYData ? this.minYAxis : undefined,
|
min:
|
||||||
max: this.fitYData ? this.maxYAxis : undefined,
|
this.fitYData && typeof minYAxis === "number"
|
||||||
|
? ({ min }) => Math.min(min, minYAxis!)
|
||||||
|
: minYAxis,
|
||||||
|
max:
|
||||||
|
this.fitYData && typeof this.maxYAxis === "number"
|
||||||
|
? ({ max }) => Math.max(max, this.maxYAxis!)
|
||||||
|
: this.maxYAxis,
|
||||||
position: rtl ? "right" : "left",
|
position: rtl ? "right" : "left",
|
||||||
scale: true,
|
scale: true,
|
||||||
nameGap: 2,
|
nameGap: 2,
|
||||||
|
@ -251,9 +251,15 @@ export class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
position: computeRTL(this.hass) ? "right" : "left",
|
position: computeRTL(this.hass) ? "right" : "left",
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
scale: this.chartType !== "bar",
|
scale: true,
|
||||||
min: this.fitYData ? undefined : this.minYAxis,
|
min:
|
||||||
max: this.fitYData ? undefined : this.maxYAxis,
|
this.fitYData && typeof this.minYAxis === "number"
|
||||||
|
? ({ min }) => Math.min(min, this.minYAxis!)
|
||||||
|
: this.minYAxis,
|
||||||
|
max:
|
||||||
|
this.fitYData && typeof this.maxYAxis === "number"
|
||||||
|
? ({ max }) => Math.max(max, this.maxYAxis!)
|
||||||
|
: this.maxYAxis,
|
||||||
splitLine: {
|
splitLine: {
|
||||||
show: true,
|
show: true,
|
||||||
lineStyle: splitLineStyle,
|
lineStyle: splitLineStyle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user