Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix for chart only displaying 100 points (#1283)

Martin Peetersb1740c280bec
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 471064e28..59e2bd104 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -1142,12 +1142,24 @@ export class OrChart extends translate(i18next)(LitElement) {
query.fromTimestamp = this._startOfPeriod;
query.toTimestamp = this._endOfPeriod;
- if(query.type == 'lttb' && !query.amountOfPoints) {
- if(this._chartElem.clientWidth == 0) {
- console.error("Could not grab width of the Chart for estimating amount of datapoints. Using 10 points instead.")
+ if(query.type == 'lttb') {
+
+ // If amount of data points is set, only allow a maximum of 1 points per pixel in width
+ // Otherwise, dynamically set amount of data points based on chart width (1000px = 200 data points)
+ if(query.amountOfPoints) {
+ if(this._chartElem?.clientWidth > 0) {
+ query.amountOfPoints = Math.min(query.amountOfPoints, this._chartElem?.clientWidth)
+ }
+ } else {
+ if(this._chartElem?.clientWidth > 0) {
+ query.amountOfPoints = Math.round(this._chartElem.clientWidth / 5)
+ } else {
+ console.warn("Could not grab width of the Chart for estimating amount of data points. Using 100 points instead.")
+ query.amountOfPoints = 100;
+ }
}
- query.amountOfPoints = (this._chartElem.clientWidth == 0) ? 100 : Math.round(this._chartElem.clientWidth / 10); // set amount of datapoints based on current chart width.
- } else if(query.type == 'interval' && !query.interval) {
+
+ } else if(query.type === 'interval' && !query.interval) {
const diffInHours = (this.datapointQuery.toTimestamp! - this.datapointQuery.fromTimestamp!) / 1000 / 60 / 60;
const intervalArr = this._getInterval(diffInHours);
query.interval = (intervalArr[0].toString() + " " + intervalArr[1].toString()); // for example: "5 minute"
diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts b/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts
index 8252ea549..a07a35931 100644
--- a/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts
+++ b/ui/component/or-dashboard-builder/src/or-dashboard-preview.ts
@@ -338,7 +338,7 @@ export class OrDashboardPreview extends LitElement {
// Main setup Grid method (often used)
async setupGrid(recreate: boolean, force: boolean = false) {
this.isLoading = true;
- await this.waitUntil((_: any) => this.shadowRoot?.getElementById("gridElement") != null)
+ await this.updateComplete;
let gridElement = this.shadowRoot?.getElementById("gridElement");
if(gridElement != null) {
if(recreate && this.grid != null) {
diff --git a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts b/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts
index fdccf2837..f7c88ccea 100644
--- a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts
@@ -57,8 +57,7 @@ function getDefaultWidgetConfig(): ChartWidgetConfig {
datapointQuery: {
type: "lttb",
fromTimestamp: dates[0].getTime(),
- toTimestamp: dates[1].getTime(),
- amountOfPoints: 100
+ toTimestamp: dates[1].getTime()
},
chartOptions: {
options: {
@@ -198,8 +197,7 @@ export class ChartWidget extends OrAssetWidget {
return {
type: "lttb",
fromTimestamp: moment().set('minute', -60).toDate().getTime(),
- toTimestamp: moment().set('minute', 60).toDate().getTime(),
- amountOfPoints: 100
+ toTimestamp: moment().set('minute', 60).toDate().getTime()
}
}
}