100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Filter out null values
Michael Rademakerd91877b05593
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex 90ad05f58..f76cde590 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -886,12 +886,6 @@ export function dispatchCancellableEvent<T>(target: EventTarget, event: CustomEv//TODO: should we keep it like this?//Added to fill in gaps with null values-export function fillInDatapointGaps(data: ValueDatapoint<any>[]) {- var prevValue: ValueDatapoint<any>;- data.forEach(value => {- if (value.y == null && prevValue && prevValue.y) {- value.y = prevValue.y;- }- prevValue = value;- });+export function filterNullValueDatapoints(data: ValueDatapoint<any>[]) {+ return data.filter(value => value.y != null);}diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex 13b6870b8..3bb8050b8 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -266,14 +266,13 @@ export class OrAttributeCard extends LitElement {return;}- Util.fillInDatapointGaps(this.data);if (!this._chart) {this._chart = new Chart(this._chartElem, {type: "line",data: {datasets: [{- data: this.data,+ data: Util.filterNullValueDatapoints(this.data),lineTension: 0.1,spanGaps: true,backgroundColor: "transparent",@@ -315,8 +314,7 @@ export class OrAttributeCard extends LitElement {});} else {if (changedProperties.has("data")) {- Util.fillInDatapointGaps(this.data);- this._chart.data.datasets![0].data = this.data;+ this._chart.data.datasets![0].data = Util.filterNullValueDatapoints(this.data);this._chart.update();this.delta = this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data));}diff --git a/ui/component/or-attribute-history/src/index.ts b/ui/component/or-attribute-history/src/index.tsindex fe62866ae..f92ad1c91 100644--- a/ui/component/or-attribute-history/src/index.ts+++ b/ui/component/or-attribute-history/src/index.ts@@ -360,13 +360,13 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {bgColor = bgColor.substring(0, bgColor.length - 1) + opacity;}}- Util.fillInDatapointGaps(this._data);+this._chart = new Chart(this._chartElem, {type: "line",data: {datasets: [{- data: this._data,+ data: Util.filterNullValueDatapoints(this._data),backgroundColor: bgColor,borderColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-line-color"),pointBorderColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-point-border-color"),@@ -433,8 +433,7 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {});} else {if (changedProperties.has("_data")) {- Util.fillInDatapointGaps(this._data);- this._chart.data.datasets![0].data = this._data;+ this._chart.data.datasets![0].data = Util.filterNullValueDatapoints(this._data);;this._chart.update();}}diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex 45078392c..420c3d918 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -619,7 +619,6 @@ export class OrChart extends translate(i18next)(LitElement) {return;}- Util.fillInDatapointGaps(this._data);if (!this._chart) {this._chart = new Chart(this._chartElem, {type: "line",@@ -698,7 +697,6 @@ export class OrChart extends translate(i18next)(LitElement) {});} else {if (changedProperties.has("_data")) {- Util.fillInDatapointGaps(this._data);this._chart.data.datasets = this._data;this._chart.update();}@@ -905,7 +903,10 @@ export class OrChart extends translate(i18next)(LitElement) {});let data = this.assetAttributes.map(async (attribute, index) => {- const valuepoints = await this._loadAttributeData(this.assets[index], attribute, this.timestamp);+ var valuepoints = await this._loadAttributeData(this.assets[index], attribute, this.timestamp);+ if (valuepoints) {+ valuepoints = Util.filterNullValueDatapoints(valuepoints);+ }const dataset = {...datasetBases[index],data: valuepoints};@@ -923,7 +924,10 @@ export class OrChart extends translate(i18next)(LitElement) {}));const predictedData = this.assetAttributes.map(async (attribute, index) => {- const valuepoints = await this._loadPredictedAttributeData(this.assets[index], attribute, this.timestamp);+ var valuepoints = await this._loadPredictedAttributeData(this.assets[index], attribute, this.timestamp);+ if (valuepoints) {+ valuepoints = Util.filterNullValueDatapoints(valuepoints);+ }const dataset = {...datasetBases[index],data: valuepoints,borderDash: [2, 4]@@ -941,7 +945,10 @@ export class OrChart extends translate(i18next)(LitElement) {if(this.periodCompare) {const cData = this.assetAttributes.map(async (attribute, index) => {- const valuepoints = await this._loadAttributeData(this.assets[index], attribute, this.compareTimestamp);+ var valuepoints = await this._loadAttributeData(this.assets[index], attribute, this.compareTimestamp);+ if (valuepoints) {+ valuepoints = Util.filterNullValueDatapoints(valuepoints);+ }const dataset = {...datasetBases[index],data: valuepoints,borderDash: [10, 10]@@ -957,7 +964,10 @@ export class OrChart extends translate(i18next)(LitElement) {});let cPredictedData = this.assetAttributes.map(async (attribute, index) => {- const valuepoints = await this._loadPredictedAttributeData(this.assets[index], attribute, this.compareTimestamp);+ var valuepoints = await this._loadPredictedAttributeData(this.assets[index], attribute, this.compareTimestamp);+ if (valuepoints) {+ valuepoints = Util.filterNullValueDatapoints(valuepoints);+ }const dataset = {...datasetBases[index],data: valuepoints,borderDash: [2, 4]