From 726ed326262b6a0f087f3c66b76bf3cef0e9c03e Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 21 Sep 2022 14:26:17 +0200 Subject: [PATCH] Drop absolute sum option --- src/components/chart/statistics-chart.ts | 22 ++++++------------- .../hui-statistics-graph-card-editor.ts | 3 +-- src/translations/en.json | 6 ++--- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/components/chart/statistics-chart.ts b/src/components/chart/statistics-chart.ts index c4e464c5d4..ea566c9fc7 100644 --- a/src/components/chart/statistics-chart.ts +++ b/src/components/chart/statistics-chart.ts @@ -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 = { 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 = []; 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]; diff --git a/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts index a843f8b077..540ce0ea61 100644 --- a/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts @@ -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 diff --git a/src/translations/en.json b/src/translations/en.json index c31542a657..75e0a794af 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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": {