Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from './const';

export default class Graph {
constructor(width, height, margin, hours = 24, points = 1, aggregateFuncName = 'avg', groupBy = 'interval', smoothing = true, logarithmic = false) {
constructor(width, height, margin, hours = 24, points = 1, aggregateFuncName = 'avg', groupBy = 'interval', smoothing = true, logarithmic = false, fillThreshold) {
const aggregateFuncMap = {
avg: this._average,
median: this._median,
Expand Down Expand Up @@ -33,6 +33,7 @@ export default class Graph {
this._logarithmic = logarithmic;
this._groupBy = groupBy;
this._endTime = 0;
this.fillThreshold = fillThreshold;
}

get max() { return this._max; }
Expand Down Expand Up @@ -184,8 +185,15 @@ export default class Graph {
});
}

getFill(path) {
const height = this.height + this.margin[Y] * 4;
getFill(path, entityFillThreshold) {
let height = this.height + this.margin[Y] * 4;
const customThreshold = [this.fillThreshold, entityFillThreshold]
.filter(t => typeof t === 'number' && !Number.isNaN(t))
.pop();
if (customThreshold !== undefined) {
const [threshold] = this._calcY([[0, 0, customThreshold]]);
[, height] = threshold;
}
let fill = path;
fill += ` L ${this.width - this.margin[X] * 2}, ${height}`;
fill += ` L ${this.coords[0][X]}, ${height} z`;
Expand Down
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class MiniGraphCard extends LitElement {
!entity.entity.startsWith('binary_sensor.'), // turn off for binary sensor by default
),
this.config.logarithmic,
this.config.fill_threshold,
),
);
}
Expand Down Expand Up @@ -774,7 +775,8 @@ class MiniGraphCard extends LitElement {
const line = this.Graph[i].getPath();
if (config.entities[i].show_line !== false) this.line[i] = line;
if (config.show.fill
&& config.entities[i].show_fill !== false) this.fill[i] = this.Graph[i].getFill(line);
&& config.entities[i].show_fill !== false) this.fill[i] = this.Graph[i]
.getFill(line, config.entities[i].fill_threshold);
if (config.show.points && (config.entities[i].show_points !== false)) {
this.points[i] = this.Graph[i].getPoints();
}
Expand Down