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
Insights line-chart improvements (#2725)
Wouter Voorberg79c5d77f5669
diff --git a/ui/app/shared/locales/en/or.json b/ui/app/shared/locales/en/or.jsonindex 8c6c1d267..801f4d34a 100644--- a/ui/app/shared/locales/en/or.json+++ b/ui/app/shared/locales/en/or.json@@ -165,6 +165,7 @@"longPressSetLoc": "Long press to set location","this": "Current","last": "Last",+ "next": "Next","60minutes": "60 minutes","hour": "Hour","6hours": "6 hours",diff --git a/ui/app/shared/locales/nl/or.json b/ui/app/shared/locales/nl/or.jsonindex f2c75b8b9..896fd7aec 100644--- a/ui/app/shared/locales/nl/or.json+++ b/ui/app/shared/locales/nl/or.json@@ -160,6 +160,7 @@"longPressSetLoc": "Druk lang op de kaart om locatie in te stellen","this": "Huidige","last": "Afgelopen",+ "next": "Aankomende","60minutes": "60 minuten","hour": "Uur","6hours": "6 uur",diff --git a/ui/app/shared/locales/pl/or.json b/ui/app/shared/locales/pl/or.jsonindex 3d048a706..f239b2df8 100644--- a/ui/app/shared/locales/pl/or.json+++ b/ui/app/shared/locales/pl/or.json@@ -164,6 +164,7 @@"longPressSetLoc": "Przytrzymaj, aby ustawić lokalizację","this": "Bieżący","last": "Ostatni",+ "next": "Następny","60minutes": "60 minut","hour": "Godzina","6hours": "6 godzin",diff --git a/ui/component/or-attribute-picker/src/asset-attribute-picker.ts b/ui/component/or-attribute-picker/src/asset-attribute-picker.tsindex 4e9836205..f0acbdabc 100644--- a/ui/component/or-attribute-picker/src/asset-attribute-picker.ts+++ b/ui/component/or-attribute-picker/src/asset-attribute-picker.ts@@ -167,15 +167,14 @@ export class OrAssetAttributePicker extends AttributePicker {this._assetAttributes = this._assetAttributes.filter((attr) => this.attributeFilter!(attr))}- if (this.showOnlyDatapointAttrs && this.showOnlyRuleStateAttrs) {+ if (this.showOnlyDatapointAttrs || this.showOnlyRuleStateAttrs || this.showPredictedDataAttrs) {this._assetAttributes = this._assetAttributes- .filter(e => e.meta && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.RULESTATE] || e.meta[WellknownMetaItems.AGENTLINK]));- } else if (this.showOnlyDatapointAttrs) {- this._assetAttributes = this._assetAttributes- .filter(e => e.meta && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.AGENTLINK]));- } else if (this.showOnlyRuleStateAttrs) {- this._assetAttributes = this._assetAttributes- .filter(e => e.meta && (e.meta[WellknownMetaItems.RULESTATE] || e.meta[WellknownMetaItems.AGENTLINK]));+ .filter(e => e.meta && (+ e.meta[WellknownMetaItems.AGENTLINK]+ || (this.showOnlyDatapointAttrs && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.AGENTLINK]))+ || (this.showOnlyRuleStateAttrs && e.meta[WellknownMetaItems.RULESTATE])+ || (this.showPredictedDataAttrs && e.meta[WellknownMetaItems.HASPREDICTEDDATAPOINTS])+ ));}}}diff --git a/ui/component/or-attribute-picker/src/attribute-picker.ts b/ui/component/or-attribute-picker/src/attribute-picker.tsindex 67077ba2a..7e03130a1 100644--- a/ui/component/or-attribute-picker/src/attribute-picker.ts+++ b/ui/component/or-attribute-picker/src/attribute-picker.ts@@ -21,6 +21,7 @@ export abstract class AttributePickerPickedEvent extends CustomEvent<any> {* @attribute {boolean} multiSelect - Whether selecting multiple attributes is allowed or not.* @attribute {boolean} showOnlyDatapointAttrs - Whether only attributes with the 'STORE_DATAPOINT' meta item should be shown.* @attribute {boolean} showOnlyRuleStateAttrs - Whether only attributes with the 'RULE_STATE' meta item should be shown.+ * @attribute {boolean} showPredictedDataAttrs - Whether attributes with the 'HAS_PREDICTED_DATA_POINTS' meta item should be shown. Composes additively with the other flags.** @remarks This class is abstract*/@@ -40,6 +41,9 @@ export abstract class AttributePicker extends OrMwcDialog {@property({type: Boolean})public showOnlyRuleStateAttrs?: boolean = false;+ @property({type: Boolean})+ public showPredictedDataAttrs?: boolean = false;+@query("#add-btn")protected addBtn!: OrVaadinButton;@@ -63,6 +67,11 @@ export abstract class AttributePicker extends OrMwcDialog {return this;}+ public setShowPredictedDataAttrs(showPredictedDataAttrs: boolean | undefined): this {+ this.showPredictedDataAttrs = showPredictedDataAttrs;+ return this;+ }+public setMultiSelect(multiSelect: boolean | undefined): this {this.multiSelect = multiSelect;return this;diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex 05bc82d3f..4079ed8ff 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -1122,7 +1122,7 @@ export class OrChart extends translate(i18next)(LitElement) {}protected _getDefaultTimePrefixOptions(): string[] {- return ["this", "last"];+ return ["this", "last", "next"];}protected _getDefaultTimeWindowOptions(): Map<string, [moment.unitOfTime.DurationConstructor, number]> {@@ -1174,6 +1174,15 @@ export class OrChart extends translate(i18next)(LitElement) {endDate = moment();}break;+ case "next":+ if (value === 1) { // For singulars like next hour+ startDate = moment().add(value, unit).startOf(unit);+ endDate = moment().add(value, unit).endOf(unit);+ } else { // For multiples like next 5 min+ startDate = moment();+ endDate = moment().add(value, unit);+ }+ break;}return [startDate.toDate(), endDate.toDate()];}@@ -1258,6 +1267,7 @@ export class OrChart extends translate(i18next)(LitElement) {})];} else {this._dataAbortController = new AbortController();+ const isZoomed = this._zoomStartOfPeriod !== undefined && this._zoomEndOfPeriod !== undefinedpromises = this.assetAttributes?.map(async ([assetIndex, attribute], index) => {const lineData: LineChartData[] = [];@@ -1285,7 +1295,7 @@ export class OrChart extends translate(i18next)(LitElement) {lineData.push(dataset);// If necessary, load Extended Data- if (extended) {+ if (extended && !isZoomed) {dataset = await this._loadAttributeData(this.assets[assetIndex], attribute, color ?? this.colors[colourIndex], false, false, stacked, false, area, faint, extended, `${asset.name} | ${label} lastKnown`, options, unit);lineData.push(dataset);}diff --git a/ui/component/or-dashboard-builder/src/panels/attributes-panel.ts b/ui/component/or-dashboard-builder/src/panels/attributes-panel.tsindex 8c9de4e37..6417c5a41 100644--- a/ui/component/or-dashboard-builder/src/panels/attributes-panel.ts+++ b/ui/component/or-dashboard-builder/src/panels/attributes-panel.ts@@ -185,6 +185,9 @@ export class AttributesPanel extends LitElement {@property({type: Boolean})public onlyDataAttrs = false;+ @property({type: Boolean})+ public includePredictedDataAttrs = false;+@property()protected attributeFilter?: (attribute: Attribute<any>) => boolean;@@ -269,9 +272,9 @@ export class AttributesPanel extends LitElement {protected openAttributeSelector(attributeRefs: AttributeRef[], multi: boolean, onlyDataAttrs = true, attributeFilter?: (attribute: Attribute<any>) => boolean) {let dialog: OrAssetAttributePicker;if (attributeRefs != null) {- dialog = showDialog(new OrAssetAttributePicker().setMultiSelect(multi).setSelectedAttributes(attributeRefs).setShowOnlyDatapointAttrs(onlyDataAttrs).setAttributeFilter(attributeFilter));+ dialog = showDialog(new OrAssetAttributePicker().setMultiSelect(multi).setSelectedAttributes(attributeRefs).setShowOnlyDatapointAttrs(onlyDataAttrs).setShowPredictedDataAttrs(this.includePredictedDataAttrs).setAttributeFilter(attributeFilter));} else {- dialog = showDialog(new OrAssetAttributePicker().setMultiSelect(multi).setShowOnlyDatapointAttrs(onlyDataAttrs));+ dialog = showDialog(new OrAssetAttributePicker().setMultiSelect(multi).setShowOnlyDatapointAttrs(onlyDataAttrs).setShowPredictedDataAttrs(this.includePredictedDataAttrs));}dialog.addEventListener(OrAssetAttributePickerPickedEvent.NAME, (event: CustomEvent) => {this.attributeRefs = event.detail;diff --git a/ui/component/or-dashboard-builder/src/settings/barchart-settings.ts b/ui/component/or-dashboard-builder/src/settings/barchart-settings.tsindex 4db50d18c..9129a7668 100644--- a/ui/component/or-dashboard-builder/src/settings/barchart-settings.ts+++ b/ui/component/or-dashboard-builder/src/settings/barchart-settings.ts@@ -436,7 +436,7 @@ export class BarChartSettings extends WidgetSettings {const inputElem = this._attributesPanelElem?.shadowRoot?.querySelector(`#chart-color-${attributeRef.id}-${attributeRef.name}`) as HTMLInputElement | undefined;if(inputElem) {- // Listen for changes+ //Listen for changesinputElem.addEventListener("input", debounce(() => {const color = inputElem.value;this.widgetConfig.attributeColors ??= [];@@ -446,6 +446,7 @@ export class BarChartSettings extends WidgetSettings {} else {this.widgetConfig.attributeColors.push([attributeRef, color]);}+ this.widgetConfig.attributeColors = [...this.widgetConfig.attributeColors];this.notifyConfigUpdate();}, 200));diff --git a/ui/component/or-dashboard-builder/src/settings/chart-settings.ts b/ui/component/or-dashboard-builder/src/settings/chart-settings.tsindex 4b82e8aea..1eb687abb 100644--- a/ui/component/or-dashboard-builder/src/settings/chart-settings.ts+++ b/ui/component/or-dashboard-builder/src/settings/chart-settings.ts@@ -168,7 +168,7 @@ export class ChartSettings extends WidgetSettings {<div><!-- Attribute selection --><settings-panel displayName="attributes" expanded>- <attributes-chart-panel .attributeRefs="${this.widgetConfig.attributeRefs}" multi onlyDataAttrs .attributeFilter="${attributeFilter}" style="padding-bottom: 12px;"+ <attributes-chart-panel .attributeRefs="${this.widgetConfig.attributeRefs}" multi onlyDataAttrs includePredictedDataAttrs .attributeFilter="${attributeFilter}" style="padding-bottom: 12px;".attributeIconCallback="${attributeIconCallback}" .attributeActionCallback="${attributeActionCallback}"@attribute-action="${(ev: AttributeActionEvent) => this.onAttributeAction(ev)}"@attribute-select="${(ev: AttributesSelectEvent) => this.onAttributesSelect(ev)}"@@ -472,23 +472,26 @@ export class ChartSettings extends WidgetSettings {}protected removeFromAttributeColors(attributeRef: AttributeRef) {- this.widgetConfig.attributeColors = this.widgetConfig.attributeColors.filter(x => x[0] !== attributeRef);+ this.widgetConfig.attributeColors = this.widgetConfig.attributeColors.filter(+ ([ref, _]) => ref.id !== attributeRef.id || ref.name !== attributeRef.name+ );}protected openColorPickDialog(attributeRef: AttributeRef) {const inputElem = this._attributesPanelElem?.shadowRoot?.querySelector(`#chart-color-${attributeRef.id}-${attributeRef.name}`) as HTMLInputElement | undefined;if(inputElem) {- // Listen for changes+ //Listen for changesinputElem.addEventListener("input", debounce(() => {const color = inputElem.value;this.widgetConfig.attributeColors ??= [];- const existingColor = this.widgetConfig.attributeColors.find(x => x[0] === attributeRef);+ const existingColor = this.widgetConfig.attributeColors.find(x => x[0].id === attributeRef.id && x[0].name === attributeRef.name);if(existingColor) {existingColor[1] = color;} else {this.widgetConfig.attributeColors.push([attributeRef, color]);}+ this.widgetConfig.attributeColors = [...this.widgetConfig.attributeColors];this.notifyConfigUpdate();}, 200));diff --git a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts b/ui/component/or-dashboard-builder/src/widgets/chart-widget.tsindex b3292347b..9ea1a6b93 100644--- a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts+++ b/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts@@ -61,7 +61,7 @@ function getDefaultTimeWindowOptions(): Map<string, [moment.unitOfTime.DurationC}function getDefaultTimePrefixOptions(): string[] {- return ["this", "last"];+ return ["this", "last", "next"];}function getDefaultSamplingOptions(): Map<string, string> {