@@ -169,7 +169,7 @@ $.fn.progress = function(parameters) {
169
169
value : module . helper . forceArray ( $module . data ( metadata . value ) )
170
170
}
171
171
;
172
- if ( data . total ) {
172
+ if ( data . total !== undefined ) {
173
173
module . debug ( 'Total value set from metadata' , data . total ) ;
174
174
module . set . total ( data . total ) ;
175
175
}
@@ -272,18 +272,18 @@ $.fn.progress = function(parameters) {
272
272
var
273
273
index_ = index || 0 ,
274
274
value = module . get . value ( index_ ) ,
275
- total = module . total || 0 ,
275
+ total = module . get . total ( ) ,
276
276
percent = ( animating )
277
277
? module . get . displayPercent ( index_ )
278
278
: module . get . percent ( index_ ) ,
279
- left = ( module . total > 0 )
280
- ? ( total - value )
279
+ left = ( total !== false )
280
+ ? Math . max ( 0 , total - value )
281
281
: ( 100 - percent )
282
282
;
283
283
templateText = templateText || '' ;
284
284
templateText = templateText
285
285
. replace ( '{value}' , value )
286
- . replace ( '{total}' , total )
286
+ . replace ( '{total}' , total || 0 )
287
287
. replace ( '{left}' , left )
288
288
. replace ( '{percent}' , percent )
289
289
. replace ( '{bar}' , settings . text . bars [ index_ ] || '' )
@@ -373,7 +373,7 @@ $.fn.progress = function(parameters) {
373
373
return module . nextValue || module . value && module . value [ index || 0 ] || 0 ;
374
374
} ,
375
375
total : function ( ) {
376
- return module . total || false ;
376
+ return module . total !== undefined ? module . total : false ;
377
377
}
378
378
} ,
379
379
@@ -506,23 +506,23 @@ $.fn.progress = function(parameters) {
506
506
;
507
507
} ) ;
508
508
var hasTotal = module . has . total ( ) ;
509
- var totalPecent = module . helper . sum ( percents ) ;
510
- var isMultpleValues = percents . length > 1 && hasTotal ;
509
+ var totalPercent = module . helper . sum ( percents ) ;
510
+ var isMultipleValues = percents . length > 1 && hasTotal ;
511
511
var sumTotal = module . helper . sum ( module . helper . forceArray ( module . value ) ) ;
512
- if ( isMultpleValues && sumTotal > module . total ) {
512
+ if ( isMultipleValues && sumTotal > module . total ) {
513
513
// Sum values instead of pecents to avoid precision issues when summing floats
514
514
module . error ( error . sumExceedsTotal , sumTotal , module . total ) ;
515
- } else if ( ! isMultpleValues && totalPecent > 100 ) {
516
- // Sum before rouding since sum of rounded may have error though sum of actual is fine
517
- module . error ( error . tooHigh , totalPecent ) ;
518
- } else if ( totalPecent < 0 ) {
519
- module . error ( error . tooLow , totalPecent ) ;
515
+ } else if ( ! isMultipleValues && totalPercent > 100 ) {
516
+ // Sum before rounding since sum of rounded may have error though sum of actual is fine
517
+ module . error ( error . tooHigh , totalPercent ) ;
518
+ } else if ( totalPercent < 0 ) {
519
+ module . error ( error . tooLow , totalPercent ) ;
520
520
} else {
521
521
var autoPrecision = settings . precision > 0
522
522
? settings . precision
523
- : isMultpleValues
523
+ : isMultipleValues
524
524
? module . helper . derivePrecision ( Math . min . apply ( null , module . value ) , module . total )
525
- : undefined ;
525
+ : 0 ;
526
526
527
527
// round display percentage
528
528
var roundedPercents = percents . map ( function ( percent ) {
@@ -532,7 +532,7 @@ $.fn.progress = function(parameters) {
532
532
;
533
533
} ) ;
534
534
module . percent = roundedPercents ;
535
- if ( ! hasTotal ) {
535
+ if ( hasTotal ) {
536
536
module . value = roundedPercents . map ( function ( percent ) {
537
537
return ( autoPrecision > 0 )
538
538
? Math . round ( ( percent / 100 ) * module . total * ( 10 * autoPrecision ) ) / ( 10 * autoPrecision )
@@ -541,11 +541,7 @@ $.fn.progress = function(parameters) {
541
541
} ) ;
542
542
if ( settings . limitValues ) {
543
543
module . value = module . value . map ( function ( value ) {
544
- return ( value > 100 )
545
- ? 100
546
- : ( module . value < 0 )
547
- ? 0
548
- : module . value ;
544
+ return Math . max ( 0 , Math . min ( 100 , value ) ) ;
549
545
} ) ;
550
546
}
551
547
}
@@ -622,7 +618,7 @@ $.fn.progress = function(parameters) {
622
618
if ( text !== undefined ) {
623
619
$progress . text ( module . get . text ( text , index ) ) ;
624
620
}
625
- else if ( settings . label == 'ratio' && module . total ) {
621
+ else if ( settings . label == 'ratio' && module . has . total ( ) ) {
626
622
module . verbose ( 'Adding ratio to bar label' ) ;
627
623
$progress . text ( module . get . text ( settings . text . ratio , index ) ) ;
628
624
}
@@ -752,7 +748,7 @@ $.fn.progress = function(parameters) {
752
748
}
753
749
value = module . get . normalizedValue ( value ) ;
754
750
if ( hasTotal ) {
755
- percentComplete = ( value / module . total ) * 100 ;
751
+ percentComplete = module . total > 0 ? ( value / module . total ) * 100 : 100 ;
756
752
module . debug ( 'Calculating percent complete from total' , percentComplete ) ;
757
753
}
758
754
else {
0 commit comments