mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 13:37:47 +00:00
Drop absolute sum option
This commit is contained in:
parent
87dedeb9b3
commit
726ed32626
@ -30,14 +30,13 @@ import {
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import "./ha-chart-base";
|
||||
|
||||
export type ExtendedStatisticType = StatisticType | "state" | "sum_rel";
|
||||
export type ExtendedStatisticType = StatisticType | "state";
|
||||
|
||||
export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
|
||||
mean: "mean",
|
||||
min: "min",
|
||||
max: "max",
|
||||
sum: "sum",
|
||||
sum_rel: "sum",
|
||||
state: "sum",
|
||||
};
|
||||
@customElement("statistics-chart")
|
||||
@ -345,14 +344,7 @@ class StatisticsChart extends LitElement {
|
||||
|
||||
let prevDate: Date | null = null;
|
||||
// Process chart data.
|
||||
const initVal: Record<"sum" | "sum_rel", number | null> = {
|
||||
sum: null,
|
||||
sum_rel: null,
|
||||
};
|
||||
const prevSum: Record<"sum" | "sum_rel", number | null> = {
|
||||
sum: null,
|
||||
sum_rel: null,
|
||||
};
|
||||
let prevSum: number | null = null;
|
||||
stats.forEach((stat) => {
|
||||
const date = new Date(stat.start);
|
||||
if (prevDate === date) {
|
||||
@ -362,12 +354,12 @@ class StatisticsChart extends LitElement {
|
||||
const dataValues: Array<number | null> = [];
|
||||
statTypes.forEach((type) => {
|
||||
let val: number | null;
|
||||
if (type === "sum" || type === "sum_rel") {
|
||||
if (initVal[type] === null) {
|
||||
initVal[type] = val = type === "sum_rel" ? 0 : stat.sum || 0;
|
||||
prevSum[type] = stat.sum;
|
||||
if (type === "sum") {
|
||||
if (prevSum === null) {
|
||||
val = 0;
|
||||
prevSum = stat.sum;
|
||||
} else {
|
||||
val = initVal[type]! + ((stat.sum || 0) - prevSum[type]!);
|
||||
val = (stat.sum || 0) - prevSum;
|
||||
}
|
||||
} else {
|
||||
val = stat[type];
|
||||
|
@ -41,7 +41,6 @@ import { statTypeMap } from "../../../../components/chart/statistics-chart";
|
||||
const statTypeStruct = union([
|
||||
literal("state"),
|
||||
literal("sum"),
|
||||
literal("sum_rel"),
|
||||
literal("min"),
|
||||
literal("max"),
|
||||
literal("mean"),
|
||||
@ -67,7 +66,7 @@ const cardConfigStruct = assign(
|
||||
);
|
||||
|
||||
const periods = ["5minute", "hour", "day", "month"] as const;
|
||||
const stat_types = ["mean", "min", "max", "sum", "sum_rel", "state"] as const;
|
||||
const stat_types = ["mean", "min", "max", "sum", "state"] as const;
|
||||
|
||||
@customElement("hui-statistics-graph-card-editor")
|
||||
export class HuiStatisticsGraphCardEditor
|
||||
|
@ -518,8 +518,7 @@
|
||||
"max": "max",
|
||||
"mean": "mean",
|
||||
"state": "state",
|
||||
"sum": "sum",
|
||||
"sum_rel": "change"
|
||||
"sum": "sum"
|
||||
}
|
||||
},
|
||||
"service-picker": {
|
||||
@ -3972,8 +3971,7 @@
|
||||
"min": "Min",
|
||||
"max": "Max",
|
||||
"state": "State",
|
||||
"sum": "Sum (absolute)",
|
||||
"sum_rel": "Change"
|
||||
"sum": "Sum (change during period)"
|
||||
},
|
||||
"chart_type": "Chart type",
|
||||
"periods": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user