mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Add option to hide legend on statistic graph card (#15506)
This commit is contained in:
parent
6c9d6755f1
commit
6986c1c8b7
@ -59,7 +59,7 @@ export const statTypeMap: Record<ExtendedStatisticType, StatisticType> = {
|
|||||||
class StatisticsChart extends LitElement {
|
class StatisticsChart extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public statisticsData!: Statistics;
|
@property({ attribute: false }) public statisticsData?: Statistics;
|
||||||
|
|
||||||
@property({ attribute: false }) public metadata?: Record<
|
@property({ attribute: false }) public metadata?: Record<
|
||||||
string,
|
string,
|
||||||
@ -99,7 +99,11 @@ class StatisticsChart extends LitElement {
|
|||||||
if (!this.hasUpdated || changedProps.has("unit")) {
|
if (!this.hasUpdated || changedProps.has("unit")) {
|
||||||
this._createOptions();
|
this._createOptions();
|
||||||
}
|
}
|
||||||
if (changedProps.has("statisticsData") || changedProps.has("statTypes")) {
|
if (
|
||||||
|
changedProps.has("statisticsData") ||
|
||||||
|
changedProps.has("statTypes") ||
|
||||||
|
changedProps.has("hideLegend")
|
||||||
|
) {
|
||||||
this._generateData();
|
this._generateData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,11 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getCardSize(): number {
|
public getCardSize(): number {
|
||||||
return this._config?.title ? 2 : 0 + 2 * (this._entities?.length || 1);
|
return (
|
||||||
|
5 +
|
||||||
|
(this._config?.title ? 2 : 0) +
|
||||||
|
(!this._config?.hide_legend ? this._entities?.length || 0 : 0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setConfig(config: StatisticsGraphCardConfig): void {
|
public setConfig(config: StatisticsGraphCardConfig): void {
|
||||||
@ -194,6 +198,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
|||||||
.statTypes=${this._statTypes!}
|
.statTypes=${this._statTypes!}
|
||||||
.names=${this._names}
|
.names=${this._names}
|
||||||
.unit=${this._unit}
|
.unit=${this._unit}
|
||||||
|
.hideLegend=${this._config.hide_legend || false}
|
||||||
></statistics-chart>
|
></statistics-chart>
|
||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
|
@ -312,6 +312,7 @@ export interface StatisticsGraphCardConfig extends LovelaceCardConfig {
|
|||||||
period?: "5minute" | "hour" | "day" | "month";
|
period?: "5minute" | "hour" | "day" | "month";
|
||||||
stat_types?: ExtendedStatisticType | ExtendedStatisticType[];
|
stat_types?: ExtendedStatisticType | ExtendedStatisticType[];
|
||||||
chart_type?: "line" | "bar";
|
chart_type?: "line" | "bar";
|
||||||
|
hide_legend?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StatisticCardConfig extends LovelaceCardConfig {
|
export interface StatisticCardConfig extends LovelaceCardConfig {
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
array,
|
array,
|
||||||
assert,
|
assert,
|
||||||
assign,
|
assign,
|
||||||
|
boolean,
|
||||||
literal,
|
literal,
|
||||||
number,
|
number,
|
||||||
object,
|
object,
|
||||||
@ -72,6 +73,7 @@ const cardConfigStruct = assign(
|
|||||||
chart_type: optional(union([literal("bar"), literal("line")])),
|
chart_type: optional(union([literal("bar"), literal("line")])),
|
||||||
stat_types: optional(union([array(statTypeStruct), statTypeStruct])),
|
stat_types: optional(union([array(statTypeStruct), statTypeStruct])),
|
||||||
unit: optional(string()),
|
unit: optional(string()),
|
||||||
|
hide_legend: optional(boolean()),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -204,6 +206,11 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
["bar", "Bar"],
|
["bar", "Bar"],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "hide_legend",
|
||||||
|
required: false,
|
||||||
|
selector: { boolean: {} },
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -334,6 +341,7 @@ export class HuiStatisticsGraphCardEditor
|
|||||||
case "stat_types":
|
case "stat_types":
|
||||||
case "period":
|
case "period":
|
||||||
case "unit":
|
case "unit":
|
||||||
|
case "hide_legend":
|
||||||
return this.hass!.localize(
|
return this.hass!.localize(
|
||||||
`ui.panel.lovelace.editor.card.statistics-graph.${schema.name}`
|
`ui.panel.lovelace.editor.card.statistics-graph.${schema.name}`
|
||||||
);
|
);
|
||||||
|
@ -4194,7 +4194,8 @@
|
|||||||
"5minute": "5 Minutes"
|
"5minute": "5 Minutes"
|
||||||
},
|
},
|
||||||
"pick_statistic": "Add a statistic",
|
"pick_statistic": "Add a statistic",
|
||||||
"picked_statistic": "Statistic"
|
"picked_statistic": "Statistic",
|
||||||
|
"hide_legend": "Hide legend"
|
||||||
},
|
},
|
||||||
"statistic": {
|
"statistic": {
|
||||||
"name": "Statistic",
|
"name": "Statistic",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user