Merge pull request #6788 from devaskim/latest_value_in_legend
[3.4] UI: Add option to show latest value in widget's legend.
This commit is contained in:
		
						commit
						8288eade74
					
				@ -285,7 +285,8 @@ export class WidgetSubscription implements IWidgetSubscription {
 | 
				
			|||||||
        (this.legendConfig.showMin === true ||
 | 
					        (this.legendConfig.showMin === true ||
 | 
				
			||||||
          this.legendConfig.showMax === true ||
 | 
					          this.legendConfig.showMax === true ||
 | 
				
			||||||
          this.legendConfig.showAvg === true ||
 | 
					          this.legendConfig.showAvg === true ||
 | 
				
			||||||
          this.legendConfig.showTotal === true);
 | 
					          this.legendConfig.showTotal === true ||
 | 
				
			||||||
 | 
					          this.legendConfig.showLatest === true);
 | 
				
			||||||
      this.initDataSubscription().subscribe(() => {
 | 
					      this.initDataSubscription().subscribe(() => {
 | 
				
			||||||
          subscriptionSubject.next(this);
 | 
					          subscriptionSubject.next(this);
 | 
				
			||||||
          subscriptionSubject.complete();
 | 
					          subscriptionSubject.complete();
 | 
				
			||||||
@ -1295,6 +1296,7 @@ export class WidgetSubscription implements IWidgetSubscription {
 | 
				
			|||||||
                  max: null,
 | 
					                  max: null,
 | 
				
			||||||
                  avg: null,
 | 
					                  avg: null,
 | 
				
			||||||
                  total: null,
 | 
					                  total: null,
 | 
				
			||||||
 | 
					                  latest: null,
 | 
				
			||||||
                  hidden: false
 | 
					                  hidden: false
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
                this.legendData.data.push(legendKeyData);
 | 
					                this.legendData.data.push(legendKeyData);
 | 
				
			||||||
@ -1526,6 +1528,9 @@ export class WidgetSubscription implements IWidgetSubscription {
 | 
				
			|||||||
    if (this.legendConfig.showTotal) {
 | 
					    if (this.legendConfig.showTotal) {
 | 
				
			||||||
      legendKeyData.total = this.ctx.widgetUtils.formatValue(calculateTotal(data), decimals, units);
 | 
					      legendKeyData.total = this.ctx.widgetUtils.formatValue(calculateTotal(data), decimals, units);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (this.legendConfig.showLatest) {
 | 
				
			||||||
 | 
					      legendKeyData.latest = this.ctx.widgetUtils.formatValue(calculateLatest(data), decimals, units);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    this.callbacks.legendDataUpdated(this, detectChanges !== false);
 | 
					    this.callbacks.legendDataUpdated(this, detectChanges !== false);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1598,3 +1603,11 @@ function calculateTotal(data: DataSet): number {
 | 
				
			|||||||
    return null;
 | 
					    return null;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function calculateLatest(data: DataSet): number {
 | 
				
			||||||
 | 
					  if (data.length > 0) {
 | 
				
			||||||
 | 
					    return Number(data[data.length - 1][1]);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    return null;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -50,6 +50,9 @@
 | 
				
			|||||||
    <mat-checkbox formControlName="showTotal" fxFlex="48">
 | 
					    <mat-checkbox formControlName="showTotal" fxFlex="48">
 | 
				
			||||||
      {{ 'legend.show-total' | translate }}
 | 
					      {{ 'legend.show-total' | translate }}
 | 
				
			||||||
    </mat-checkbox>
 | 
					    </mat-checkbox>
 | 
				
			||||||
 | 
					    <mat-checkbox formControlName="showLatest" fxFlex="48">
 | 
				
			||||||
 | 
					      {{ 'legend.show-latest' | translate }}
 | 
				
			||||||
 | 
					    </mat-checkbox>
 | 
				
			||||||
    <mat-checkbox formControlName="sortDataKeys" fxFlex="48">
 | 
					    <mat-checkbox formControlName="sortDataKeys" fxFlex="48">
 | 
				
			||||||
      {{ 'legend.sort-legend' | translate }}
 | 
					      {{ 'legend.sort-legend' | translate }}
 | 
				
			||||||
    </mat-checkbox>
 | 
					    </mat-checkbox>
 | 
				
			||||||
 | 
				
			|||||||
@ -66,7 +66,8 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc
 | 
				
			|||||||
      showMin: [null, []],
 | 
					      showMin: [null, []],
 | 
				
			||||||
      showMax: [null, []],
 | 
					      showMax: [null, []],
 | 
				
			||||||
      showAvg: [null, []],
 | 
					      showAvg: [null, []],
 | 
				
			||||||
      showTotal: [null, []]
 | 
					      showTotal: [null, []],
 | 
				
			||||||
 | 
					      showLatest: [null, []]
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    this.legendSettingsFormDirectionChanges$ = this.legendConfigForm.get('direction').valueChanges
 | 
					    this.legendSettingsFormDirectionChanges$ = this.legendConfigForm.get('direction').valueChanges
 | 
				
			||||||
      .subscribe((direction: LegendDirection) => {
 | 
					      .subscribe((direction: LegendDirection) => {
 | 
				
			||||||
@ -124,7 +125,8 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc
 | 
				
			|||||||
        showMin: isDefined(legendConfig.showMin) ? legendConfig.showMin : false,
 | 
					        showMin: isDefined(legendConfig.showMin) ? legendConfig.showMin : false,
 | 
				
			||||||
        showMax: isDefined(legendConfig.showMax) ? legendConfig.showMax : false,
 | 
					        showMax: isDefined(legendConfig.showMax) ? legendConfig.showMax : false,
 | 
				
			||||||
        showAvg: isDefined(legendConfig.showAvg) ? legendConfig.showAvg : false,
 | 
					        showAvg: isDefined(legendConfig.showAvg) ? legendConfig.showAvg : false,
 | 
				
			||||||
        showTotal: isDefined(legendConfig.showTotal) ? legendConfig.showTotal : false
 | 
					        showTotal: isDefined(legendConfig.showTotal) ? legendConfig.showTotal : false,
 | 
				
			||||||
 | 
					        showLatest: isDefined(legendConfig.showLatest) ? legendConfig.showLatest : false
 | 
				
			||||||
      }, {emitEvent: false});
 | 
					      }, {emitEvent: false});
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.onDirectionChanged(legendConfig.direction);
 | 
					    this.onDirectionChanged(legendConfig.direction);
 | 
				
			||||||
 | 
				
			|||||||
@ -23,6 +23,7 @@
 | 
				
			|||||||
    <th *ngIf="legendConfig.showMax === true">{{ 'legend.max' | translate }}</th>
 | 
					    <th *ngIf="legendConfig.showMax === true">{{ 'legend.max' | translate }}</th>
 | 
				
			||||||
    <th *ngIf="legendConfig.showAvg === true">{{ 'legend.avg' | translate }}</th>
 | 
					    <th *ngIf="legendConfig.showAvg === true">{{ 'legend.avg' | translate }}</th>
 | 
				
			||||||
    <th *ngIf="legendConfig.showTotal === true">{{ 'legend.total' | translate }}</th>
 | 
					    <th *ngIf="legendConfig.showTotal === true">{{ 'legend.total' | translate }}</th>
 | 
				
			||||||
 | 
					    <th *ngIf="legendConfig.showLatest === true">{{ 'legend.latest' | translate }}</th>
 | 
				
			||||||
  </tr>
 | 
					  </tr>
 | 
				
			||||||
  </thead>
 | 
					  </thead>
 | 
				
			||||||
  <tbody>
 | 
					  <tbody>
 | 
				
			||||||
@ -38,6 +39,7 @@
 | 
				
			|||||||
        <td class="tb-legend-value" *ngIf="legendConfig.showMax === true">{{ legendData.data[legendKey.dataIndex].max }}</td>
 | 
					        <td class="tb-legend-value" *ngIf="legendConfig.showMax === true">{{ legendData.data[legendKey.dataIndex].max }}</td>
 | 
				
			||||||
        <td class="tb-legend-value" *ngIf="legendConfig.showAvg === true">{{ legendData.data[legendKey.dataIndex].avg }}</td>
 | 
					        <td class="tb-legend-value" *ngIf="legendConfig.showAvg === true">{{ legendData.data[legendKey.dataIndex].avg }}</td>
 | 
				
			||||||
        <td class="tb-legend-value" *ngIf="legendConfig.showTotal === true">{{ legendData.data[legendKey.dataIndex].total }}</td>
 | 
					        <td class="tb-legend-value" *ngIf="legendConfig.showTotal === true">{{ legendData.data[legendKey.dataIndex].total }}</td>
 | 
				
			||||||
 | 
					        <td class="tb-legend-value" *ngIf="legendConfig.showLatest === true">{{ legendData.data[legendKey.dataIndex].latest }}</td>
 | 
				
			||||||
      </tr>
 | 
					      </tr>
 | 
				
			||||||
    </ng-container>
 | 
					    </ng-container>
 | 
				
			||||||
    <tr *ngIf="isRowDirection" class="tb-legend-keys" [ngClass]="{ 'tb-row-direction': !displayHeader }">
 | 
					    <tr *ngIf="isRowDirection" class="tb-legend-keys" [ngClass]="{ 'tb-row-direction': !displayHeader }">
 | 
				
			||||||
@ -75,5 +77,11 @@
 | 
				
			|||||||
        {{ legendData.data[legendKey.dataIndex].total }}
 | 
					        {{ legendData.data[legendKey.dataIndex].total }}
 | 
				
			||||||
      </td>
 | 
					      </td>
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
 | 
					    <tr class="tb-legend-keys" *ngIf="isRowDirection && legendConfig.showLatest === true">
 | 
				
			||||||
 | 
					      <td class="tb-legend-type">{{ 'legend.latest' | translate }}</td>
 | 
				
			||||||
 | 
					      <td class="tb-legend-value" *ngFor="let legendKey of legendKeys()">
 | 
				
			||||||
 | 
					        {{ legendData.data[legendKey.dataIndex].latest }}
 | 
				
			||||||
 | 
					      </td>
 | 
				
			||||||
 | 
					    </tr>
 | 
				
			||||||
  </tbody>
 | 
					  </tbody>
 | 
				
			||||||
</table>
 | 
					</table>
 | 
				
			||||||
 | 
				
			|||||||
@ -43,7 +43,8 @@ export class LegendComponent implements OnInit {
 | 
				
			|||||||
    this.displayHeader = this.legendConfig.showMin === true ||
 | 
					    this.displayHeader = this.legendConfig.showMin === true ||
 | 
				
			||||||
      this.legendConfig.showMax === true ||
 | 
					      this.legendConfig.showMax === true ||
 | 
				
			||||||
      this.legendConfig.showAvg === true ||
 | 
					      this.legendConfig.showAvg === true ||
 | 
				
			||||||
      this.legendConfig.showTotal === true;
 | 
					      this.legendConfig.showTotal === true ||
 | 
				
			||||||
 | 
					      this.legendConfig.showLatest === true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.isHorizontal = this.legendConfig.position === LegendPosition.bottom ||
 | 
					    this.isHorizontal = this.legendConfig.position === LegendPosition.bottom ||
 | 
				
			||||||
      this.legendConfig.position === LegendPosition.top;
 | 
					      this.legendConfig.position === LegendPosition.top;
 | 
				
			||||||
 | 
				
			|||||||
@ -243,6 +243,7 @@ export interface LegendConfig {
 | 
				
			|||||||
  showMax: boolean;
 | 
					  showMax: boolean;
 | 
				
			||||||
  showAvg: boolean;
 | 
					  showAvg: boolean;
 | 
				
			||||||
  showTotal: boolean;
 | 
					  showTotal: boolean;
 | 
				
			||||||
 | 
					  showLatest: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function defaultLegendConfig(wType: widgetType): LegendConfig {
 | 
					export function defaultLegendConfig(wType: widgetType): LegendConfig {
 | 
				
			||||||
@ -253,7 +254,8 @@ export function defaultLegendConfig(wType: widgetType): LegendConfig {
 | 
				
			|||||||
    showMin: false,
 | 
					    showMin: false,
 | 
				
			||||||
    showMax: false,
 | 
					    showMax: false,
 | 
				
			||||||
    showAvg: wType === widgetType.timeseries,
 | 
					    showAvg: wType === widgetType.timeseries,
 | 
				
			||||||
    showTotal: false
 | 
					    showTotal: false,
 | 
				
			||||||
 | 
					    showLatest: false
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -362,6 +364,7 @@ export interface LegendKeyData {
 | 
				
			|||||||
  max: string;
 | 
					  max: string;
 | 
				
			||||||
  avg: string;
 | 
					  avg: string;
 | 
				
			||||||
  total: string;
 | 
					  total: string;
 | 
				
			||||||
 | 
					  latest: string;
 | 
				
			||||||
  hidden: boolean;
 | 
					  hidden: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2501,11 +2501,13 @@
 | 
				
			|||||||
        "show-min": "Show min value",
 | 
					        "show-min": "Show min value",
 | 
				
			||||||
        "show-avg": "Show average value",
 | 
					        "show-avg": "Show average value",
 | 
				
			||||||
        "show-total": "Show total value",
 | 
					        "show-total": "Show total value",
 | 
				
			||||||
 | 
					        "show-latest": "Show latest value",
 | 
				
			||||||
        "settings": "Legend settings",
 | 
					        "settings": "Legend settings",
 | 
				
			||||||
        "min": "min",
 | 
					        "min": "min",
 | 
				
			||||||
        "max": "max",
 | 
					        "max": "max",
 | 
				
			||||||
        "avg": "avg",
 | 
					        "avg": "avg",
 | 
				
			||||||
        "total": "total",
 | 
					        "total": "total",
 | 
				
			||||||
 | 
					        "latest": "latest",
 | 
				
			||||||
        "comparison-time-ago": {
 | 
					        "comparison-time-ago": {
 | 
				
			||||||
            "previousInterval": "(previous interval)",
 | 
					            "previousInterval": "(previous interval)",
 | 
				
			||||||
            "customInterval": "(custom interval)",
 | 
					            "customInterval": "(custom interval)",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user