mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
Don's start at zero so growth is beter visible + calc sum state correctly (#9672)
This commit is contained in:
parent
6fd85e043b
commit
b6055062c6
@ -133,6 +133,7 @@ class StatisticsChart extends LitElement {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
|
beginAtZero: false,
|
||||||
ticks: {
|
ticks: {
|
||||||
maxTicksLimit: 7,
|
maxTicksLimit: 7,
|
||||||
},
|
},
|
||||||
@ -328,6 +329,8 @@ class StatisticsChart extends LitElement {
|
|||||||
|
|
||||||
let prevDate: Date | null = null;
|
let prevDate: Date | null = null;
|
||||||
// Process chart data.
|
// Process chart data.
|
||||||
|
let initVal: number | null = null;
|
||||||
|
let prevSum: number | null = null;
|
||||||
stats.forEach((stat) => {
|
stats.forEach((stat) => {
|
||||||
const date = new Date(stat.start);
|
const date = new Date(stat.start);
|
||||||
if (prevDate === date) {
|
if (prevDate === date) {
|
||||||
@ -338,7 +341,12 @@ class StatisticsChart extends LitElement {
|
|||||||
statTypes.forEach((type) => {
|
statTypes.forEach((type) => {
|
||||||
let val: number | null;
|
let val: number | null;
|
||||||
if (type === "sum") {
|
if (type === "sum") {
|
||||||
val = stat.state;
|
if (!initVal) {
|
||||||
|
initVal = val = stat.state;
|
||||||
|
prevSum = stat.sum;
|
||||||
|
} else {
|
||||||
|
val = initVal + ((stat.sum || 0) - prevSum!);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val = stat[type];
|
val = stat[type];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user