Flatline fix for Sensor Cards (#2064)

* Update hui-sensor-card.js

This fixes issues where the first history item was repeated many times at the start of the graph resulting in a flat line that does not represent the data.

Also, the graph now has the ability to reach a 1 to 1 history graph to sensor graph point representation.  Before 2 to 1 was the highest resolution possible.  This was due to using history.length - 1 as the denominator in cases where the user set the accuracy larger than the total number of points in the history.

* Update hui-sensor-card.js

* Update hui-sensor-card.js

* Update hui-sensor-card.js

* Update hui-sensor-card.js

* Update hui-sensor-card.js
This commit is contained in:
Petro31 2018-11-19 10:47:30 -05:00 committed by Paulus Schoutsen
parent 1bb62bfc05
commit 9a9986cf17

View File

@ -180,13 +180,16 @@ class HuiSensorCard extends EventsMixin(LitElement) {
const history = stateHistory[0];
const valArray = [history[history.length - 1]];
let pos = history.length - 1;
const accuracy = this._config.accuracy <= pos ? this._config.accuracy : pos;
const accuracy =
this._config.accuracy <= history.length
? this._config.accuracy
: history.length;
let increment = Math.ceil(history.length / accuracy);
increment = increment <= 0 ? 1 : increment;
for (let i = accuracy; i >= 2; i--) {
let pos = history.length - 1;
for (let i = accuracy; i >= 1; i--) {
pos -= increment;
valArray.unshift(pos >= 0 ? history[pos] : history[0]);
if (pos >= 0) valArray.unshift(history[pos]);
}
this._line = this._getGraph(valArray, 500, this._config.height);
}