Skip to content

Commit 5d1dbc4

Browse files
committed
Added center label unit tests for pctDonutChart
1 parent 8a70a74 commit 5d1dbc4

File tree

4 files changed

+145
-57
lines changed

4 files changed

+145
-57
lines changed

dist/angular-patternfly.js

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
651651
d[0].value + ' ' + d[0].name +
652652
'</span>';
653653
},
654-
'centerLabelFn': function (scope) {
655-
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>' +
656656
'<tspan dy="20" x="0" class="donut-title-small-pf">Free</tspan>';
657657
}
658658
};
@@ -757,6 +757,30 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
757757
};
758758
};
759759

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+
760784
$scope.updateAll = function (scope) {
761785
$scope.updateAvailable();
762786
$scope.config.data = $scope.getDonutData($scope);
@@ -771,34 +795,25 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
771795
link: function (scope, element) {
772796
var setupDonutChartTitle = function () {
773797
$timeout(function () {
774-
var donutChartTitle, bigText, smText;
798+
var donutChartTitle, centerLabelText;
775799

776800
donutChartTitle = element[0].querySelector('text.c3-chart-arcs-title');
777-
if (scope.config.centerLabelFn) {
778-
donutChartTitle.innerHTML = scope.config.centerLabelFn(scope);
779-
} else if (scope.centerLabel === 'none') {
780-
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;
781809
} else {
782-
// default to 'used' info.
783-
bigText = scope.data.used;
784-
smText = scope.config.units + ' Used';
785-
786-
if (scope.centerLabel === 'available') {
787-
bigText = scope.data.available;
788-
smText = scope.config.units + ' Available';
789-
} else if (scope.centerLabel === 'percent') {
790-
bigText = Math.round(scope.data.used / scope.data.total * 100.0) + '%';
791-
smText = 'of ' + scope.data.total + ' ' + scope.config.units;
792-
}
793-
if (donutChartTitle) {
794-
donutChartTitle.innerHTML =
795-
'<tspan dy="0" x="0" class="donut-title-big-pf">' +
796-
bigText +
797-
'</tspan>' +
798-
'<tspan dy="20" x="0" class="donut-title-small-pf">' +
799-
smText +
800-
'</tspan>';
801-
}
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>';
802817
}
803818
}, 300);
804819
};

0 commit comments

Comments
 (0)