Skip to content

armgit / core

Public Imported from GitHub
0

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

Fill gaps between datapoints when null values are present because no update on the attribute has occurred

Michael Rademaker05d406443310
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.ts
index 22d29df13..576e9c4c9 100644
--- a/ui/component/core/src/util.ts
+++ b/ui/component/core/src/util.ts
@@ -22,6 +22,7 @@ import {
AbstractNameValueDescriptorHolder,
MetaItemDescriptor,
ValueFormatStyleRepresentation,
+ ValueDatapoint,
} from "@openremote/model";
import i18next from "i18next";
import Qs from "qs";
@@ -882,3 +883,15 @@ export function dispatchCancellableEvent<T>(target: EventTarget, event: CustomEv
return deferred.promise;
}
+
+//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 (prevValue && prevValue.y && !value.y) {
+ value.y = prevValue.y;
+ }
+ prevValue = value;
+ });
+}
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index 9d2c42222..13b6870b8 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -266,6 +266,7 @@ export class OrAttributeCard extends LitElement {
return;
}
+ Util.fillInDatapointGaps(this.data);
if (!this._chart) {
this._chart = new Chart(this._chartElem, {
type: "line",
@@ -314,6 +315,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.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.ts
index b969438e1..fe62866ae 100644
--- a/ui/component/or-attribute-history/src/index.ts
+++ b/ui/component/or-attribute-history/src/index.ts
@@ -15,7 +15,7 @@ import {
import i18next from "i18next";
import {translate} from "@openremote/or-translate";
import {Attribute, AttributeRef, DatapointInterval, ValueDatapoint, ValueDescriptor} from "@openremote/model";
-import manager, {AssetModelUtil, DefaultColor2, DefaultColor3, DefaultColor4, DefaultColor5} from "@openremote/core";
+import manager, {AssetModelUtil, DefaultColor2, DefaultColor3, DefaultColor4, DefaultColor5, Util} from "@openremote/core";
import "@openremote/or-input";
import "@openremote/or-panel";
import "@openremote/or-translate";
@@ -360,7 +360,7 @@ 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: {
@@ -433,6 +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.update();
}
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 6f26a7b3c..45078392c 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -618,6 +618,8 @@ export class OrChart extends translate(i18next)(LitElement) {
if (!this._data) {
return;
}
+
+ Util.fillInDatapointGaps(this._data);
if (!this._chart) {
this._chart = new Chart(this._chartElem, {
type: "line",
@@ -696,6 +698,7 @@ 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();
}