diff --git a/.devcontainer/ui-lovelace.yaml b/.devcontainer/ui-lovelace.yaml index 86d94f3..1de12a0 100644 --- a/.devcontainer/ui-lovelace.yaml +++ b/.devcontainer/ui-lovelace.yaml @@ -24,4 +24,9 @@ views: name: test2 type: bar hours_to_show: 0.25 - cache: true \ No newline at end of file + cache: true + - type: custom:apexcharts-card + hours_to_show: 0.25 + series: + - entity: sensor.humidity + # extend_to_end: true \ No newline at end of file diff --git a/src/apexcharts-card.ts b/src/apexcharts-card.ts index 843a36c..38d11f8 100644 --- a/src/apexcharts-card.ts +++ b/src/apexcharts-card.ts @@ -107,6 +107,9 @@ class ChartsCard extends LitElement { useCompress: false, ...JSON.parse(JSON.stringify(config)), }; + this._config?.series.map((serie) => { + serie.extend_to_end = serie.extend_to_end !== undefined ? serie.extend_to_end : true; + }); } static get styles(): CSSResult { @@ -240,9 +243,11 @@ class ChartsCard extends LitElement { const promise = this._entities.map((entity, i) => this._updateEntity(entity, i, start)); await Promise.all(promise); const graphData = { - series: this._history.map((history) => { + series: this._history.map((history, index) => { return { - data: history?.data, + data: this._config?.series[index].extend_to_end + ? [...history?.data, ...[[end.getTime(), history?.data.slice(-1)[0][1]]]] + : history?.data, }; }), subtitle: { diff --git a/src/types.ts b/src/types.ts index c4c34f0..5c17588 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,6 +18,7 @@ export interface ChartCardSeriesExternalConfig { name?: string; type: 'line' | 'bar' | 'area'; curve?: 'smooth' | 'straight' | 'stepline'; + extend_to_end?: boolean; } export interface ChartCardSeriesConfig extends ChartCardSeriesExternalConfig {