@@ -13,7 +13,7 @@ angular.module('patternfly.card', []);
1313 * Charts module for patternfly. Must Include d3.js and c3.js to use
1414 *
1515 */
16- angular . module ( 'patternfly.charts' , [ ] ) ;
16+ angular . module ( 'patternfly.charts' , [ 'patternfly.utils' ] ) ;
1717
1818; /**
1919 * @name patternfly card
@@ -672,7 +672,7 @@ angular.module('patternfly.card').directive('pfCard', function () {
672672 </file>
673673 </example>
674674 */
675- angular . module ( 'patternfly.charts' ) . directive ( 'pfDonutPctChart' , [ "c3ChartDefaults" , "$timeout" , function ( c3ChartDefaults , $timeout ) {
675+ angular . module ( 'patternfly.charts' ) . directive ( 'pfDonutPctChart' , [ "c3ChartDefaults" , "pfUtils" , " $timeout", function ( c3ChartDefaults , pfUtils , $timeout ) {
676676 'use strict' ;
677677
678678 return {
@@ -796,7 +796,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
796796 $scope . config . tooltip = donutTooltip ( scope ) ;
797797 } ;
798798
799- $scope . config = angular . merge ( { } , c3ChartDefaults . getDefaultDonutConfig ( ) , $scope . config ) ;
799+ $scope . config = pfUtils . merge ( c3ChartDefaults . getDefaultDonutConfig ( ) , $scope . config ) ;
800800 $scope . updateAll ( $scope ) ;
801801 }
802802 ] ,
@@ -974,7 +974,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
974974 </file>
975975 </example>
976976 */
977- angular . module ( 'patternfly.charts' ) . directive ( 'pfSparklineChart' , [ "c3ChartDefaults" , function ( c3ChartDefaults ) {
977+ angular . module ( 'patternfly.charts' ) . directive ( 'pfSparklineChart' , [ "c3ChartDefaults" , "pfUtils" , function ( c3ChartDefaults , pfUtils ) {
978978 'use strict' ;
979979 return {
980980 restrict : 'A' ,
@@ -1131,7 +1131,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11311131 $scope . defaultConfig . units = '' ;
11321132
11331133 // Override defaults with callers specifications
1134- $scope . config = angular . merge ( { } , $scope . defaultConfig , $scope . config ) ;
1134+ $scope . config = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
11351135
11361136 // Convert the given data to C3 chart format
11371137 $scope . config . data = $scope . getSparklineData ( $scope . chartData ) ;
@@ -1140,7 +1140,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11401140
11411141 link : function ( scope ) {
11421142 scope . $watch ( 'config' , function ( ) {
1143- scope . config = angular . merge ( { } , scope . defaultConfig , scope . config ) ;
1143+ scope . config = pfUtils . merge ( scope . defaultConfig , scope . config ) ;
11441144 } , true ) ;
11451145 scope . $watch ( 'chartHeight' , function ( ) {
11461146 scope . config . size . height = scope . chartHeight ;
@@ -2969,6 +2969,58 @@ angular
29692969 }
29702970 } ;
29712971 } ) ;
2972+ ; ( function ( ) {
2973+ 'use strict' ;
2974+
2975+ angular . module ( 'patternfly.utils' ) . constant ( 'pfUtils' , {
2976+ merge : function ( source1 , source2 ) {
2977+ var retValue ;
2978+
2979+ if ( typeof angular . merge === 'function' ) {
2980+ retValue = this . angularMerge ( source1 , source2 ) ;
2981+ } else if ( typeof _ . merge === 'function' ) {
2982+ retValue = this . _merge ( source1 , source2 ) ;
2983+ } else if ( typeof $ . extend === 'function' ) {
2984+ retValue = this . $extend ( source1 , source2 ) ;
2985+ } else {
2986+ retValue = this . mergeDeep ( source1 , source2 ) ;
2987+ }
2988+
2989+ return retValue ;
2990+ } ,
2991+ angularMerge : function ( source1 , source2 ) {
2992+ return angular . merge ( { } , source1 , source2 ) ;
2993+ } ,
2994+ _merge : function ( source1 , source2 ) {
2995+ return _ . merge ( { } , source1 , source2 ) ;
2996+ } ,
2997+ $extend : function ( source1 , source2 ) {
2998+ return $ . extend ( true , angular . copy ( source1 ) , source2 ) ;
2999+ } ,
3000+ mergeDeep : function ( source1 , source2 ) {
3001+ return mergeDeep ( { } , angular . copy ( source1 ) , angular . copy ( source2 ) ) ;
3002+ }
3003+ } ) ;
3004+ } ) ( ) ;
3005+
3006+ /* This function does not merge/concat Arrays.
3007+ * It replaces the earlier Array with any latter Array.
3008+ */
3009+ function mergeDeep ( dst ) {
3010+ 'use strict' ;
3011+ angular . forEach ( arguments , function ( obj ) {
3012+ if ( obj !== dst ) {
3013+ angular . forEach ( obj , function ( value , key ) {
3014+ if ( dst [ key ] && dst [ key ] . constructor && dst [ key ] . constructor === Object ) {
3015+ mergeDeep ( dst [ key ] , value ) ;
3016+ } else {
3017+ dst [ key ] = value ;
3018+ }
3019+ } ) ;
3020+ }
3021+ } ) ;
3022+ return dst ;
3023+ }
29723024; /**
29733025 * @ngdoc directive
29743026 * @name patternfly.validation:pfValidation
@@ -3330,8 +3382,7 @@ angular.module('patternfly.validation', []).directive('pfValidation', ["$timeout
33303382 </file>
33313383</example>
33323384 */
3333- angular . module ( 'patternfly.views' ) . directive ( 'pfDataList' , [
3334- function ( ) {
3385+ angular . module ( 'patternfly.views' ) . directive ( 'pfDataList' , [ "pfUtils" , function ( pfUtils ) {
33353386 'use strict' ;
33363387 return {
33373388 restrict : 'A' ,
@@ -3360,7 +3411,7 @@ angular.module('patternfly.views').directive('pfDataList', [
33603411 onDblClick : null
33613412 } ;
33623413
3363- $scope . config = angular . merge ( { } , $scope . defaultConfig , $scope . config ) ;
3414+ $scope . config = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
33643415 if ( $scope . config . selectItems && $scope . config . showSelectBox ) {
33653416 throw new Error ( 'pfDataList - ' +
33663417 'Illegal use of pfDataList directive! ' +
@@ -3371,7 +3422,7 @@ angular.module('patternfly.views').directive('pfDataList', [
33713422
33723423 link : function ( scope , element , attrs ) {
33733424 attrs . $observe ( 'config' , function ( ) {
3374- scope . config = angular . merge ( { } , scope . defaultConfig , scope . config ) ;
3425+ scope . config = pfUtils . merge ( scope . defaultConfig , scope . config ) ;
33753426 if ( ! scope . config . selectItems ) {
33763427 scope . config . selectedItems = [ ] ;
33773428 }
@@ -3463,8 +3514,8 @@ angular.module('patternfly.views').directive('pfDataList', [
34633514 } ;
34643515 }
34653516 } ;
3466- }
3467- ] ) ;
3517+ } ]
3518+ ) ;
34683519; /**
34693520 * @ngdoc directive
34703521 * @name patternfly.views.directive:pfDataTiles
@@ -3658,8 +3709,7 @@ angular.module('patternfly.views').directive('pfDataList', [
36583709 </file>
36593710 </example>
36603711 */
3661- angular . module ( 'patternfly.views' ) . directive ( 'pfDataTiles' , [
3662- function ( ) {
3712+ angular . module ( 'patternfly.views' ) . directive ( 'pfDataTiles' , [ "pfUtils" , function ( pfUtils ) {
36633713 'use strict' ;
36643714 return {
36653715 restrict : 'A' ,
@@ -3686,7 +3736,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
36863736 onDblClick : null
36873737 } ;
36883738
3689- $scope . config = angular . merge ( { } , $scope . defaultConfig , $scope . config ) ;
3739+ $scope . config = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
36903740 if ( $scope . config . selectItems && $scope . config . showSelectBox ) {
36913741 throw new Error ( 'pfDataTiles - ' +
36923742 'Illegal use of pfDataTiles directive! ' +
@@ -3695,7 +3745,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
36953745 } ] ,
36963746 link : function ( scope , element , attrs ) {
36973747 attrs . $observe ( 'config' , function ( ) {
3698- scope . config = angular . merge ( { } , scope . defaultConfig , scope . config ) ;
3748+ scope . config = pfUtils . merge ( scope . defaultConfig , scope . config ) ;
36993749 if ( ! scope . config . selectItems ) {
37003750 scope . config . selectedItems = [ ] ;
37013751 }
@@ -3789,8 +3839,8 @@ angular.module('patternfly.views').directive('pfDataTiles', [
37893839 } ;
37903840 }
37913841 } ;
3792- }
3793- ] ) ;
3842+ } ]
3843+ ) ;
37943844; /**
37953845 * @ngdoc directive
37963846 * @name patternfly.views.directive:pfDataToolbar
0 commit comments