MudProgressCircular: Calculate view box size based on stroke width#11557
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #11557 +/- ##
=======================================
Coverage 91.20% 91.20%
=======================================
Files 466 466
Lines 14688 14697 +9
Branches 2855 2855
=======================================
+ Hits 13396 13405 +9
Misses 646 646
Partials 646 646 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that the SVG viewBox of MudProgressCircular dynamically adjusts when the StrokeWidth changes, preventing the circle from being clipped.
- Calculates a new
viewBoxinOnParametersSetbased onStrokeWidth - Updates the Razor markup to use the computed
_viewBoxinstead of a static value - Adds unit tests to verify correct viewBox values across stroke widths
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/MudBlazor/Components/Progress/MudProgressCircular.razor.cs | Compute _viewBox dynamically in OnParametersSet |
| src/MudBlazor/Components/Progress/MudProgressCircular.razor | Bind SVG viewBox attribute to the computed _viewBox |
| src/MudBlazor.UnitTests/Components/ProgressCircularTests.cs | Add and correct tests for viewBox logic and existing test cases |
| src/MudBlazor.UnitTests.Viewer/TestComponents/Progress/MudProgressCircularWidthTest.razor | Provide a live demo for variable StrokeWidth in the test viewer |
Comments suppressed due to low confidence (2)
src/MudBlazor.UnitTests/Components/ProgressCircularTests.cs:158
- Consider adding a test case for a negative
StrokeWidth(e.g.,-5) to validate that theMath.Max(0, StrokeWidth)guard correctly treats negatives as zero and produces the same viewBox.
[TestCase(0, "24 24 40 40")]
src/MudBlazor/Components/Progress/MudProgressCircular.razor.cs:21
- Replace the hard-coded
MagicNumberwith a computed circumference (e.g.,int circumference = (int)(2 * Math.PI * CircleRadius)) or rename it to something likeCircumferenceto avoid magic numbers and make future radius changes safe.
private const int MagicNumber = 126; // weird, but required for the SVG to work
|
Yeah, this was one of the known bug. Happy to see this PR. |
|



Description
Currently the view box size remains static while the stroke width value can be changed. This can result in a stroke width that eventually renders the circle outside the bounds of the view box. This PR adjusts the view box size based on the value of the stroke width.
Resolves #11550
How Has This Been Tested?
Visually and Unit test
Type of Changes
Checklist
dev).