@@ -543,19 +543,19 @@ angular.module('patternfly.card').directive('pfCard', function () {
543
543
</div>
544
544
545
545
<div class="col-md-3">
546
- <div pf-donut-pct-chart config="usedConfig" data="usedData" center-label="used "></div>
546
+ <div pf-donut-pct-chart config="usedConfig" data="usedData" center-label="usedLabel "></div>
547
547
center-label =<br> 'used'
548
548
</div>
549
549
<div class="col-md-3">
550
- <div pf-donut-pct-chart config="availConfig" data="availData" center-label="available "></div>
550
+ <div pf-donut-pct-chart config="availConfig" data="availData" center-label="availLabel "></div>
551
551
center-label =<br> 'available'
552
552
</div>
553
553
<div class="col-md-3">
554
- <div pf-donut-pct-chart config="pctConfig" data="pctData" center-label="percent "></div>
554
+ <div pf-donut-pct-chart config="pctConfig" data="pctData" center-label="pctLabel "></div>
555
555
center-label =<br> 'percent'
556
556
</div>
557
557
<div class="col-md-3">
558
- <div pf-donut-pct-chart config="noneConfig" data="noneData" center-label="none "></div>
558
+ <div pf-donut-pct-chart config="noneConfig" data="noneData" center-label="noLabel "></div>
559
559
center-label =<br> ' none'
560
560
</div>
561
561
@@ -600,6 +600,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
600
600
'total': '1000'
601
601
};
602
602
603
+ $scope.usedLabel = "used";
604
+
603
605
$scope.availConfig = {
604
606
'chartId': 'availChart',
605
607
'units': 'GB',
@@ -611,6 +613,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
611
613
'total': '1000'
612
614
};
613
615
616
+ $scope.availLabel = "available";
617
+
614
618
$scope.pctConfig = {
615
619
'chartId': 'pctChart',
616
620
'units': 'GB',
@@ -622,6 +626,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
622
626
'total': '1000'
623
627
};
624
628
629
+ $scope.pctLabel = "percent";
630
+
625
631
$scope.noneConfig = {
626
632
'chartId': 'noneChart',
627
633
'units': 'GB',
@@ -633,6 +639,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
633
639
'total': '1000'
634
640
};
635
641
642
+ $scope.noLabel = "none";
643
+
636
644
$scope.custConfig = {
637
645
'chartId': 'custChart',
638
646
'units': 'MHz',
@@ -643,8 +651,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
643
651
d[0].value + ' ' + d[0].name +
644
652
'</span>';
645
653
},
646
- 'centerLabelFn': function (scope ) {
647
- return '<tspan dy="0" x="0" class="donut-title-big-pf">' + scope.data .available + '</tspan>' +
654
+ 'centerLabelFn': function () {
655
+ return '<tspan dy="0" x="0" class="donut-title-big-pf">' + $ scope.custData .available + '</tspan>' +
648
656
'<tspan dy="20" x="0" class="donut-title-small-pf">Free</tspan>';
649
657
}
650
658
};
@@ -749,6 +757,30 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
749
757
} ;
750
758
} ;
751
759
760
+ $scope . getCenterLabelText = function ( ) {
761
+ var centerLabelText ;
762
+
763
+ // default to 'used' info.
764
+ centerLabelText = { bigText : $scope . data . used ,
765
+ smText : $scope . config . units + ' Used' } ;
766
+
767
+ if ( $scope . config . centerLabelFn ) {
768
+ centerLabelText . bigText = $scope . config . centerLabelFn ( ) ;
769
+ centerLabelText . smText = '' ;
770
+ } else if ( $scope . centerLabel === 'none' ) {
771
+ centerLabelText . bigText = '' ;
772
+ centerLabelText . smText = '' ;
773
+ } else if ( $scope . centerLabel === 'available' ) {
774
+ centerLabelText . bigText = $scope . data . available ;
775
+ centerLabelText . smText = $scope . config . units + ' Available' ;
776
+ } else if ( $scope . centerLabel === 'percent' ) {
777
+ centerLabelText . bigText = Math . round ( $scope . data . used / $scope . data . total * 100.0 ) + '%' ;
778
+ centerLabelText . smText = 'of ' + $scope . data . total + ' ' + $scope . config . units ;
779
+ }
780
+
781
+ return centerLabelText ;
782
+ } ;
783
+
752
784
$scope . updateAll = function ( scope ) {
753
785
$scope . updateAvailable ( ) ;
754
786
$scope . config . data = $scope . getDonutData ( $scope ) ;
@@ -763,34 +795,25 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
763
795
link : function ( scope , element ) {
764
796
var setupDonutChartTitle = function ( ) {
765
797
$timeout ( function ( ) {
766
- var donutChartTitle , bigText , smText ;
798
+ var donutChartTitle , centerLabelText ;
767
799
768
800
donutChartTitle = element [ 0 ] . querySelector ( 'text.c3-chart-arcs-title' ) ;
769
- if ( scope . config . centerLabelFn ) {
770
- donutChartTitle . innerHTML = scope . config . centerLabelFn ( scope ) ;
771
- } else if ( scope . centerLabel === 'none' ) {
772
- donutChartTitle . innerHTML = '' ;
801
+ if ( ! donutChartTitle ) {
802
+ return ;
803
+ }
804
+
805
+ centerLabelText = scope . getCenterLabelText ( ) ;
806
+
807
+ if ( centerLabelText . bigText && ! centerLabelText . smText ) {
808
+ donutChartTitle . innerHTML = centerLabelText . bigText ;
773
809
} else {
774
- // default to 'used' info.
775
- bigText = scope . data . used ;
776
- smText = scope . config . units + ' Used' ;
777
-
778
- if ( scope . centerLabel === 'available' ) {
779
- bigText = scope . data . available ;
780
- smText = scope . config . units + ' Available' ;
781
- } else if ( scope . centerLabel === 'percent' ) {
782
- bigText = Math . round ( scope . data . used / scope . data . total * 100.0 ) + '%' ;
783
- smText = 'of ' + scope . data . total + ' ' + scope . config . units ;
784
- }
785
- if ( donutChartTitle ) {
786
- donutChartTitle . innerHTML =
787
- '<tspan dy="0" x="0" class="donut-title-big-pf">' +
788
- bigText +
789
- '</tspan>' +
790
- '<tspan dy="20" x="0" class="donut-title-small-pf">' +
791
- smText +
792
- '</tspan>' ;
793
- }
810
+ donutChartTitle . innerHTML =
811
+ '<tspan dy="0" x="0" class="donut-title-big-pf">' +
812
+ centerLabelText . bigText +
813
+ '</tspan>' +
814
+ '<tspan dy="20" x="0" class="donut-title-small-pf">' +
815
+ centerLabelText . smText +
816
+ '</tspan>' ;
794
817
}
795
818
} , 300 ) ;
796
819
} ;
0 commit comments