@@ -543,19 +543,19 @@ angular.module('patternfly.card').directive('pfCard', function () {
543543 </div>
544544
545545 <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>
547547 center-label =<br> 'used'
548548 </div>
549549 <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>
551551 center-label =<br> 'available'
552552 </div>
553553 <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>
555555 center-label =<br> 'percent'
556556 </div>
557557 <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>
559559 center-label =<br> ' none'
560560 </div>
561561
@@ -600,6 +600,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
600600 'total': '1000'
601601 };
602602
603+ $scope.usedLabel = "used";
604+
603605 $scope.availConfig = {
604606 'chartId': 'availChart',
605607 'units': 'GB',
@@ -611,6 +613,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
611613 'total': '1000'
612614 };
613615
616+ $scope.availLabel = "available";
617+
614618 $scope.pctConfig = {
615619 'chartId': 'pctChart',
616620 'units': 'GB',
@@ -622,6 +626,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
622626 'total': '1000'
623627 };
624628
629+ $scope.pctLabel = "percent";
630+
625631 $scope.noneConfig = {
626632 'chartId': 'noneChart',
627633 'units': 'GB',
@@ -633,6 +639,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
633639 'total': '1000'
634640 };
635641
642+ $scope.noLabel = "none";
643+
636644 $scope.custConfig = {
637645 'chartId': 'custChart',
638646 'units': 'MHz',
@@ -643,8 +651,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
643651 d[0].value + ' ' + d[0].name +
644652 '</span>';
645653 },
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>' +
648656 '<tspan dy="20" x="0" class="donut-title-small-pf">Free</tspan>';
649657 }
650658 };
@@ -749,6 +757,30 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
749757 } ;
750758 } ;
751759
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+
752784 $scope . updateAll = function ( scope ) {
753785 $scope . updateAvailable ( ) ;
754786 $scope . config . data = $scope . getDonutData ( $scope ) ;
@@ -763,34 +795,25 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
763795 link : function ( scope , element ) {
764796 var setupDonutChartTitle = function ( ) {
765797 $timeout ( function ( ) {
766- var donutChartTitle , bigText , smText ;
798+ var donutChartTitle , centerLabelText ;
767799
768800 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 ;
773809 } 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>' ;
794817 }
795818 } , 300 ) ;
796819 } ;
0 commit comments