@@ -3726,12 +3726,14 @@ angular.module('patternfly.card').component('pfCard', {
3726
3726
onThresholdChange: '&'
3727
3727
},
3728
3728
templateUrl: 'charts/donut/donut-pct-chart.html',
3729
- controller: ["pfUtils", "$element ", "$timeout", function (pfUtils, $element, $timeout ) {
3729
+ controller: ["pfUtils", "$scope ", function (pfUtils, $scope ) {
3730
3730
'use strict';
3731
3731
var ctrl = this, prevData;
3732
+ ctrl.$id = $scope.$id;
3732
3733
3733
3734
ctrl.$onInit = function () {
3734
- ctrl.donutChartId = 'donutPctChart';
3735
+ ctrl.donutChartId = 'donutPctChart' + ctrl.$id;
3736
+
3735
3737
if (ctrl.config.chartId) {
3736
3738
ctrl.donutChartId = ctrl.config.chartId + ctrl.donutChartId;
3737
3739
}
@@ -3743,6 +3745,10 @@ angular.module('patternfly.card').component('pfCard', {
3743
3745
ctrl.data.available = ctrl.data.total - ctrl.data.used;
3744
3746
};
3745
3747
3748
+ ctrl.updatePercentage = function () {
3749
+ ctrl.data.percent = Math.round(ctrl.data.used / ctrl.data.total * 100.0);
3750
+ };
3751
+
3746
3752
ctrl.getStatusColor = function (used, thresholds) {
3747
3753
var threshold = "none";
3748
3754
var color = pfUtils.colorPalette.blue;
@@ -3846,6 +3852,7 @@ angular.module('patternfly.card').component('pfCard', {
3846
3852
3847
3853
ctrl.config = pfUtils.merge(patternfly.c3ChartDefaults().getDefaultDonutConfig(), ctrl.config);
3848
3854
ctrl.updateAvailable();
3855
+ ctrl.updatePercentage();
3849
3856
ctrl.config.data = pfUtils.merge(ctrl.config.data, ctrl.getDonutData());
3850
3857
ctrl.config.color = ctrl.statusDonutColor(ctrl);
3851
3858
ctrl.config.tooltip = ctrl.donutTooltip();
@@ -4022,11 +4029,21 @@ angular.module('patternfly.card').component('pfCard', {
4022
4029
* <li>.tooltipFn(d) - user defined function to customize the tool tip (optional)
4023
4030
* <li>.centerLabelFn - user defined function to customize the text of the center label (optional)
4024
4031
* <li>.onClickFn(d,i) - user defined function to handle when donut arc is clicked upon.
4032
+ * <li>.labelConfig - object containing properties for external label (optional) - default: undefined
4033
+ * <ul>
4034
+ * <li>.orientation - string with possible values: 'left', 'right' (optional) - default: 'center'
4035
+ * <li>.title - string representing a prefix or title (optional) - default: empty string
4036
+ * <li>.label - the wording format to display, possible values: 'used', 'available', 'percent', 'none' (optional) - default: 'used'
4037
+ * <li>.units - unit label for values, ex: 'MHz','GB', etc.. (optional) - default: empty string
4038
+ * <li>.labelFn - function to customize the text of the external label. This callback returns no data. Updated display data can be accessed through the passed and updated parameter 'data'. (optional) - default: undefined
4039
+ * </ul>
4040
+ * </li>
4025
4041
* </ul>
4026
4042
*
4027
4043
* @param {object} data the Total and Used values for the donut chart. Available is calculated as Total - Used.<br/>
4028
4044
* <ul style='list-style-type: none'>
4029
4045
* <li>.used - number representing the amount used
4046
+ * <li>.percent - number representing the percentage used
4030
4047
* <li>.total - number representing the total amount
4031
4048
* <li>.dataAvailable - Flag if there is data available - default: true
4032
4049
* </ul>
@@ -4058,19 +4075,23 @@ angular.module('patternfly.card').component('pfCard', {
4058
4075
<div class="row">
4059
4076
<div class="col-md-3 text-center">
4060
4077
<label>Error Threshold</label>
4061
- <pf-donut-pct-chart config="configErr" data="dataErr" chart="chartErr"></pf-donut-pct-chart>
4078
+ <p class="text-right">
4079
+ <pf-donut-pct-chart config="configErr" data="dataErr" chart="chartErr"></pf-donut-pct-chart>
4080
+ </p>
4062
4081
</div>
4063
- <div class="col-md-3 text-center"" >
4082
+ <div class="col-md-3 text-center">
4064
4083
<label>Warning Threshold</label>
4065
4084
<pf-donut-pct-chart config="configWarn" data="dataWarn"></pf-donut-pct-chart>
4066
4085
</div>
4067
- <div class="col-md-3 text-center"" >
4086
+ <div class="col-md-3 text-center">
4068
4087
<label class="camelcase">{{threshLabel}} Threshold</label>
4069
- <pf-donut-pct-chart config="configDynamic" data="dataDynamic" center-label="labelDynamic"
4070
- on-threshold-change="thresholdChanged(threshold)">
4071
- </pf-donut-pct-chart>
4088
+ <p class="text-left">
4089
+ <pf-donut-pct-chart config="configDynamic" data="dataDynamic" center-label="labelDynamic"
4090
+ on-threshold-change="thresholdChanged(threshold)">
4091
+ </pf-donut-pct-chart>
4092
+ </p>
4072
4093
</div>
4073
- <div class="col-md-3 text-center"" >
4094
+ <div class="col-md-3 text-center">
4074
4095
<label>No Threshold</label>
4075
4096
<pf-donut-pct-chart config="configNoThresh" data="dataNoThresh"></pf-donut-pct-chart>
4076
4097
</div>
@@ -4084,20 +4105,45 @@ angular.module('patternfly.card').component('pfCard', {
4084
4105
4085
4106
<div class="row">
4086
4107
<div class="col-md-3 text-center">
4087
- <pf-donut-pct-chart config="usedConfig" data="usedData" center-label="usedLabel"></pf-donut-pct-chart>
4088
4108
<label>center-label = 'used'</label>
4109
+ <pf-donut-pct-chart config="usedConfig" data="usedData" center-label="usedLabel"></pf-donut-pct-chart>
4089
4110
</div>
4090
4111
<div class="col-md-3 text-center">
4091
- <pf-donut-pct-chart config="availConfig" data="availData" center-label="availLabel"></pf-donut-pct-chart>
4092
4112
<label>center-label = 'available'</label>
4113
+ <pf-donut-pct-chart config="availConfig" data="availData" center-label="availLabel"></pf-donut-pct-chart>
4093
4114
</div>
4094
4115
<div class="col-md-3 text-center">
4095
- <pf-donut-pct-chart config="pctConfig" data="pctData" center-label="pctLabel"></pf-donut-pct-chart>
4096
4116
<label>center-label = 'percent'</label>
4117
+ <pf-donut-pct-chart config="pctConfig" data="pctData" center-label="pctLabel"></pf-donut-pct-chart>
4097
4118
</div>
4098
4119
<div class="col-md-3 text-center">
4120
+ <label>center-label = 'none'</label>
4099
4121
<pf-donut-pct-chart config="noneConfig" data="noneData" center-label="noLabel"></pf-donut-pct-chart>
4100
- <label>center-label = ' none'</label>
4122
+ </div>
4123
+ </div>
4124
+
4125
+ <div class="row">
4126
+ <div class="col-md-12">
4127
+ <hr>
4128
+ </div>
4129
+ </div>
4130
+
4131
+ <div class="row">
4132
+ <div class="col-md-4 text-center">
4133
+ <label>Sized with orientation left 'configLabel'</label>
4134
+ <p class="text-right">
4135
+ <pf-donut-pct-chart config="configOrientationLeft" data="dataOrientationLeft"></pf-donut-pct-chart>
4136
+ </p>
4137
+ </div>
4138
+ <div class="col-md-4 text-center">
4139
+ <label>Sized with 'configLabel'</label>
4140
+ <pf-donut-pct-chart config="configOrientationCenter" data="dataOrientationCenter"></pf-donut-pct-chart>
4141
+ </div>
4142
+ <div class="col-md-4 text-center">
4143
+ <label>Sized with orientation right 'configLabel'</label>
4144
+ <p class="text-left">
4145
+ <pf-donut-pct-chart config="configOrientationRight" data="dataOrientationRight"></pf-donut-pct-chart>
4146
+ </p>
4101
4147
</div>
4102
4148
</div>
4103
4149
@@ -4116,7 +4162,7 @@ angular.module('patternfly.card').component('pfCard', {
4116
4162
</div>
4117
4163
<div class="row">
4118
4164
<div class="col-md-3">
4119
- <form role="form"" >
4165
+ <form role="form">
4120
4166
<div class="form-group">
4121
4167
<label class="checkbox-inline">
4122
4168
<input type="checkbox" ng-model="custData.dataAvailable">Data Available</input>
@@ -4140,6 +4186,7 @@ angular.module('patternfly.card').component('pfCard', {
4140
4186
4141
4187
<file name="script.js">
4142
4188
angular.module( 'patternfly.charts' ).controller( 'ChartCtrl', function( $scope, $interval ) {
4189
+ // start demo 1st row
4143
4190
$scope.configErr = {
4144
4191
'chartId': 'chartErr',
4145
4192
'units': 'GB',
@@ -4196,14 +4243,15 @@ angular.module('patternfly.card').component('pfCard', {
4196
4243
4197
4244
$scope.configNoThresh = {
4198
4245
'chartId': 'chartNoThresh',
4199
- 'units': 'GB',
4246
+ 'units': 'GB'
4200
4247
};
4201
4248
4202
4249
$scope.dataNoThresh = {
4203
4250
'used': '750',
4204
4251
'total': '1000'
4205
4252
};
4206
4253
4254
+ //start demo 2nd row
4207
4255
$scope.usedConfig = {
4208
4256
'chartId': 'usedChart',
4209
4257
'units': 'GB',
@@ -4256,6 +4304,76 @@ angular.module('patternfly.card').component('pfCard', {
4256
4304
4257
4305
$scope.noLabel = "none";
4258
4306
4307
+ //start demo 3rd row
4308
+ $scope.configOrientationLeft = {
4309
+ 'units': 'GB',
4310
+ 'thresholds':{'warning':'60','error':'90'},
4311
+ 'labelConfig': {
4312
+ 'orientation': 'left',
4313
+ 'labelFn': function () {
4314
+ return "<strong>Lorem ipsum</strong><br/>" + $scope.dataOrientationLeft.used + " GB used";
4315
+ }
4316
+ },
4317
+ 'size': {
4318
+ 'height': 85,
4319
+ 'width': 85
4320
+ },
4321
+ 'centerLabelFn': function () {
4322
+ return $scope.dataOrientationLeft.used + "GB";
4323
+ }
4324
+ };
4325
+
4326
+ $scope.dataOrientationLeft = {
4327
+ 'used': '350',
4328
+ 'total': '1000'
4329
+ };
4330
+
4331
+ $scope.configOrientationCenter = {
4332
+ 'units': 'GB',
4333
+ 'thresholds':{'warning':'60','error':'90'},
4334
+ 'labelConfig': {
4335
+ 'label': 'available',
4336
+ 'units': 'GB',
4337
+ 'title': 'Lorem ipsum,'
4338
+ },
4339
+ 'size': {
4340
+ 'height': 115,
4341
+ 'width': 115
4342
+ },
4343
+ 'centerLabelFn': function () {
4344
+ return $scope.dataOrientationCenter.used + "GB";
4345
+ }
4346
+ };
4347
+
4348
+ $scope.dataOrientationCenter = {
4349
+ 'used': '350',
4350
+ 'total': '1000'
4351
+ };
4352
+
4353
+ $scope.configOrientationRight = {
4354
+ 'units': 'GB',
4355
+ 'thresholds':{'warning':'60','error':'90'},
4356
+ 'labelConfig': {
4357
+ 'orientation': 'right',
4358
+ 'labelFn': function () {
4359
+ return "<strong>Lorem ipsum</strong><br/>" + $scope.dataOrientationRight.percent + "% used";
4360
+ }
4361
+ },
4362
+ 'size': {
4363
+ 'height': 85,
4364
+ 'width': 85
4365
+ },
4366
+ 'centerLabelFn': function () {
4367
+ return $scope.dataOrientationRight.percent + "%";
4368
+ }
4369
+ };
4370
+
4371
+ $scope.dataOrientationRight = {
4372
+ 'used': '350',
4373
+ 'total': '1000'
4374
+ };
4375
+
4376
+ //start demo 4th row
4259
4377
$scope.custConfig = {
4260
4378
'chartId': 'custChart',
4261
4379
'units': 'MHz',
@@ -4285,6 +4403,7 @@ angular.module('patternfly.card').component('pfCard', {
4285
4403
</file>
4286
4404
</example>
4287
4405
*/
4406
+
4288
4407
;/**
4289
4408
*
4290
4409
* @description
@@ -17875,7 +17994,7 @@ angular.module('patternfly.wizard').component('pfWizard', {
17875
17994
17876
17995
17877
17996
$templateCache.put('charts/donut/donut-pct-chart.html',
17878
- "<span><pf-c3-chart ng-if=\"$ctrl.data.dataAvailable !== false\" id={{$ctrl.donutChartId}} config=$ctrl.config get-chart-callback=$ctrl.setChart></pf-c3-chart><pf-empty-chart ng-if=\"$ctrl.data.dataAvailable === false\" chart-height=$ctrl.chartHeight></pf-empty-chart></span>"
17997
+ "<span class=pct-donut-chart-pf><span ng-class=\"{'pct-donut-chart-pf-left': $ctrl.config.labelConfig.orientation === 'left', 'pct-donut-chart-pf-right': $ctrl.config.labelConfig.orientation === 'right'}\"><span class=pct-donut-chart-pf-chart><pf-c3-chart ng-if=\"$ctrl.data.dataAvailable !== false\" id={{$ctrl.donutChartId}} config=$ctrl.config get-chart-callback=$ctrl.setChart></pf-c3-chart><pf-empty-chart ng-if=\"$ctrl.data.dataAvailable === false\" chart-height=$ctrl.chartHeight></pf-empty-chart></span> <span ng-if=\"$ctrl.data.dataAvailable !== false && $ctrl.config.labelConfig && !$ctrl.config.labelConfig.labelFn()\" class=pct-donut-chart-pf-label>{{$ctrl.config.labelConfig.title}} <span ng-if=$ctrl.data ng-switch=$ctrl.config.labelConfig.label><span ng-switch-when=none></span> <span ng-switch-when=available>{{$ctrl.data.available}} {{$ctrl.config.labelConfig.units}} available</span> <span ng-switch-when=percent>{{$ctrl.data.percent}}% used</span> <span ng-switch-default=\"\">{{$ctrl.data.used}} {{$ctrl.config.labelConfig.units}} of {{$ctrl.data.total}} {{$ctrl.config.labelConfig.units}} used</span></span></span> <span ng-if=\"$ctrl.data.dataAvailable !== false && $ctrl.config.labelConfig && $ctrl.config.labelConfig.labelFn()\" class=pct-donut-chart-pf-label ng-bind-html=$ctrl.config.labelConfig.labelFn()></span></span></span>"
17879
17998
);
17880
17999
17881
18000
0 commit comments