Skip to content

fix(progress-spinner): inaccurate stroke width on really small spinners #7725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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