Skip to content

Commit 6576c54

Browse files
palbizuPatricio Albizu
andauthored
feat: Adding count reference to Gauge List (#1203)
Co-authored-by: Patricio Albizu <patricioalbizu@Patricios-MacBook-Pro.local>
1 parent 9ecc56c commit 6576c54

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

projects/observability/src/shared/components/gauge-list/gauge-list.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
22
import { TypedSimpleChanges } from '@hypertrace/common';
3-
import { maxBy } from 'lodash-es';
3+
import { maxBy, sum } from 'lodash-es';
44

55
@Component({
66
selector: 'ht-gauge-list',
@@ -25,6 +25,7 @@ import { maxBy } from 'lodash-es';
2525
</div>
2626
<div class="value">
2727
<span>{{ item.value | htDisplayNumber }}</span>
28+
<span *ngIf="this.showPercentages"> ({{ item.percentage | htDisplayNumber }}%)</span>
2829
</div>
2930
</ng-container>
3031
</div>
@@ -43,6 +44,9 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
4344
@Input()
4445
public showLabels: boolean = true;
4546

47+
@Input()
48+
public showPercentages: boolean = false;
49+
4650
@Input()
4751
public showItemBorders: boolean = true;
4852

@@ -73,12 +77,14 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
7377
}
7478

7579
const colorLookupMap = this.buildColorLookupForData(this.items);
80+
const totalCount = sum(this.items.map((gaugeItem: GaugeItem) => gaugeItem.value));
7681

7782
this.itemOptions = this.items.map(option => ({
7883
label: option.label,
7984
color: colorLookupMap.get(option.colorKey ?? option.label),
8085
width: `${((option.value / maxValue!) * 100).toFixed(2)}%`,
8186
value: option.value,
87+
percentage: totalCount > 0 ? (option.value / totalCount) * 100 : 100,
8288
original: option
8389
}));
8490
}
@@ -95,6 +101,7 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
95101
export interface GaugeItem {
96102
label: string;
97103
value: number;
104+
percentage?: number;
98105
colorKey?: string;
99106
}
100107

0 commit comments

Comments
 (0)