diff --git a/src/graph.js b/src/graph.js index 84697d4c..d251edcd 100644 --- a/src/graph.js +++ b/src/graph.js @@ -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, @@ -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; } @@ -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`; diff --git a/src/main.js b/src/main.js index f5316210..21638df9 100644 --- a/src/main.js +++ b/src/main.js @@ -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, ), ); } @@ -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(); }