Skip to content

Commit

Permalink
fix(progress-spinner): inaccurate stroke width on really small spinners
Browse files Browse the repository at this point in the history
Fixes the spinner stroke not being accurate on really small spinners (<20px). This is follow-up from angular#7686.
  • Loading branch information
crisbeto committed Oct 11, 2017
1 parent 9b07712 commit 0f531f6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/demo-app/progress-spinner/progress-spinner-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ <h1>Determinate</h1>

<div class="demo-progress-spinner">
<mat-progress-spinner [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
[value]="progressValue" color="primary" [strokeWidth]="1" [diameter]="32"></mat-progress-spinner>
[value]="progressValue" color="warn" [strokeWidth]="1.6" [diameter]="16"></mat-progress-spinner>
<mat-progress-spinner [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
[value]="progressValue" color="accent" [diameter]="50"></mat-progress-spinner>
[value]="progressValue" color="accent" [strokeWidth]="1" [diameter]="32"></mat-progress-spinner>
<mat-progress-spinner [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
[value]="progressValue" color="primary" [diameter]="50"></mat-progress-spinner>
</div>

<h1>Indeterminate</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/progress-spinner/progress-spinner.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
[style.animation-name]="'mat-progress-spinner-stroke-rotate-' + diameter"
[style.stroke-dashoffset.px]="_strokeDashOffset"
[style.stroke-dasharray.px]="_strokeCircumference"
[style.stroke-width.px]="strokeWidth"></circle>
[style.stroke-width.%]="_circleStrokeWidth"></circle>
</svg>
4 changes: 2 additions & 2 deletions src/lib/progress-spinner/progress-spinner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ describe('MatProgressSpinner', () => {
fixture.componentInstance.strokeWidth = 40;
fixture.detectChanges();

expect(parseInt(circleElement.style.strokeWidth))
.toBe(40, 'Expected the custom stroke width to be applied to the circle element.');
expect(parseInt(circleElement.style.strokeWidth)).toBe(30, 'Expected the custom stroke ' +
'width to be applied to the circle element as a percentage of the element size.');
expect(svgElement.getAttribute('viewBox'))
.toBe('0 0 130 130', 'Expected the viewBox to be adjusted based on the stroke width.');
});
Expand Down
5 changes: 5 additions & 0 deletions src/lib/progress-spinner/progress-spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
return null;
}

/** Stroke width of the circle in percent. */
get _circleStrokeWidth() {
return this.strokeWidth / this._elementSize * 100;
}

/** Sets the diameter and adds diameter-specific styles if necessary. */
private _setDiameterAndInitStyles(size: number): void {
this._diameter = size;
Expand Down

0 comments on commit 0f531f6

Please sign in to comment.