Skip to content

Commit

Permalink
v2.1.2/v3.1.1
Browse files Browse the repository at this point in the history
developer preview
  • Loading branch information
zibous committed Apr 21, 2021
1 parent 9403c60 commit 88bfcc0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 42 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ If you find any information on this page useful, feel free to buy me a coffee:

### Manual install

1. Download the [latest release](https://github.com/zibous/lovelace-graph-chart-card/releases), unzip and copy the folder `chart-card` into your `config/www/community` directory.
<br>
1. Download the [latest release](https://github.com/zibous/lovelace-graph-chart-card/releases), unzip and copy the folder `chart-card` into your `config/www/community` directory or download the **latest main version** from https://github.com/zibous/lovelace-graph-chart-card/tree/main/dist/chart-card (all files) to the `config/www/community` directory.

2. <br>

2. Add a reference to `chart-card-min.js` inside your `ui-lovelace.yaml` or at the top of the *raw config editor UI*:
3. Add a reference to `chart-card-min.js` inside your `ui-lovelace.yaml` or at the top of the *raw config editor UI*:

```yaml
resources:
Expand Down
2 changes: 1 addition & 1 deletion dist/chart-card/chart-card-min.js

Large diffs are not rendered by default.

45 changes: 26 additions & 19 deletions dist/chart-card/chart-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ class ChartCard extends HTMLElement {
item.state = item.state * item.datascales.factor
item.factor = item.datascales.factor
item.ignoreZero = item.ignoreZero || this.datascales.ignoreZero
item.stateOnly = item.stateOnly || false
/**
* handling the item attribute
* item.id: sensor name --> sensor.thermometer
Expand Down Expand Up @@ -1520,26 +1521,33 @@ class ChartCard extends HTMLElement {
y: row[1],
localedate: formatdate(row[0], item.datascales.format)
}))
// if (item.datascales.useStatistics) {
// item.statistics = {
// current: item.state,
// first: item.seriesdata.data[0],
// last: item.seriesdata.data[item.seriesdata.data - 1],
// max: arrStatistics.max(item.seriesdata.data),
// min: arrStatistics.min(item.seriesdata.data),
// sum: arrStatistics.sum(item.seriesdata.data),
// avg: arrStatistics.mean(item.seriesdata.data)
// }
// }
item.datascales.data_count = item.seriesdata.data.length
if (item.datascales.data_count) this._buildGraphData(null, API_DATAMODE.database)
if (item.datascales.data_count) {
if (item.datascales.useStatistics) {
const _data = item.seriesdata.data.filter(e => e.y !== null)
item.statistics = {
current: _data[_data.length - 1].y,
first: _data[0].y,
last: _data[_data.length - 1].y,
min: _data.reduce((min, p) => (p.y < min ? p.y : min), _data[0].y),
max: _data.reduce((max, p) => (p.y > max ? p.y : max), _data[0].y),
sum: _data.reduce((n, { y }) => n + y, 0),
avg: _data.reduce((n, { y }) => n + y, 0) / _data.length
}
item.statistics.range = item.statistics.max - item.statistics.min
item.statistics.midrange = (item.statistics.max - item.statistics.min) * 0.5
item.state = item.statistics.current
}
this._buildGraphData(null, API_DATAMODE.database)
}
if (this.DEBUGMODE) this.DEBUGDATA.INFLUXDB.count = item.datascales.data_count
}
if (this.DEBUGMODE) this.DEBUGDATA.INFLUXDB.status = "No Error, all well done..."
if (this.DEBUGMODE)
this.DEBUGDATA.PROFILER.INFLUXDB.elapsed = msToTime(
performance.now() - this.DEBUGDATA.PROFILER.INFLUXDB.start
)

} else {
// no data
if (this.DEBUGMODE) this.DEBUGDATA.INFLUXDB.status = "No Error, but no data found!"
Expand All @@ -1565,7 +1573,7 @@ class ChartCard extends HTMLElement {
connection: item.datasource.influxdb,
query: item.datasource.query,
token: item.datasource.token
})
})
throw error
})
}
Expand Down Expand Up @@ -1720,7 +1728,7 @@ class ChartCard extends HTMLElement {

this._renderCardTimestamp()

if (mode === API_DATAMODE.history) {
if (mode != API_DATAMODE.statemode) {
if (this.chart_showstate || this.showdetails) {
let _data = this.graphData.data.datasets.map(function (item) {
return {
Expand Down Expand Up @@ -1799,12 +1807,11 @@ class Entities {
* @param {objec} entity
*/
addEntity(entity) {
if(entity.dataid){
if (entity.dataid) {
this.items[entity.dataid] = entity
}else{
} else {
this.items[entity.id] = entity
}

}
_getDataFromInfluxDb() {}
/**
Expand Down Expand Up @@ -2013,15 +2020,15 @@ class Entities {
* datasource ...
*/
checkDataSouresItems() {
return Object.keys(this.items).filter((item) => this.items[item].datasource != undefined)
return Object.keys(this.items).filter((item) => this.items[item].datasource != undefined)
}
/**
* get entities id's as string
* @returns string
*/
getEntityIdsAsString() {
const d = Object.keys(this.items)
.filter((item) => this.items[item].datasource == undefined)
.filter((item) => this.items[item].datasource == undefined && this.items[item].stateOnly == false)
.map((item) => this.items[item].id)
return [...new Set(d)].join(",")
}
Expand Down
9 changes: 4 additions & 5 deletions src/entitydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class Entities {
* @param {objec} entity
*/
addEntity(entity) {
if(entity.dataid){
if (entity.dataid) {
this.items[entity.dataid] = entity
}else{
} else {
this.items[entity.id] = entity
}

}
_getDataFromInfluxDb() {}
/**
Expand Down Expand Up @@ -228,15 +227,15 @@ class Entities {
* datasource ...
*/
checkDataSouresItems() {
return Object.keys(this.items).filter((item) => this.items[item].datasource != undefined)
return Object.keys(this.items).filter((item) => this.items[item].datasource != undefined)
}
/**
* get entities id's as string
* @returns string
*/
getEntityIdsAsString() {
const d = Object.keys(this.items)
.filter((item) => this.items[item].datasource == undefined)
.filter((item) => this.items[item].datasource == undefined && this.items[item].stateOnly == false)
.map((item) => this.items[item].id)
return [...new Set(d)].join(",")
}
Expand Down
36 changes: 22 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ class ChartCard extends HTMLElement {
item.state = item.state * item.datascales.factor
item.factor = item.datascales.factor
item.ignoreZero = item.ignoreZero || this.datascales.ignoreZero
item.stateOnly = item.stateOnly || false
/**
* handling the item attribute
* item.id: sensor name --> sensor.thermometer
Expand Down Expand Up @@ -1349,26 +1350,33 @@ class ChartCard extends HTMLElement {
y: row[1],
localedate: formatdate(row[0], item.datascales.format)
}))
// if (item.datascales.useStatistics) {
// item.statistics = {
// current: item.state,
// first: item.seriesdata.data[0],
// last: item.seriesdata.data[item.seriesdata.data - 1],
// max: arrStatistics.max(item.seriesdata.data),
// min: arrStatistics.min(item.seriesdata.data),
// sum: arrStatistics.sum(item.seriesdata.data),
// avg: arrStatistics.mean(item.seriesdata.data)
// }
// }
item.datascales.data_count = item.seriesdata.data.length
if (item.datascales.data_count) this._buildGraphData(null, API_DATAMODE.database)
if (item.datascales.data_count) {
if (item.datascales.useStatistics) {
const _data = item.seriesdata.data.filter(e => e.y !== null)
item.statistics = {
current: _data[_data.length - 1].y,
first: _data[0].y,
last: _data[_data.length - 1].y,
min: _data.reduce((min, p) => (p.y < min ? p.y : min), _data[0].y),
max: _data.reduce((max, p) => (p.y > max ? p.y : max), _data[0].y),
sum: _data.reduce((n, { y }) => n + y, 0),
avg: _data.reduce((n, { y }) => n + y, 0) / _data.length
}
item.statistics.range = item.statistics.max - item.statistics.min
item.statistics.midrange = (item.statistics.max - item.statistics.min) * 0.5
item.state = item.statistics.current
}
this._buildGraphData(null, API_DATAMODE.database)
}
if (this.DEBUGMODE) this.DEBUGDATA.INFLUXDB.count = item.datascales.data_count
}
if (this.DEBUGMODE) this.DEBUGDATA.INFLUXDB.status = "No Error, all well done..."
if (this.DEBUGMODE)
this.DEBUGDATA.PROFILER.INFLUXDB.elapsed = msToTime(
performance.now() - this.DEBUGDATA.PROFILER.INFLUXDB.start
)

} else {
// no data
if (this.DEBUGMODE) this.DEBUGDATA.INFLUXDB.status = "No Error, but no data found!"
Expand All @@ -1394,7 +1402,7 @@ class ChartCard extends HTMLElement {
connection: item.datasource.influxdb,
query: item.datasource.query,
token: item.datasource.token
})
})
throw error
})
}
Expand Down Expand Up @@ -1549,7 +1557,7 @@ class ChartCard extends HTMLElement {

this._renderCardTimestamp()

if (mode === API_DATAMODE.history) {
if (mode != API_DATAMODE.statemode) {
if (this.chart_showstate || this.showdetails) {
let _data = this.graphData.data.datasets.map(function (item) {
return {
Expand Down

0 comments on commit 88bfcc0

Please sign in to comment.