Skip to content

Commit

Permalink
feat(graph): Extends graph's last value to the current time
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Jan 22, 2021
1 parent 280e328 commit bfe64c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ views:
name: test2
type: bar
hours_to_show: 0.25
cache: true
cache: true
- type: custom:apexcharts-card
hours_to_show: 0.25
series:
- entity: sensor.humidity
# extend_to_end: true
9 changes: 7 additions & 2 deletions src/apexcharts-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bfe64c5

Please sign in to comment.