1
1
import { ChangeDetectionStrategy , Component , EventEmitter , Input , OnChanges , Output } from '@angular/core' ;
2
2
import { TypedSimpleChanges } from '@hypertrace/common' ;
3
- import { maxBy } from 'lodash-es' ;
3
+ import { maxBy , sum } from 'lodash-es' ;
4
4
5
5
@Component ( {
6
6
selector : 'ht-gauge-list' ,
@@ -25,6 +25,7 @@ import { maxBy } from 'lodash-es';
25
25
</div>
26
26
<div class="value">
27
27
<span>{{ item.value | htDisplayNumber }}</span>
28
+ <span *ngIf="this.showPercentages"> ({{ item.percentage | htDisplayNumber }}%)</span>
28
29
</div>
29
30
</ng-container>
30
31
</div>
@@ -43,6 +44,9 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
43
44
@Input ( )
44
45
public showLabels : boolean = true ;
45
46
47
+ @Input ( )
48
+ public showPercentages : boolean = false ;
49
+
46
50
@Input ( )
47
51
public showItemBorders : boolean = true ;
48
52
@@ -73,12 +77,14 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
73
77
}
74
78
75
79
const colorLookupMap = this . buildColorLookupForData ( this . items ) ;
80
+ const totalCount = sum ( this . items . map ( ( gaugeItem : GaugeItem ) => gaugeItem . value ) ) ;
76
81
77
82
this . itemOptions = this . items . map ( option => ( {
78
83
label : option . label ,
79
84
color : colorLookupMap . get ( option . colorKey ?? option . label ) ,
80
85
width : `${ ( ( option . value / maxValue ! ) * 100 ) . toFixed ( 2 ) } %` ,
81
86
value : option . value ,
87
+ percentage : totalCount > 0 ? ( option . value / totalCount ) * 100 : 100 ,
82
88
original : option
83
89
} ) ) ;
84
90
}
@@ -95,6 +101,7 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
95
101
export interface GaugeItem {
96
102
label : string ;
97
103
value : number ;
104
+ percentage ?: number ;
98
105
colorKey ?: string ;
99
106
}
100
107
0 commit comments