This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,8 @@ angular.module('ui.bootstrap.progressbar', [])
27
27
} ) ;
28
28
29
29
bar . recalculatePercentage = function ( ) {
30
- bar . percent = + ( 100 * bar . value / bar . max ) . toFixed ( 2 ) ;
31
-
32
30
var totalPercentage = self . bars . reduce ( function ( total , bar ) {
31
+ bar . percent = + ( 100 * bar . value / bar . max ) . toFixed ( 2 ) ;
33
32
return total + bar . percent ;
34
33
} , 0 ) ;
35
34
@@ -46,6 +45,9 @@ angular.module('ui.bootstrap.progressbar', [])
46
45
47
46
this . removeBar = function ( bar ) {
48
47
this . bars . splice ( this . bars . indexOf ( bar ) , 1 ) ;
48
+ this . bars . forEach ( function ( bar ) {
49
+ bar . recalculatePercentage ( ) ;
50
+ } ) ;
49
51
} ;
50
52
51
53
$scope . $watch ( 'max' , function ( max ) {
Original file line number Diff line number Diff line change @@ -315,6 +315,29 @@ describe('progressbar directive', function() {
315
315
}
316
316
expect ( totalWidth . toFixed ( 2 ) ) . toBe ( '100.00' ) ;
317
317
} ) ;
318
+
319
+ it ( 'should not have a total width over 37.65% when removing bar' , function ( ) {
320
+ $rootScope . objects = [
321
+ { value : 60 , type : 'warning' } ,
322
+ { value : 103 } ,
323
+ { value : 270 , type : 'info' }
324
+ ] ;
325
+ $rootScope . max = 433 ;
326
+ $rootScope . $digest ( ) ;
327
+ var totalWidth = 0 ;
328
+ for ( var i = 0 ; i < 3 ; i ++ ) {
329
+ totalWidth += parseFloat ( getBar ( i ) . css ( 'width' ) ) ;
330
+ }
331
+ expect ( totalWidth . toFixed ( 2 ) ) . toBe ( '100.00' ) ;
332
+
333
+ $rootScope . objects . splice ( 2 , 1 ) ;
334
+ $rootScope . $digest ( ) ;
335
+ totalWidth = 0 ;
336
+ for ( i = 0 ; i < 2 ; i ++ ) {
337
+ totalWidth += parseFloat ( getBar ( i ) . css ( 'width' ) ) ;
338
+ }
339
+ expect ( totalWidth . toFixed ( 2 ) ) . toBe ( '37.65' ) ;
340
+ } ) ;
318
341
} ) ;
319
342
} ) ;
320
343
} ) ;
You can’t perform that action at this time.
0 commit comments