mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix types selection for statistics-graph-card (#16988)
This commit is contained in:
parent
e9961b93f9
commit
752bc192cd
@ -260,10 +260,10 @@ export const calculateStatisticsSumGrowth = (
|
|||||||
export const statisticsHaveType = (
|
export const statisticsHaveType = (
|
||||||
stats: StatisticValue[],
|
stats: StatisticValue[],
|
||||||
type: StatisticType
|
type: StatisticType
|
||||||
) => stats.some((stat) => stat[type] !== null);
|
) => stats.some((stat) => stat[type] !== undefined && stat[type] !== null);
|
||||||
|
|
||||||
const mean_stat_types: readonly StatisticType[] = ["mean", "min", "max"];
|
const mean_stat_types: readonly StatisticType[] = ["mean", "min", "max"];
|
||||||
const sum_stat_types: readonly StatisticType[] = ["sum"];
|
const sum_stat_types: readonly StatisticType[] = ["sum", "state", "change"];
|
||||||
|
|
||||||
export const statisticsMetaHasType = (
|
export const statisticsMetaHasType = (
|
||||||
metadata: StatisticsMetaData,
|
metadata: StatisticsMetaData,
|
||||||
|
@ -187,7 +187,7 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
),
|
),
|
||||||
disabled:
|
disabled:
|
||||||
!metaDatas ||
|
!metaDatas ||
|
||||||
!metaDatas.every((metaData) =>
|
!metaDatas.some((metaData) =>
|
||||||
statisticsMetaHasType(
|
statisticsMetaHasType(
|
||||||
metaData,
|
metaData,
|
||||||
supportedStatTypeMap[stat_type]
|
supportedStatTypeMap[stat_type]
|
||||||
@ -246,12 +246,10 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
);
|
);
|
||||||
const configured_stat_types = this._config!.stat_types
|
const configured_stat_types = this._config!.stat_types
|
||||||
? ensureArray(this._config.stat_types)
|
? ensureArray(this._config.stat_types)
|
||||||
: stat_types.filter(
|
: stat_types.filter((stat_type) =>
|
||||||
(stat_type) =>
|
this._metaDatas?.some((metaData) =>
|
||||||
stat_type !== "change" &&
|
statisticsMetaHasType(metaData, stat_type)
|
||||||
this._metaDatas?.every((metaData) =>
|
)
|
||||||
statisticsMetaHasType(metaData, stat_type)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
const data = {
|
const data = {
|
||||||
chart_type: "line",
|
chart_type: "line",
|
||||||
@ -320,9 +318,7 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
: undefined;
|
: undefined;
|
||||||
if (config.stat_types && config.entities.length) {
|
if (config.stat_types && config.entities.length) {
|
||||||
config.stat_types = ensureArray(config.stat_types).filter((stat_type) =>
|
config.stat_types = ensureArray(config.stat_types).filter((stat_type) =>
|
||||||
metadata!.every((metaData) =>
|
metadata!.some((metaData) => statisticsMetaHasType(metaData, stat_type))
|
||||||
statisticsMetaHasType(metaData, stat_type)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
if (!config.stat_types.length) {
|
if (!config.stat_types.length) {
|
||||||
delete config.stat_types;
|
delete config.stat_types;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user