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