Skip to content

Commit 998c222

Browse files
authored
fix(progress): fix calculations when total > 100
The limitValues setting limits the values between 0 and 100. Instead it should limit the calculated precentages instead and calculate the actual values afterwards. In addition low value increase in combination with a high total, led into wrong calculated values making the progress bar stuck
1 parent dbe6ee4 commit 998c222

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/definitions/modules/progress.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,14 @@ $.fn.progress = function(parameters) {
500500
},
501501
percent: function(percents) {
502502
percents = module.helper.forceArray(percents).map(function(percent) {
503-
return (typeof percent == 'string')
503+
percent = (typeof percent == 'string')
504504
? +(percent.replace('%', ''))
505505
: percent
506506
;
507+
return (settings.limitValues)
508+
? Math.max(0, Math.min(100, percent))
509+
: percent
510+
;
507511
});
508512
var hasTotal = module.has.total();
509513
var totalPercent = module.helper.sum(percents);
@@ -533,21 +537,15 @@ $.fn.progress = function(parameters) {
533537
});
534538
module.percent = roundedPercents;
535539
if (hasTotal) {
536-
module.value = roundedPercents.map(function (percent) {
540+
module.value = percents.map(function (percent) {
537541
return (autoPrecision > 0)
538542
? Math.round((percent / 100) * module.total * (10 * autoPrecision)) / (10 * autoPrecision)
539543
: Math.round((percent / 100) * module.total * 10) / 10
540544
;
541545
});
542-
if (settings.limitValues) {
543-
module.value = module.value.map(function (value) {
544-
return Math.max(0, Math.min(100, value));
545-
});
546-
}
547546
}
548547
module.set.barWidth(percents);
549548
module.set.labelInterval();
550-
module.set.labels();
551549
}
552550
settings.onChange.call(element, percents, module.value, module.total);
553551
},

0 commit comments

Comments
 (0)