From 8ba46f7f57572ef7cca3cbe30089940f09cb3e91 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Tue, 6 Dec 2022 01:41:08 +0100 Subject: [PATCH] Add "show_names" option to history graphs (#14546) --- src/components/chart/state-history-chart-line.ts | 4 ++-- src/components/chart/state-history-chart-timeline.ts | 5 ++--- src/components/chart/state-history-charts.ts | 8 +++----- src/dialogs/more-info/ha-more-info-history.ts | 2 ++ src/panels/history/ha-panel-history.ts | 1 - src/panels/lovelace/cards/hui-history-graph-card.ts | 2 +- src/panels/lovelace/cards/types.ts | 1 + .../config-elements/hui-history-graph-card-editor.ts | 2 ++ 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/chart/state-history-chart-line.ts b/src/components/chart/state-history-chart-line.ts index 85bb575985..488fc9ee58 100644 --- a/src/components/chart/state-history-chart-line.ts +++ b/src/components/chart/state-history-chart-line.ts @@ -26,7 +26,7 @@ class StateHistoryChartLine extends LitElement { @property() public identifier?: string; - @property({ type: Boolean }) public isSingleDevice = false; + @property({ type: Boolean }) public showNames = true; @property({ attribute: false }) public endTime!: Date; @@ -101,7 +101,7 @@ class StateHistoryChartLine extends LitElement { propagate: true, }, legend: { - display: !this.isSingleDevice, + display: this.showNames, labels: { usePointStyle: true, }, diff --git a/src/components/chart/state-history-chart-timeline.ts b/src/components/chart/state-history-chart-timeline.ts index fd98de2125..680bf9ae2c 100644 --- a/src/components/chart/state-history-chart-timeline.ts +++ b/src/components/chart/state-history-chart-timeline.ts @@ -83,7 +83,7 @@ export class StateHistoryChartTimeline extends LitElement { @property() public identifier?: string; - @property({ type: Boolean }) public isSingleDevice = false; + @property({ type: Boolean }) public showNames = true; @property({ type: Boolean }) public chunked = false; @@ -175,8 +175,7 @@ export class StateHistoryChartTimeline extends LitElement { drawTicks: false, }, ticks: { - display: - this.chunked || !this.isSingleDevice || this.data.length !== 1, + display: this.chunked || this.showNames, }, afterSetDimensions: (y) => { y.maxWidth = y.chart.width * 0.18; diff --git a/src/components/chart/state-history-charts.ts b/src/components/chart/state-history-charts.ts index 415ecbb4e7..a4f467cfd8 100644 --- a/src/components/chart/state-history-charts.ts +++ b/src/components/chart/state-history-charts.ts @@ -48,7 +48,7 @@ class StateHistoryCharts extends LitElement { @property({ type: Boolean, attribute: "up-to-now" }) public upToNow = false; - @property({ type: Boolean, attribute: "no-single" }) public noSingle = false; + @property({ type: Boolean }) public showNames = true; @property({ type: Boolean }) public isLoadingData = false; @@ -128,8 +128,7 @@ class StateHistoryCharts extends LitElement { .unit=${item.unit} .data=${item.data} .identifier=${item.identifier} - .isSingleDevice=${!this.noSingle && - this.historyData.line?.length === 1} + .showNames=${this.showNames} .endTime=${this._computedEndTime} .names=${this.names} > @@ -141,8 +140,7 @@ class StateHistoryCharts extends LitElement { .data=${item} .startTime=${this._computedStartTime} .endTime=${this._computedEndTime} - .isSingleDevice=${!this.noSingle && - this.historyData.timeline?.length === 1} + .showNames=${this.showNames} .names=${this.names} .narrow=${this.narrow} .chunked=${this.virtualize} diff --git a/src/dialogs/more-info/ha-more-info-history.ts b/src/dialogs/more-info/ha-more-info-history.ts index 105fd43c63..a9f30604f1 100644 --- a/src/dialogs/more-info/ha-more-info-history.ts +++ b/src/dialogs/more-info/ha-more-info-history.ts @@ -67,12 +67,14 @@ export class MoreInfoHistory extends LitElement { .statTypes=${statTypes} .names=${this._statNames} hideLegend + .showNames=${false} >` : html``}` : ""}`; } diff --git a/src/panels/history/ha-panel-history.ts b/src/panels/history/ha-panel-history.ts index 8f07895d24..f78ca6b0ec 100644 --- a/src/panels/history/ha-panel-history.ts +++ b/src/panels/history/ha-panel-history.ts @@ -163,7 +163,6 @@ class HaPanelHistory extends SubscribeMixin(LitElement) { .hass=${this.hass} .historyData=${this._stateHistory} .endTime=${this._endDate} - no-single > `} diff --git a/src/panels/lovelace/cards/hui-history-graph-card.ts b/src/panels/lovelace/cards/hui-history-graph-card.ts index a94a1b521b..eda1fa1239 100644 --- a/src/panels/lovelace/cards/hui-history-graph-card.ts +++ b/src/panels/lovelace/cards/hui-history-graph-card.ts @@ -144,7 +144,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { .historyData=${this._stateHistory} .names=${this._names} up-to-now - no-single + .showNames=${this._config.show_names} > diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index 5bde49b650..0e3bea773d 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -300,6 +300,7 @@ export interface HistoryGraphCardConfig extends LovelaceCardConfig { hours_to_show?: number; refresh_interval?: number; title?: string; + show_names?: boolean; } export interface StatisticsGraphCardConfig extends LovelaceCardConfig { diff --git a/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts index fb9e05f42f..8ca713ba7b 100644 --- a/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts @@ -4,6 +4,7 @@ import { customElement, property, state } from "lit/decorators"; import { array, assert, + boolean, number, object, optional, @@ -28,6 +29,7 @@ const cardConfigStruct = assign( title: optional(string()), hours_to_show: optional(number()), refresh_interval: optional(number()), + show_names: optional(boolean()), }) );