Skip to content

Commit 6326d7a

Browse files
committed
Fix issue ashish-chopra#49 reading-label container overlaps elements below it (with example) [bug]
1 parent 04c494e commit 6326d7a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed
+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
<div class="reading-block" #reading [style.fontSize]="size * 0.22 + 'px'" [style.lineHeight]="size + 'px'">
1+
<div class="reading-block" #reading [style.fontSize]="size * 0.22 + 'px'">
22
<!-- This block can not be indented correctly, because line breaks cause layout spacing, related problem: https://pt.stackoverflow.com/q/276760/2998 -->
33
<u class="reading-affix" [ngSwitch]="_prependChild != null"><ng-content select="ngx-gauge-prepend" *ngSwitchCase="true"></ng-content><ng-container *ngSwitchCase="false">{{prepend}}</ng-container></u><ng-container [ngSwitch]="_valueDisplayChild != null"><ng-content *ngSwitchCase="true" select="ngx-gauge-value"></ng-content><ng-container *ngSwitchCase="false">{{value | number}}</ng-container></ng-container><u class="reading-affix" [ngSwitch]="_appendChild != null"><ng-content select="ngx-gauge-append" *ngSwitchCase="true"></ng-content><ng-container *ngSwitchCase="false">{{append}}</ng-container></u>
44
</div>
5-
<div class="reading-label"
6-
[style.fontSize]="size / 13 + 'px'"
7-
[style.lineHeight]="(5 * size / 13) + size + 'px'"
5+
<div class="reading-label" #rLabel
6+
[style.fontSize]="size / 13 + 'px'"
87
[ngSwitch]="_labelChild != null">
98
<ng-content select="ngx-gauge-label" *ngSwitchCase="true"></ng-content>
109
<ng-container *ngSwitchCase="false">{{label}}</ng-container>
1110
</div>
12-
<canvas #canvas></canvas>
11+
<canvas #canvas></canvas>

projects/ngx-gauge/src/gauge/gauge.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export type NgxGaugeCap = 'round' | 'butt';
5555
export class NgxGauge implements AfterViewInit, OnChanges, OnDestroy {
5656

5757
@ViewChild('canvas', { static: true }) _canvas: ElementRef;
58+
@ViewChild('rLabel', {static: true}) _label: ElementRef;
59+
@ViewChild('reading', {static: true}) _reading: ElementRef;
5860

5961
@ContentChild(NgxGaugeLabel, {static: false}) _labelChild: NgxGaugeLabel;
6062
@ContentChild(NgxGaugePrepend, {static: false}) _prependChild: NgxGaugePrepend;
@@ -139,7 +141,7 @@ export class NgxGauge implements AfterViewInit, OnChanges, OnDestroy {
139141
ov = changes['value'].previousValue;
140142
}
141143
this._update(nv, ov);
142-
}
144+
}
143145
if (isCanvasPropertyChanged) {
144146
this._destroy();
145147
this._init();
@@ -152,6 +154,10 @@ export class NgxGauge implements AfterViewInit, OnChanges, OnDestroy {
152154
this._renderer.setElementStyle(this._elementRef.nativeElement, 'height', cssUnit(this._size));
153155
this._canvas.nativeElement.width = this.size;
154156
this._canvas.nativeElement.height = this.size;
157+
this._renderer.setElementStyle(this._label.nativeElement,
158+
'transform', 'translateY(' + (this.size / 3 * 2 - this.size / 13 / 4) + 'px)');
159+
this._renderer.setElementStyle(this._reading.nativeElement,
160+
'transform', 'translateY(' + (this.size / 2 - this.size * 0.22 / 2) + 'px)');
155161
}
156162

157163
ngAfterViewInit() {
@@ -308,4 +314,4 @@ export class NgxGauge implements AfterViewInit, OnChanges, OnDestroy {
308314
this._create(nv, ov);
309315
}
310316

311-
}
317+
}

src/app/app.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Document
1717
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
1818
</li>
1919
</ul>
20-
<ngx-gauge [value]="currentValue"></ngx-gauge>
20+
<ngx-gauge [value]="currentValue" [label]="'Label'"></ngx-gauge>
2121
<button (click)="changeValue()">change</button>
2222
<input type="checkbox" #checkbox>
2323
<router-outlet></router-outlet>

0 commit comments

Comments
 (0)