From 47a7e3b31bf266d9b2edb07465bc15073446ffb1 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Wed, 2 Sep 2020 19:20:13 +0300 Subject: [PATCH 1/2] Fixed after sort legend keys, is not correct dataKey index; Refactoring --- ui-ngx/src/app/core/api/widget-subscription.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ui-ngx/src/app/core/api/widget-subscription.ts b/ui-ngx/src/app/core/api/widget-subscription.ts index 0eb71c7e90..df5fac2e9a 100644 --- a/ui-ngx/src/app/core/api/widget-subscription.ts +++ b/ui-ngx/src/app/core/api/widget-subscription.ts @@ -403,7 +403,7 @@ export class WidgetSubscription implements IWidgetSubscription { configDatasource: datasource, configDatasourceIndex: index, dataLoaded: (pageData, data1, datasourceIndex, pageLink) => { - this.dataLoaded(pageData, data1, datasourceIndex, pageLink, true) + this.dataLoaded(pageData, data1, datasourceIndex, pageLink, true); }, initialPageDataChanged: this.initialPageDataChanged.bind(this), dataUpdated: this.dataUpdated.bind(this), @@ -804,7 +804,7 @@ export class WidgetSubscription implements IWidgetSubscription { configDatasourceIndex: datasourceIndex, subscriptionTimewindow: this.subscriptionTimewindow, dataLoaded: (pageData, data1, datasourceIndex1, pageLink1) => { - this.dataLoaded(pageData, data1, datasourceIndex1, pageLink1, true) + this.dataLoaded(pageData, data1, datasourceIndex1, pageLink1, true); }, dataUpdated: this.dataUpdated.bind(this), updateRealtimeSubscription: () => { @@ -1149,7 +1149,7 @@ export class WidgetSubscription implements IWidgetSubscription { this.onSubscriptionMessage({ severity: 'warn', message - }) + }); } } if (isUpdate) { @@ -1226,9 +1226,6 @@ export class WidgetSubscription implements IWidgetSubscription { }); }); } - if (this.displayLegend) { - this.legendData.keys = this.legendData.keys.sort((key1, key2) => key1.dataKey.label.localeCompare(key2.dataKey.label)); - } if (this.caulculateLegendData) { this.data.forEach((dataSetHolder, keyIndex) => { this.updateLegend(keyIndex, dataSetHolder.data, false); @@ -1274,7 +1271,7 @@ export class WidgetSubscription implements IWidgetSubscription { const configuredDatasource = this.configuredDatasources[datasourceIndex]; const startIndex = configuredDatasource.dataKeyStartIndex; const dataKeysCount = configuredDatasource.dataKeys.length; - const index = startIndex + dataIndex*dataKeysCount + dataKeyIndex; + const index = startIndex + dataIndex * dataKeysCount + dataKeyIndex; let update = true; let currentData: DataSetHolder; if (this.displayLegend && this.legendData.keys[index].dataKey.hidden) { From 903080f4f3c6ffdd530af9c37012276ccf88ebc0 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 3 Sep 2020 12:40:17 +0300 Subject: [PATCH 2/2] Add correct sort dataKey --- ui-ngx/src/app/core/api/widget-subscription.ts | 7 +++++-- .../modules/home/components/widget/legend.component.html | 4 ++-- .../app/modules/home/components/widget/legend.component.ts | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ui-ngx/src/app/core/api/widget-subscription.ts b/ui-ngx/src/app/core/api/widget-subscription.ts index df5fac2e9a..bb594f0802 100644 --- a/ui-ngx/src/app/core/api/widget-subscription.ts +++ b/ui-ngx/src/app/core/api/widget-subscription.ts @@ -575,7 +575,7 @@ export class WidgetSubscription implements IWidgetSubscription { updateDataVisibility(index: number): void { if (this.displayLegend) { - const hidden = this.legendData.keys[index].dataKey.hidden; + const hidden = this.legendData.keys.find(key => key.dataIndex === index).dataKey.hidden; if (hidden) { this.hiddenData[index].data = this.data[index].data; this.data[index].data = []; @@ -1226,6 +1226,9 @@ export class WidgetSubscription implements IWidgetSubscription { }); }); } + if (this.displayLegend) { + this.legendData.keys = this.legendData.keys.sort((key1, key2) => key1.dataKey.label.localeCompare(key2.dataKey.label)); + } if (this.caulculateLegendData) { this.data.forEach((dataSetHolder, keyIndex) => { this.updateLegend(keyIndex, dataSetHolder.data, false); @@ -1328,7 +1331,7 @@ export class WidgetSubscription implements IWidgetSubscription { } private updateLegend(dataIndex: number, data: DataSet, detectChanges: boolean) { - const dataKey = this.legendData.keys[dataIndex].dataKey; + const dataKey = this.legendData.keys.find(key => key.dataIndex === dataIndex).dataKey; const decimals = isDefined(dataKey.decimals) ? dataKey.decimals : this.decimals; const units = dataKey.units && dataKey.units.length ? dataKey.units : this.units; const legendKeyData = this.legendData.data[dataIndex]; diff --git a/ui-ngx/src/app/modules/home/components/widget/legend.component.html b/ui-ngx/src/app/modules/home/components/widget/legend.component.html index 3d0eda2856..272e5fae64 100644 --- a/ui-ngx/src/app/modules/home/components/widget/legend.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/legend.component.html @@ -32,7 +32,7 @@ + [ngClass]="{ 'tb-hidden-label': legendKey.dataKey.hidden, 'tb-horizontal': isHorizontal }"> {{ legendKey.dataKey.label }} {{ legendData.data[legendKey.dataIndex].min }} @@ -47,7 +47,7 @@ + [ngClass]="{ 'tb-hidden-label': legendKey.dataKey.hidden}"> {{ legendKey.dataKey.label }} diff --git a/ui-ngx/src/app/modules/home/components/widget/legend.component.ts b/ui-ngx/src/app/modules/home/components/widget/legend.component.ts index b47ba317c0..55fffa2b5b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/legend.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/legend.component.ts @@ -52,8 +52,9 @@ export class LegendComponent implements OnInit { } toggleHideData(index: number) { - if (!this.legendData.keys[index].dataKey.settings.disableDataHiding) { - this.legendData.keys[index].dataKey.hidden = !this.legendData.keys[index].dataKey.hidden; + const dataKey = this.legendData.keys.find(key => key.dataIndex === index).dataKey; + if (!dataKey.settings.disableDataHiding) { + dataKey.hidden = !dataKey.hidden; this.legendKeyHiddenChange.emit(index); } }