@@ -5,26 +5,28 @@ import { Arc, arc, DefaultArcObject } from 'd3-shape';
5
5
@Component ( {
6
6
selector : 'ht-gauge' ,
7
7
template : `
8
- <svg #chartContainer class="gauge" (htLayoutChange)="this.onLayoutChange()" *ngIf="this.rendererData">
9
- <g attr.transform="translate({{ rendererData.origin.x }}, {{ rendererData.origin.y }})">
10
- <path class="gauge-ring" [attr.d]="rendererData.backgroundArc" />
11
- <g
12
- class="input-data"
13
- *ngIf="rendererData.data"
14
- htTooltip="{{ rendererData.data.value }} of {{ rendererData.data.maxValue }}"
15
- >
16
- <path
17
- class="value-ring"
18
- [attr.d]="rendererData.data.valueArc"
19
- [attr.fill]="rendererData.data.threshold.color"
20
- />
21
- <text x="0" y="0" class="value-display" [attr.fill]="rendererData.data.threshold.color">
22
- {{ rendererData.data.value }}
23
- </text>
24
- <text x="0" y="24" class="label-display">{{ rendererData.data.threshold.label }}</text>
8
+ <div class="gauge-container" (htLayoutChange)="this.onLayoutChange()">
9
+ <svg class="gauge" *ngIf="this.rendererData">
10
+ <g attr.transform="translate({{ rendererData.origin.x }}, {{ rendererData.origin.y }})">
11
+ <path class="gauge-ring" [attr.d]="rendererData.backgroundArc" />
12
+ <g
13
+ class="input-data"
14
+ *ngIf="rendererData.data"
15
+ htTooltip="{{ rendererData.data.value }} of {{ rendererData.data.maxValue }}"
16
+ >
17
+ <path
18
+ class="value-ring"
19
+ [attr.d]="rendererData.data.valueArc"
20
+ [attr.fill]="rendererData.data.threshold.color"
21
+ />
22
+ <text x="0" y="0" class="value-display" [attr.fill]="rendererData.data.threshold.color">
23
+ {{ rendererData.data.value }}
24
+ </text>
25
+ <text x="0" y="24" class="label-display">{{ rendererData.data.threshold.label }}</text>
26
+ </g>
25
27
</g>
26
- </g >
27
- </svg >
28
+ </svg >
29
+ </div >
28
30
` ,
29
31
styleUrls : [ './gauge.component.scss' ] ,
30
32
changeDetection : ChangeDetectionStrategy . OnPush
@@ -44,14 +46,18 @@ export class GaugeComponent implements OnChanges {
44
46
public thresholds : GaugeThreshold [ ] = [ ] ;
45
47
46
48
public rendererData ?: GaugeSvgRendererData ;
49
+ public hasLayoutChangeReceived : boolean = false ;
47
50
48
51
public constructor ( public readonly elementRef : ElementRef ) { }
49
52
50
53
public ngOnChanges ( ) : void {
51
- this . rendererData = this . buildRendererData ( ) ;
54
+ if ( this . hasLayoutChangeReceived ) {
55
+ this . rendererData = this . buildRendererData ( ) ;
56
+ }
52
57
}
53
58
54
59
public onLayoutChange ( ) : void {
60
+ this . hasLayoutChangeReceived = true ;
55
61
this . rendererData = this . buildRendererData ( ) ;
56
62
}
57
63
@@ -107,7 +113,7 @@ export class GaugeComponent implements OnChanges {
107
113
private buildRadius ( boundingBox : ClientRect ) : number {
108
114
return Math . min (
109
115
boundingBox . height - GaugeComponent . GAUGE_AXIS_PADDING ,
110
- boundingBox . width / 2 - GaugeComponent . GAUGE_AXIS_PADDING / 2
116
+ boundingBox . height / 2 + Math . min ( boundingBox . height , boundingBox . width ) / 2
111
117
) ;
112
118
}
113
119
0 commit comments