diff --git a/src/components/chart/state-history-chart-line.ts b/src/components/chart/state-history-chart-line.ts index d73faaf9e747..bdde57a7ad0c 100644 --- a/src/components/chart/state-history-chart-line.ts +++ b/src/components/chart/state-history-chart-line.ts @@ -45,6 +45,8 @@ export class StateHistoryChartLine extends LitElement { @property({ type: Number }) public chartIndex?; + @property({ type: Boolean }) public logarithmicScale = false; + @state() private _chartData?: ChartData<"line">; @state() private _entityIds: string[] = []; @@ -78,7 +80,8 @@ export class StateHistoryChartLine extends LitElement { !this.hasUpdated || changedProps.has("showNames") || changedProps.has("startTime") || - changedProps.has("endTime") + changedProps.has("endTime") || + changedProps.has("logarithmicScale") ) { this._chartOptions = { parsing: false, @@ -132,6 +135,7 @@ export class StateHistoryChartLine extends LitElement { } }, position: computeRTL(this.hass) ? "right" : "left", + type: this.logarithmicScale ? "logarithmic" : "linear", }, }, plugins: { diff --git a/src/components/chart/state-history-charts.ts b/src/components/chart/state-history-charts.ts index 61d02699ea6f..854c893d89ab 100644 --- a/src/components/chart/state-history-charts.ts +++ b/src/components/chart/state-history-charts.ts @@ -73,6 +73,8 @@ export class StateHistoryCharts extends LitElement { @property({ type: Boolean }) public isLoadingData = false; + @property({ type: Boolean }) public logarithmicScale = false; + private _computedStartTime!: Date; private _computedEndTime!: Date; @@ -159,6 +161,7 @@ export class StateHistoryCharts extends LitElement { .names=${this.names} .chartIndex=${index} .clickForMoreInfo=${this.clickForMoreInfo} + .logarithmicScale=${this.logarithmicScale} @y-width-changed=${this._yWidthChanged} > `; diff --git a/src/panels/lovelace/cards/hui-history-graph-card.ts b/src/panels/lovelace/cards/hui-history-graph-card.ts index 7c4ad061a763..e4576d1fccf9 100644 --- a/src/panels/lovelace/cards/hui-history-graph-card.ts +++ b/src/panels/lovelace/cards/hui-history-graph-card.ts @@ -216,6 +216,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { .showNames=${this._config.show_names !== undefined ? this._config.show_names : true} + .logarithmicScale=${this._config.logarithmic_scale || false} > `} diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index e83e1f620cca..b56da2c88c81 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -317,6 +317,7 @@ export interface HistoryGraphCardConfig extends LovelaceCardConfig { hours_to_show?: number; title?: string; show_names?: boolean; + logarithmic_scale?: 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 ed73afb0768b..adcd6a9314c7 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 @@ -31,6 +31,7 @@ const cardConfigStruct = assign( hours_to_show: optional(number()), refresh_interval: optional(number()), // deprecated show_names: optional(boolean()), + logarithmic_scale: optional(boolean()), }) ); @@ -47,6 +48,11 @@ const SCHEMA = [ }, ], }, + { + name: "logarithmic_scale", + required: false, + selector: { boolean: {} }, + }, ] as const; @customElement("hui-history-graph-card-editor") @@ -100,8 +106,18 @@ export class HuiHistoryGraphCardEditor fireEvent(this, "config-changed", { config }); } - private _computeLabelCallback = (schema: SchemaUnion) => - this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`); + private _computeLabelCallback = (schema: SchemaUnion) => { + switch (schema.name) { + case "logarithmic_scale": + return this.hass!.localize( + `ui.panel.lovelace.editor.card.history-graph.${schema.name}` + ); + default: + return this.hass!.localize( + `ui.panel.lovelace.editor.card.generic.${schema.name}` + ); + } + }; static styles: CSSResultGroup = css` ha-form { diff --git a/src/translations/en.json b/src/translations/en.json index ac95bf09e79c..1e819e063f93 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4971,7 +4971,8 @@ }, "history-graph": { "name": "History graph", - "description": "The History graph card allows you to display a graph for each of the entities listed." + "description": "The History graph card allows you to display a graph for each of the entities listed.", + "logarithmic_scale": "Logarithmic scale" }, "statistics-graph": { "name": "Statistics graph",