forked from patternfly/angular-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-patternfly.js
5017 lines (4563 loc) · 180 KB
/
angular-patternfly.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @name patternfly card
*
* @description
* Card module for patternfly.
*
*/
angular.module('patternfly.card', []);
;/**
* @name patternfly
*
* @description
* Charts module for patternfly. Must Include d3.js and c3.js to use
*
*/
angular.module('patternfly.charts', ['patternfly.utils', 'ui.bootstrap']);
;/**
* @name patternfly card
*
* @description
* Filters module for patternfly.
*
*/
angular.module('patternfly.filters', ['patternfly.select']);
;/**
* @name patternfly.form
*
* @description
* Module for formting related functionality, primarily filters.
*/
angular.module('patternfly.form', []);
;/**
* @name patternfly
*
* @description
* Base module for patternfly.
*/
angular.module('patternfly', [
'patternfly.autofocus',
'patternfly.card',
'patternfly.filters',
'patternfly.form',
'patternfly.notification',
'patternfly.select',
'patternfly.sort',
'patternfly.utils',
'patternfly.validation',
'patternfly.views'
]);
;/**
* @name patternfly card
*
* @description
* Sort module for patternfly.
*
*/
angular.module('patternfly.sort', []);
;
angular.module( 'patternfly.utils', [] );
;/**
* @name patternfly
*
* @description
* Views module for patternfly.
*
*/
angular.module('patternfly.views', ['patternfly.utils', 'patternfly.filters', 'patternfly.sort']);
;/**
* @ngdoc directive
* @name patternfly.autofocus:pfFocused
* @restrict A
* @element ANY
* @param {expression=} pfFocused If the expression is true, the element is focused and selected (if possible).
*
* @description
* The focus on element is evaluated from given expression. If the expression provided as an attribute to this directive
* is evaluated as true, the element is selected (and focused).
*
* @example
<example module="patternfly.autofocus">
<file name="index.html">
<div>
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="i1">Focus next input:</label>
<div class="col-sm-10">
<input id="i1" ng-model="isFocus" type="checkbox"></input>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="i2">Focused input:</label>
<div class="col-sm-10">
<input class="form-control" id="i1" ng-model="i2" pf-focused="isFocus" placeholder="This will be selected after checking the box above."></input>
</div>
</div>
</form>
</div>
</file>
</example>
*/
angular.module('patternfly.autofocus', []).directive('pfFocused', ["$timeout", function ($timeout) {
'use strict';
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch(attrs.pfFocused, function (newValue) {
$timeout(function () {
if (newValue) {
element[0].focus();
if (element[0].select) {
element[0].select();
}
}
});
});
}
};
}]);
;/**
* @ngdoc directive
* @name patternfly.card.directive:pfAggregateStatusCard
* @restrict A
* @element ANY
* @param {object} status Status configuration information<br/>
* <ul style='list-style-type: none'>
* <li>.title - the main title of the aggregate status card
* <li>.count - the number count of the main statuses
* <li>.href - the href to navigate to if one clicks on the title or count
* <li>.iconClass - an icon to display to the left of the count
* <li>.notifications - an array of status icons & counts
* <ul style='list-style-type: none'>
* <li>.iconClass - an icon to display to the right of the notification count
* <li>.count - the number count of the notification status
* <li>.href - href to navigate to if one clicks on the notification status icon or count
* </ul>
* </ul>
* When layout='mini', only one notification can be specified:<br>
* <ul style='list-style-type: none'>
* <li>...
* <li><strong>.notification</strong> - an <em>object</em> of containing a single notification icon & count
* <ul style='list-style-type: none'>
* <li>.iconClass - an icon to display to the right of the notification count
* <li>.count - the number count of the notification status
* <li>.href - href to navigate to if one clicks on the notification status icon or count
* </ul>
* </ul>
* @param {boolean=} show-top-border Show/hide the top border, true shows top border, false (default) hides top border
* @param {string=} layout Various alternative layouts the aggregate status card may have:<br/>
* <ul style='list-style-type: none'>
* <li>'mini' displays a mini aggregate status card. Note: when using 'mini' layout, only one notification can be specified in the status object
* <li>'tall' displays a tall aggregate status card. This equals the depreciated 'alt-layout' param.</li>
* </ul>
* @deprecated {boolean=} alt-layout Display the aggregate status card in a 'alternate tall' layout. false (default) displays normal layout, true displays tall layout
*
* @description
* Directive for easily displaying status information
*
* @example
<example module="patternfly.card">
<file name="index.html">
<div ng-controller="CardDemoCtrl" style="display:inline-block;">
<div class="col-md-10">
<label>With Top Border</label>
<div pf-aggregate-status-card status="status" show-top-border="true"></div>
<br/>
<label>No Top Border</label>
<div pf-aggregate-status-card status="status"></div>
<br/>
<label>layout = "mini"</label>
<div pf-aggregate-status-card status="miniAggStatus" show-top-border="true" layout="mini"></div>
<div pf-aggregate-status-card status="miniAggStatus2" show-top-border="true" layout="mini"></div>
<br/>
<label>layout = "tall"</label>
<div pf-aggregate-status-card status="aggStatusAlt" show-top-border="true" layout="tall"></div>
<br/>
<label>Alternate Layout</label>
<i>(depreciated, use layout = 'tall' instead)</i>
</br></br>
<div pf-aggregate-status-card status="aggStatusAlt" show-top-border="true" alt-layout="true"></div>
</div>
</div>
</file>
<file name="script.js">
angular.module( 'patternfly.card' ).controller( 'CardDemoCtrl', function( $scope ) {
$scope.status = {
"title":"Nodes",
"count":793,
"href":"#",
"iconClass": "fa fa-shield",
"notifications":[
{
"iconClass":"pficon pficon-error-circle-o",
"count":4,
"href":"#"
},
{
"iconClass":"pficon pficon-warning-triangle-o",
"count":1
}
]
};
$scope.aggStatusAlt = {
"title":"Providers",
"count":3,
"notifications":[
{
"iconClass":"pficon pficon-openshift",
"count":1,
"href":"#"
},
{
"iconClass":"pficon pficon-kubernetes",
"count":2,
"href":"#"
}
]
};
$scope.miniAggStatus = {
"iconClass":"pficon pficon-container-node",
"title":"Nodes",
"count":52,
"href":"#",
"notification": {
"iconClass":"pficon pficon-error-circle-o",
"count":3
}
};
$scope.miniAggStatus2 = {
"iconClass":"pficon pficon-cluster",
"title":"Adipiscing",
"count":9,
"href":"#",
"notification":{
"iconClass":"pficon pficon-ok"
}
};
});
</file>
</example>
*/
angular.module( 'patternfly.card' ).directive('pfAggregateStatusCard', function () {
'use strict';
return {
restrict: 'A',
scope: {
status: '=',
showTopBorder: '@?',
altLayout: '@?',
layout: '@?'
},
templateUrl: 'card/aggregate-status/aggregate-status-card.html',
link: function (scope) {
scope.shouldShowTopBorder = (scope.showTopBorder === 'true');
scope.isAltLayout = (scope.altLayout === 'true' || scope.layout === 'tall');
scope.isMiniLayout = (scope.layout === 'mini');
}
};
});
;/**
* @ngdoc directive
* @name patternfly.card.directive:pfCard
* @restrict A
* @element ANY
* @param {string} headTitle Title for the card
* @param {string=} subTitle Sub-Title for the card
* @param {boolean=} showTopBorder Show/Hide the blue top border. True shows top border, false (default) hides top border
* @param {boolean=} showTitlesSeparator Show/Hide the grey line between the title and sub-title.
* True (default) shows the line, false hides the line
* @param {object=} footer footer configuration properties:<br/>
* <ul style='list-style-type: none'>
* <li>.iconClass - (optional) the icon to show on the bottom left of the footer panel
* <li>.text - (optional) the text to show on the bottom left of the footer panel, to the right of the icon
* <li>.href - (optional) the href link to navigate to when the footer href is clicked
* <li>.callBackFn - (optional) user defined function to call when the footer href is clicked
* </ul>
* *Note: If a href link and a callBackFn are specified, the href link will be called
* @param {object=} filter filter configuration properties:<br/>
* <ul style='list-style-type: none'>
* <li>.filters - drop down items for the filter.
*<pre class=''>
* Ex: 'filters' : [{label:'Last 30 Days', value:'30'},
* {label:'Last 15 Days', value:'15'},
* {label:'Today', value:'today'}]</pre>
* <li>.defaultFilter - integer, 0 based index into the filters array
* <li>.callBackFn - user defined function to call when a filter is selected
* </ul>
* @description
* Directive for easily displaying a card with html content
*
* @example
<example module="demo">
<file name="index.html">
<div ng-controller="ChartCtrl">
<div pf-card head-title="Card Title" sub-title="Card Subtitle" filter="filterConfigHeader" style="width: 50%">
[Card Contents] <button>Click Me</button> Timeframe filter in header
</div>
<div pf-card head-title="Card Title" sub-title="Card Subtitle" show-top-border="true"
footer="footerConfig" filter="filterConfig" style="width: 50%">
[Card Contents] <button>Click Me</button> Footer with Link & Timeframe filter
</div>
<div pf-card head-title="Performance" sub-title="Last 30 Days" show-top-border="false"
show-titles-separator="false" style="width: 65%" footer="actionBarConfig">
<div pf-trends-chart config="configVirtual" chart-data="dataVirtual"></div>
<div pf-trends-chart config="configPhysical" chart-data="dataPhysical"></div>
<div pf-trends-chart config="configMemory" chart-data="dataMemory"></div>
</div>
</div>
</file>
<file name="script.js">
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope ) {
$scope.footerConfig = {
'iconClass' : 'fa fa-flag',
'text' : 'View All Events',
'callBackFn': function () {
alert("Footer Callback Fn Called");
}
}
$scope.filterConfigHeader = {
'filters' : [{label:'Last 30 Days', value:'30'},
{label:'Last 15 Days', value:'15'},
{label:'Today', value:'today'}],
'callBackFn': function (f) {
alert("Header Filter Callback Fn Called for '" + f.label + "' value = " + f.value);
},
'position' : 'header'
}
$scope.filterConfig = {
'filters' : [{label:'Last 30 Days', value:'30'},
{label:'Last 15 Days', value:'15'},
{label:'Today', value:'today'}],
'callBackFn': function (f) {
alert("Filter Callback Fn Called for '" + f.label + "' value = " + f.value);
},
'defaultFilter' : '1'
}
var today = new Date();
var dates = ['dates'];
for (var d = 20 - 1; d >= 0; d--) {
dates.push(new Date(today.getTime() - (d * 24 * 60 * 60 * 1000)));
}
$scope.configVirtual = {
'chartId' : 'virtualTrendsChart',
'layout' : 'inline',
'trendLabel' : 'Virtual Disk I/O',
'units' : 'GB',
'tooltipType' : 'percentage'
};
$scope.dataVirtual = {
'total': '250',
'xData': dates,
'yData': ['used', '90', '20', '30', '20', '20', '10', '14', '20', '25', '68', '44', '56', '78', '56', '67', '88', '76', '65', '87', '76']
};
$scope.configPhysical = {
'chartId' : 'physicalTrendsChart',
'layout' : 'inline',
'trendLabel' : 'Physical Disk I/O',
'units' : 'MHz',
'tooltipType' : 'percentage'
};
$scope.dataPhysical = {
'total': '250',
'xData': dates,
'yData': ['used', '20', '20', '35', '20', '20', '87', '14', '20', '25', '28', '44', '56', '78', '56', '67', '88', '76', '65', '87', '16']
};
$scope.configMemory = {
'chartId' : 'memoryTrendsChart',
'layout' : 'inline',
'trendLabel' : 'Memory Utilization',
'units' : 'GB',
'tooltipType' : 'percentage'
};
$scope.dataMemory = {
'total': '250',
'xData': dates,
'yData': ['used', '20', '20', '35', '70', '20', '87', '14', '95', '25', '28', '44', '56', '66', '16', '67', '88', '76', '65', '87', '56']
};
$scope.actionBarConfig = {
'iconClass' : 'fa fa-plus-circle',
'text' : 'Add New Cluster',
'callBackFn': function () {
alert("Footer Callback Fn Called");
}
}
});
</file>
</example>
*/
angular.module('patternfly.card').directive('pfCard', function () {
'use strict';
return {
restrict: 'A',
transclude: true,
templateUrl: 'card/basic/card.html',
scope: {
headTitle: '@',
subTitle: '@?',
showTopBorder: '@?',
showTitlesSeparator: '@?',
footer: '=?',
filter: '=?'
},
controller: ["$scope", function ($scope) {
if ($scope.filter && !$scope.currentFilter) {
if ($scope.filter.defaultFilter) {
$scope.currentFilter = $scope.filter.filters[$scope.filter.defaultFilter];
} else {
$scope.currentFilter = $scope.filter.filters[0];
}
}
$scope.footerCallBackFn = function () {
$scope.footerCallBackResult = $scope.footer.callBackFn();
};
$scope.filterCallBackFn = function (f) {
$scope.currentFilter = f;
if ($scope.filter.callBackFn) {
$scope.filterCallBackResult = $scope.filter.callBackFn(f);
}
};
$scope.showHeader = function () {
return ($scope.headTitle || $scope.showFilterInHeader());
};
$scope.showFilterInHeader = function () {
return ($scope.filter && $scope.filter.filters && $scope.filter.position && $scope.filter.position === 'header');
};
}]
};
});
;(function () {
'use strict';
angular.module('patternfly.charts').constant('c3ChartDefaults', {
getDefaultDonut: function (title) {
return {
title: title,
label: {
show: false
},
width: 11
};
},
getDefaultDonutSize: function () {
return {
height: 171 // produces a diameter of 150 and a centered chart
};
},
getDefaultDonutColor: function () {
return {
pattern: ['#0088CE', '#D1D1D1']
};
},
getDefaultDonutTooltip: function () {
return {
show: false
};
},
getDefaultDonutLegend: function () {
return {
show: false
};
},
getDefaultDonutConfig: function (title) {
return {
donut: this.getDefaultDonut(title),
size: this.getDefaultDonutSize(),
legend: this.getDefaultDonutLegend(),
color: this.getDefaultDonutColor(),
tooltip: this.getDefaultDonutTooltip()
};
},
getDefaultSparklineArea: function () {
return {
zerobased: true
};
},
getDefaultSparklineSize: function () {
return {
height: 60
};
},
getDefaultSparklineAxis: function () {
return {
x: {
show: false
},
y: {
show: false
}
};
},
getDefaultSparklineColor: function () {
return {
pattern: ['#0088ce', '#00659c', '#3f9c35', '#ec7a08', '#cc0000']
};
},
getDefaultSparklineLegend: function () {
return {
show: false
};
},
getDefaultSparklinePoint: function () {
return {
r: 1,
focus: {
expand: {
r: 4
}
}
};
},
getDefaultSparklineTooltip: function () {
return {
// because a sparkline should only contain a single data column, the tooltip will only work for a single data column
contents: function (d) {
return '<span class="c3-tooltip-sparkline">' + d[0].value + ' ' + d[0].name + '</span>';
}
};
},
getDefaultSparklineConfig: function () {
return {
area: this.getDefaultSparklineArea(),
size: this.getDefaultSparklineSize(),
axis: this.getDefaultSparklineAxis(),
color: this.getDefaultSparklineColor(),
legend: this.getDefaultSparklineLegend(),
point: this.getDefaultSparklinePoint(),
tooltip: this.getDefaultSparklineTooltip()
};
}
});
})();
;/**
* @ngdoc directive
* @name patternfly.charts.directive:pfC3Chart
*
* @description
* Directive for wrapping c3 library
*
* Note: The 'patternfly.charts' module is not a dependency in the default angular 'patternfly' module.
* In order to use patternfly charts you must add 'patternfly.charts' as a dependency in your application.
*
*
* @param {string} id the ID of the container that the chart should bind to
* @param {expression} config the c3 configuration options for the chart
*
* @example
<example module="patternfly.charts">
<file name="index.html">
<div ng-controller="ChartCtrl">
<div pf-c3-chart id="chartId" config="chartConfig"></div>
<form role="form" style="width:300px">
Total = {{total}}, Used = {{used}}, Available = {{available}}
<div class="form-group">
<label>Used</label>
<input type="text" class="form-control" ng-model="newUsed">
</div>
<input type="button" ng-click="submitform(newUsed)" value="Go" />
</form>
</div>
</file>
<file name="script.js">
angular.module( 'patternfly.charts' ).controller( 'ChartCtrl', function( $scope ) {
$scope.used = 950;
$scope.total = 1000;
$scope.available = $scope.total - $scope.used;
$scope.chartConfig = {
type: "donut",
donut: {
title: "MHz Used",
label: {show: false},
width: 10
},
size: {
height: 130
},
legend: {
show: false
},
color: {
pattern: ["#0088CE","#D1D1D1"]
},
tooltip: {},
data: {
type: "donut",
columns: [
["Used", $scope.used],
["Available", $scope.total - $scope.used]
],
groups: [
["used", "available"]
],
order: null
}
};
$scope.updateAvailable = function (val) {
$scope.available = $scope.total - $scope.used;
}
$scope.submitform = function (val) {
$scope.used = val;
$scope.updateAvailable();
$scope.chartConfig.data.columns = [["Used",$scope.used],["Available",$scope.available]];
};
});
</file>
</example>
*/
(function () {
'use strict';
angular.module('patternfly.charts').directive('pfC3Chart', ["$timeout", function ($timeout) {
return {
restrict: 'A',
scope: {
config: '='
},
template: '<div id=""></div>',
replace: true,
link: function (scope, element, attrs) {
scope.$watch('config', function () {
$timeout(function () {
//generate c3 chart data
var chartData = scope.config;
chartData.bindto = '#' + attrs.id;
c3.generate(chartData);
});
}, true);
}
};
}]);
}());
;/**
* @ngdoc directive
* @name patternfly.charts.directive:pfDonutPctChart
*
* @description
* Directive for rendering a percentage used donut/radial chart. The Used Percentage fill starts at 12 o’clock and
* moves clockwise. Whatever portion of the donut not Used, will be represented as Available, and rendered as a
* gray fill.
* There are three possible fill colors for Used Percentage, dependent on whether or not there are thresholds:<br/>
* <ul>
* <li>When no thresholds exist, or if the used percentage has not surpassed any thresholds, the indicator is blue.
* <li>When the used percentage has surpassed the warning threshold, but not the error threshold, the indicator is orange.
* <li>When the used percentage has surpassed the error threshold, the indicator is is red.
* </ul>
* The directive will calculate the Available Percentage (Total - Used), and display it as a grey radial fill.
*
* <br><br>
* See http://c3js.org/reference.html for a full list of C3 chart options.
*
* @param {object} config configuration properties for the donut chart:<br/>
* <ul style='list-style-type: none'>
* <li>.chartId - the unique id of the donut chart
* <li>.units - unit label for values, ex: 'MHz','GB', etc..
* <li>.thresholds - warning and error percentage thresholds used to determine the Usage Percentage fill color (optional)
* <li>.tooltipFn(d) - user defined function to customize the tool tip (optional)
* <li>.centerLabelFn - user defined function to customize the center label (optional)
* <li>.onClickFn(d,i) - user defined function to handle when donut arc is clicked upon.
* </ul>
*
* @param {object} data the Total and Used values for the donut chart. Available is calculated as Total - Used.<br/>
* <ul style='list-style-type: none'>
* <li>.used - number representing the amount used
* <li>.total - number representing the total amount
* </ul>
*
* @param {string=} center-label specifies the contents of the donut's center label.<br/>
* <strong>Values:</strong>
* <ul style='list-style-type: none'>
* <li> 'used' - displays the Used amount in the center label (default)
* <li> 'available' - displays the Available amount in the center label
* <li> 'percent' - displays the Usage Percent of the Total amount in the center label
* <li> 'none' - does not display the center label
* </ul>
* @example
<example module="patternfly.charts">
<file name="index.html">
<div ng-controller="ChartCtrl">
<div class="container-fluid">
<div class="row">
<div class="col-md-3 text-center">
<label>Error Threshold</label>
<div pf-donut-pct-chart config="configErr" data="dataErr"></div>
</div>
<div class="col-md-3 text-center"">
<label>Warning Threshold</label>
<div pf-donut-pct-chart config="configWarn" data="dataWarn"></div>
</div>
<div class="col-md-3 text-center"">
<label>Ok</label>
<div pf-donut-pct-chart config="configOk" data="dataOk"></div>
</div>
<div class="col-md-3 text-center"">
<label>No Threshold</label>
<div pf-donut-pct-chart config="configNoThresh" data="dataNoThresh"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<hr>
</div>
</div>
<div class="row">
<div class="col-md-3 text-center">
<div pf-donut-pct-chart config="usedConfig" data="usedData" center-label="usedLabel"></div>
<label>center-label = 'used'</label>
</div>
<div class="col-md-3 text-center">
<div pf-donut-pct-chart config="availConfig" data="availData" center-label="availLabel"></div>
<label>center-label = 'available'</label>
</div>
<div class="col-md-3 text-center">
<div pf-donut-pct-chart config="pctConfig" data="pctData" center-label="pctLabel"></div>
<label>center-label = 'percent'</label>
</div>
<div class="col-md-3 text-center">
<div pf-donut-pct-chart config="noneConfig" data="noneData" center-label="noLabel"></div>
<label>center-label = ' none'</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<hr>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<label>Custom Tooltip, Legend, Click handling, and Center Label</label><br>
<label><strong>Click on Donut Arc!</strong></label>
<div pf-donut-pct-chart config="custConfig" data="custData"></div>
</div>
</div>
</div>
</div>
</file>
<file name="script.js">
angular.module( 'patternfly.charts' ).controller( 'ChartCtrl', function( $scope ) {
$scope.configErr = {
'chartId': 'chartErr',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.dataErr = {
'used': '950',
'total': '1000'
};
$scope.configWarn = {
'chartId': 'chartWarn',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.dataWarn = {
'used': '650',
'total': '1000'
};
$scope.configOk = {
'chartId': 'chartOk',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.dataOk = {
'used': '550',
'total': '1000'
};
$scope.configNoThresh = {
'chartId': 'chartNoThresh',
'units': 'GB',
};
$scope.dataNoThresh = {
'used': '750',
'total': '1000'
};
$scope.usedConfig = {
'chartId': 'usedChart',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.usedData = {
'used': '350',
'total': '1000'
};
$scope.usedLabel = "used";
$scope.availConfig = {
'chartId': 'availChart',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.availData = {
'used': '350',
'total': '1000'
};
$scope.availLabel = "available";
$scope.pctConfig = {
'chartId': 'pctChart',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.pctData = {
'used': '350',
'total': '1000'
};
$scope.pctLabel = "percent";
$scope.noneConfig = {
'chartId': 'noneChart',
'units': 'GB',
'thresholds':{'warning':'60','error':'90'}
};
$scope.noneData = {
'used': '350',
'total': '1000'
};
$scope.noLabel = "none";
$scope.custConfig = {
'chartId': 'custChart',
'units': 'MHz',
'thresholds':{'warning':'60','error':'90'},
"legend":{"show":true},
'tooltipFn': function (d) {
return '<span class="donut-tooltip-pf"style="white-space: nowrap;">' +
d[0].value + ' ' + d[0].name +
'</span>';
},
'centerLabelFn': function () {
return '<tspan dy="0" x="0" class="donut-title-big-pf">' + $scope.custData.available + '</tspan>' +
'<tspan dy="20" x="0" class="donut-title-small-pf">Free</tspan>';
},
'onClickFn': function (d, i) {
alert("You Clicked On The Donut!");
}
};
$scope.custData = {
'used': '670',
'total': '1000'
};
});
</file>
</example>
*/
angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaults", "pfUtils", "$timeout", function (c3ChartDefaults, pfUtils, $timeout) {
'use strict';
return {
restrict: 'A',
scope: {
config: '=',
data: '=',
centerLabel: '=?'
},
replace: true,
templateUrl: 'charts/donut/donut-pct-chart.html',
controller: ['$scope',
function ($scope) {
var donutTooltip;
$scope.donutChartId = 'donutChart';
if ($scope.config.chartId) {
$scope.donutChartId = $scope.config.chartId + $scope.donutChartId;
}
$scope.updateAvailable = function () {
$scope.data.available = $scope.data.total - $scope.data.used;
};
if ($scope.data.available === undefined) {
$scope.updateAvailable();
}
$scope.getStatusColor = function (used, thresholds) {
var color = '#0088CE';
if (thresholds) {
color = '#3f9c35';
if (used >= thresholds.error) {
color = '#CC0000';
} else if (used >= thresholds.warning) {
color = '#EC7A08';
}
}
return color;
};
$scope.statusDonutColor = function (scope) {
var color, percentUsed;
color = { pattern: [] };
percentUsed = scope.data.used / scope.data.total * 100.0;
color.pattern[0] = $scope.getStatusColor(percentUsed, scope.config.thresholds);
color.pattern[1] = '#D1D1D1';
return color;
};
donutTooltip = function (scope) {
return {
contents: function (d) {
var tooltipHtml;
if (scope.config.tooltipFn) {
tooltipHtml = '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
scope.config.tooltipFn(d) +
'</span>';
} else {
tooltipHtml = '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
Math.round(d[0].ratio * 100) + '%' + ' ' + $scope.config.units + ' ' + d[0].name +
'</span>';
}
return tooltipHtml;
}
};
};
$scope.getDonutData = function (scope) {
return {
columns: [
['Used', scope.data.used],
['Available', scope.data.available]
],
type: 'donut',
donut: {
label: {
show: false
}
},
groups: [
['used', 'available']
],
order: null
};
};
$scope.getCenterLabelText = function () {
var centerLabelText;
// default to 'used' info.