Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 0cca317

Browse files
authored
fix(progress-circular): correct rendering for diameter bigger than 60 (#11896)
1 parent 3aa9090 commit 0cca317

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/components/progressCircular/js/progressCircularDirective.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
159159
diameter = getSize(scope.mdDiameter);
160160
strokeWidth = getStroke(diameter);
161161
path.attr('d', getSvgArc(diameter, strokeWidth, true));
162-
path.attr('stroke-dasharray', (diameter - strokeWidth) * $window.Math.PI * 0.75);
162+
path.attr('stroke-dasharray', getDashLength(diameter, strokeWidth, 75));
163163
}
164164
startIndeterminateAnimation();
165165
} else {
@@ -172,7 +172,7 @@ function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
172172
diameter = getSize(scope.mdDiameter);
173173
strokeWidth = getStroke(diameter);
174174
path.attr('d', getSvgArc(diameter, strokeWidth, false));
175-
path.attr('stroke-dasharray', (diameter - strokeWidth) * $window.Math.PI);
175+
path.attr('stroke-dasharray', getDashLength(diameter, strokeWidth, 100));
176176
}
177177

178178
element.attr('aria-valuenow', newValue);
@@ -216,12 +216,12 @@ function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
216216
path.attr('stroke-linecap', 'square');
217217
if (scope.mdMode == MODE_INDETERMINATE) {
218218
path.attr('d', getSvgArc(diameter, strokeWidth, true));
219-
path.attr('stroke-dasharray', (diameter - strokeWidth) * $window.Math.PI * 0.75);
220-
path.attr('stroke-dashoffset', getDashLength(diameter, strokeWidth, 1, 75));
219+
path.attr('stroke-dasharray', getDashLength(diameter, strokeWidth, 75));
220+
path.attr('stroke-dashoffset', getDashOffset(diameter, strokeWidth, 1, 75));
221221
} else {
222222
path.attr('d', getSvgArc(diameter, strokeWidth, false));
223-
path.attr('stroke-dasharray', (diameter - strokeWidth) * $window.Math.PI);
224-
path.attr('stroke-dashoffset', getDashLength(diameter, strokeWidth, 0, 100));
223+
path.attr('stroke-dasharray', getDashLength(diameter, strokeWidth, 100));
224+
path.attr('stroke-dashoffset', getDashOffset(diameter, strokeWidth, 0, 100));
225225
renderCircle(value, value);
226226
}
227227

@@ -255,7 +255,7 @@ function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
255255
}
256256

257257
function renderFrame(value) {
258-
path.attr('stroke-dashoffset', getDashLength(diameter, strokeWidth, value, dashLimit));
258+
path.attr('stroke-dashoffset', getDashOffset(diameter, strokeWidth, value, dashLimit));
259259
path.attr('transform','rotate(' + (rotation) + ' ' + diameter/2 + ' ' + diameter/2 + ')');
260260
}
261261
}
@@ -330,12 +330,12 @@ function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
330330
* @param {number} diameter Diameter of the container.
331331
* @param {number} strokeWidth Stroke width to be used when drawing circle
332332
* @param {number} value Percentage of circle (between 0 and 100)
333-
* @param {number} limit Max percentage for circle
333+
* @param {number} maxArcLength Maximum length of arc as a percentage of circle (between 0 and 100)
334334
*
335-
* @returns {number} Stroke length for progres circle
335+
* @returns {number} Stroke length for progress circle
336336
*/
337-
function getDashLength(diameter, strokeWidth, value, limit) {
338-
return (diameter - strokeWidth) * $window.Math.PI * ((3 * (limit || 100) / 100) - (value/100));
337+
function getDashOffset(diameter, strokeWidth, value, maxArcLength) {
338+
return getSpinnerCircumference(diameter, strokeWidth) * ((maxArcLength - value) / 100);
339339
}
340340

341341
/**
@@ -373,4 +373,29 @@ function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
373373
return $mdProgressCircular.strokeWidth / 100 * diameter;
374374
}
375375

376+
/**
377+
* Return length of the dash
378+
*
379+
* @param {number} diameter Diameter of the container.
380+
* @param {number} strokeWidth Stroke width to be used when drawing circle
381+
* @param {number} value Percentage of circle (between 0 and 100)
382+
*
383+
* @returns {number} Length of the dash
384+
*/
385+
function getDashLength(diameter, strokeWidth, value) {
386+
return getSpinnerCircumference(diameter, strokeWidth) * (value / 100);
387+
}
388+
389+
/**
390+
* Return circumference of the spinner
391+
*
392+
* @param {number} diameter Diameter of the container.
393+
* @param {number} strokeWidth Stroke width to be used when drawing circle
394+
*
395+
* @returns {number} Circumference of the spinner
396+
*/
397+
function getSpinnerCircumference(diameter, strokeWidth) {
398+
return ((diameter - strokeWidth) * $window.Math.PI);
399+
}
400+
376401
}

0 commit comments

Comments
 (0)