Skip to content

Commit

Permalink
fix: group_by would sometimes not work with data_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
RomRider committed Mar 3, 2021
1 parent 7dd6e60 commit cfa6871
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .devcontainer/ui-lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,8 @@ views:
header:
show: true
title: radialBar
chart_type: radialBar
header:
show: true
show_states: true
chart_type: radialBar
series:
- entity: sensor.random0_100
- entity: sensor.random_0_1000
Expand Down
12 changes: 10 additions & 2 deletions src/graphEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ export default class GraphEntry {
const now = new Date().getTime();
buckets.forEach((bucket, index) => {
if (bucket.data.length === 0) {
if (this._config.group_by.fill === 'last' && bucket.timestamp <= now) {
if (this._config.group_by.fill === 'last' && (bucket.timestamp <= now || this._config.data_generator)) {
bucket.data[0] = [bucket.timestamp, lastNonNullBucketValue];
} else if (this._config.group_by.fill === 'zero' && bucket.timestamp <= now) {
} else if (this._config.group_by.fill === 'zero' && (bucket.timestamp <= now || this._config.data_generator)) {
bucket.data[0] = [bucket.timestamp, 0];
} else if (this._config.group_by.fill === 'null') {
bucket.data[0] = [bucket.timestamp, null];
Expand All @@ -410,13 +410,21 @@ export default class GraphEntry {
}
});
buckets.pop();
// Remove nulls at the end
while (
buckets.length > 0 &&
(buckets[buckets.length - 1].data.length === 0 ||
(buckets[buckets.length - 1].data.length === 1 && buckets[buckets.length - 1].data[0][1] === null))
) {
buckets.pop();
}
// Remove nulls at the beginning
while (
buckets.length > 0 &&
(buckets[0].data.length === 0 || (buckets[0].data.length === 1 && buckets[0].data[0][1] === null))
) {
buckets.shift();
}
return buckets;
}

Expand Down

0 comments on commit cfa6871

Please sign in to comment.