@@ -13,7 +13,7 @@ angular.module('patternfly.card', []);
13
13
* Charts module for patternfly. Must Include d3.js and c3.js to use
14
14
*
15
15
*/
16
- angular . module ( 'patternfly.charts' , [ 'patternfly.utils' ] ) ;
16
+ angular . module ( 'patternfly.charts' , [ 'patternfly.utils' , 'ui.bootstrap' ] ) ;
17
17
18
18
; /**
19
19
* @name patternfly card
@@ -460,8 +460,6 @@ angular.module('patternfly.card').directive('pfCard', function () {
460
460
} ]
461
461
} ;
462
462
} ) ;
463
-
464
-
465
463
; ( function ( ) {
466
464
'use strict' ;
467
465
@@ -1597,6 +1595,171 @@ angular.module('patternfly.charts').directive('pfTrendsChart', function () {
1597
1595
}
1598
1596
} ;
1599
1597
} ) ;
1598
+ ; /**
1599
+ * @ngdoc directive
1600
+ * @name patternfly.charts.directive:pfUtilizationBarChart
1601
+ *
1602
+ * @description
1603
+ * Directive for rendering a utilization bar chart
1604
+ * There are three possible fill colors for Used Percentage, dependent on whether or not there are thresholds:<br/>
1605
+ * <ul>
1606
+ * <li>When no thresholds exist, or if the used percentage has not surpassed any thresholds, the indicator is blue.
1607
+ * <li>When the used percentage has surpassed the warning threshold, but not the error threshold, the indicator is orange.
1608
+ * <li>When the used percentage has surpassed the error threshold, the indicator is is red.
1609
+ * </ul>
1610
+ *
1611
+ * @param {object } chartData the data to be shown in the utilization bar chart<br/>
1612
+ * <ul style='list-style-type: none'>
1613
+ * <li>.used - number representing the amount used
1614
+ * <li>.total - number representing the total amount
1615
+ * </ul>
1616
+ *
1617
+ * @param {object= } chart-title The title displayed on the left-hand side of the chart
1618
+ * @param {object= } layout Various alternative layouts the utilization bar chart may have:<br/>
1619
+ * <ul style='list-style-type: none'>
1620
+ * <li>.type - The type of layout to use. Valid values are 'regular' (default) displays the standard chart layout,
1621
+ * and 'inline' displays a smaller, inline layout.</li>
1622
+ * <li>.titleLabelWidth - Width of the left-hand title label when using 'inline' layout. Example values are "120px", "20%", "10em", etc..</li>
1623
+ * <li>.usedLabelWidth - Width of the right-hand used label when using 'inline' layout. Example values are "120px", "20%", "10em", etc..</li>
1624
+ * </ul>
1625
+ * @param {string= } used-label-format The format of the used label on the right side of the bar chart. Values may be:<br/>
1626
+ * <ul style='list-style-type: none'>
1627
+ * <li>'actual' - (default) displays the standard label of '(n) of (m) (units) Used'.
1628
+ * <li>'percent' - displays a percentage label of '(n)% Used'.</li>
1629
+ * </ul>
1630
+ * @param {object= } units to be displayed on the chart. Examples: "GB", "MHz", "I/Ops", etc...
1631
+ * @param {string= } threshold-error Percent used to determine the usage error threshold fill color (red). Valid values are 1-100.
1632
+ * @param {string= } threshold-warning Percent used to determine the usage error threshold fill color (orange) Valid values are 1-100.
1633
+ *
1634
+ * @example
1635
+ <example module="patternfly.example">
1636
+ <file name="index.html">
1637
+ <div ng-controller="ChartCtrl">
1638
+ <div pf-utilization-bar-chart chart-data=data1 chart-title=title1 units=units1></div>
1639
+ <hr>
1640
+ <div pf-card head-title="Utilization Bar Chart">
1641
+ <div pf-utilization-bar-chart chart-data=data2 chart-title=title2 units=units2 threshold-error="85" threshold-warning="60"></div>
1642
+ <div pf-utilization-bar-chart chart-data=data3 chart-title=title3 units=units3 threshold-error="85" threshold-warning="60"></div>
1643
+ <div pf-utilization-bar-chart chart-data=data4 chart-title=title4 units=units4 threshold-error="85" threshold-warning="60"></div>
1644
+ <div pf-utilization-bar-chart chart-data=data5 chart-title=title5 units=units5 threshold-error="85" threshold-warning="60"></div>
1645
+ </div>
1646
+
1647
+ <hr>
1648
+ <label><strong>layout='inline'</strong></label>
1649
+ <div pf-card head-title="Utilization Bar Chart">
1650
+ <div pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInline units=units2 threshold-error="85" threshold-warning="60"></div>
1651
+ <div pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInline units=units3 threshold-error="85" threshold-warning="60"></div>
1652
+ <div pf-utilization-bar-chart chart-data=data4 chart-title=title4 layout=layoutInline units=units4 threshold-error="85" threshold-warning="60"></div>
1653
+ <div pf-utilization-bar-chart chart-data=data5 chart-title=title5 layout=layoutInline units=units5 threshold-error="85" threshold-warning="60"></div>
1654
+ </div>
1655
+
1656
+ <hr>
1657
+ <label><strong>layout='inline', used-label-format='percent', custom widths</strong></label>
1658
+ <div pf-card head-title="Utilization Bar Chart">
1659
+ <div pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInlineWidths used-label-format='percent' units=units2 threshold-error="85" threshold-warning="60"></div>
1660
+ <div pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInlineWidths used-label-format='percent' units=units3 threshold-error="85" threshold-warning="60"></div>
1661
+ <div pf-utilization-bar-chart chart-data=data4 chart-title=title4 layout=layoutInlineWidths used-label-format='percent' units=units4 threshold-error="85" threshold-warning="60"></div>
1662
+ <div pf-utilization-bar-chart chart-data=data5 chart-title=title5 layout=layoutInlineWidths used-label-format='percent' units=units5 threshold-error="85" threshold-warning="60"></div>
1663
+ </div>
1664
+ </div>
1665
+ </file>
1666
+
1667
+ <file name="script.js">
1668
+ angular.module( 'patternfly.example', ['patternfly.charts', 'patternfly.card']);
1669
+
1670
+ angular.module( 'patternfly.example' ).controller( 'ChartCtrl', function( $scope ) {
1671
+
1672
+ $scope.title1 = 'RAM Usage';
1673
+ $scope.units1 = 'MB';
1674
+
1675
+ $scope.data1 = {
1676
+ 'used': '8',
1677
+ 'total': '24'
1678
+ };
1679
+
1680
+ $scope.title2 = 'Memory Utilization';
1681
+ $scope.units2 = 'GB';
1682
+
1683
+ $scope.data2 = {
1684
+ 'used': '25',
1685
+ 'total': '100'
1686
+ };
1687
+
1688
+ $scope.title3 = 'CPU Usage';
1689
+ $scope.units3 = 'MHz';
1690
+
1691
+ $scope.data3 = {
1692
+ 'used': '420',
1693
+ 'total': '500',
1694
+ };
1695
+
1696
+ $scope.title4 = 'Disk Usage';
1697
+ $scope.units4 = 'TB';
1698
+ $scope.data4 = {
1699
+ 'used': '350',
1700
+ 'total': '500',
1701
+ };
1702
+
1703
+ $scope.title5 = 'Disk I/O';
1704
+ $scope.units5 = 'I/Ops';
1705
+ $scope.data5 = {
1706
+ 'used': '450',
1707
+ 'total': '500',
1708
+ };
1709
+
1710
+ $scope.layoutInline = {
1711
+ 'type': 'inline'
1712
+ };
1713
+
1714
+ $scope.layoutInlineWidths = {
1715
+ 'type': 'inline',
1716
+ 'titleLabelWidth': '120px',
1717
+ 'usedLabelWidth': '60px'
1718
+ };
1719
+ });
1720
+ </file>
1721
+ </example>
1722
+ */
1723
+
1724
+ angular . module ( 'patternfly.charts' ) . directive ( 'pfUtilizationBarChart' , [ "$timeout" , function ( $timeout ) {
1725
+ 'use strict' ;
1726
+ return {
1727
+ restrict : 'A' ,
1728
+ scope : {
1729
+ chartData : '=' ,
1730
+ chartTitle : '=' ,
1731
+ units : '=' ,
1732
+ thresholdError : '=?' ,
1733
+ thresholdWarning : '=?' ,
1734
+ usedLabelFormat : '@?' ,
1735
+ layout : '=?'
1736
+ } ,
1737
+ templateUrl : 'charts/utilization-bar/utilization-bar-chart.html' ,
1738
+ link : function ( scope ) {
1739
+ scope . $watch ( 'chartData' , function ( newVal , oldVal ) {
1740
+ if ( typeof ( newVal ) !== 'undefined' ) {
1741
+ //Calculate the percentage used
1742
+ scope . chartData . percentageUsed = Math . round ( 100 * ( scope . chartData . used / scope . chartData . total ) ) ;
1743
+
1744
+ if ( scope . thresholdError || scope . thresholdWarning ) {
1745
+ scope . isError = ( scope . chartData . percentageUsed > scope . thresholdError ) ;
1746
+ scope . isWarn = ( scope . chartData . percentageUsed > scope . thresholdWarning &&
1747
+ scope . chartData . percentageUsed < scope . thresholdError ) ;
1748
+ scope . isOk = ( scope . chartData . percentageUsed < scope . thresholdWarning ) ;
1749
+ }
1750
+
1751
+ //Animate in the chart load.
1752
+ scope . animate = true ;
1753
+ $timeout ( function ( ) {
1754
+ scope . animate = false ;
1755
+ } , 0 ) ;
1756
+ }
1757
+ } ) ;
1758
+
1759
+
1760
+ }
1761
+ } ;
1762
+ } ] ) ;
1600
1763
; /**
1601
1764
* @ngdoc directive
1602
1765
* @name patternfly.charts.directive:pfUtilizationChart
@@ -4764,6 +4927,12 @@ angular.module('patternfly.views').directive('pfDataToolbar', function () {
4764
4927
) ;
4765
4928
4766
4929
4930
+ $templateCache . put ( 'charts/utilization-bar/utilization-bar-chart.html' ,
4931
+ "<div class=pf-utilization-bar-chart><span ng-if=\"!layout || layout.type === 'regular'\"><div ng-if=chartTitle class=progress-description>{{chartTitle}}</div><div class=\"progress progress-label-top-right\"><div class=progress-bar role=progressbar ng-class=\"{'animate': animate,\n" +
4932
+ " 'progress-bar-success': isOk, 'progress-bar-danger': isError, 'progress-bar-warning': isWarn}\" style=width:{{chartData.percentageUsed}}% tooltip=\"{{chartData.percentageUsed}}% Used\"><span ng-if=\"!usedLabelFormat || usedLabelFormat === 'actual'\">{{chartData.used}} of {{chartData.total}} {{units}} Used</span> <span ng-if=\"usedLabelFormat === 'percent'\">{{chartData.percentageUsed}}% Used</span></div><div class=\"progress-bar progress-bar-remaining\" role=progressbar aria-valuenow=5 aria-valuemin=0 aria-valuemax=100 style=\"width: {{100-chartData.percentageUsed}}%\" tooltip=\"{{100-chartData.percentageUsed}}% Available\"></div></div></span> <span ng-if=\"layout && layout.type === 'inline'\"><div class=\"progress-container progress-description-left progress-label-right\" ng-style=\"{'padding-left':layout.titleLabelWidth, 'padding-right':layout.usedLabelWidth}\"><div ng-if=chartTitle class=progress-description ng-style=\"{'max-width':layout.titleLabelWidth}\">{{chartTitle}}</div><div class=progress><div class=progress-bar role=progressbar aria-valuenow=25 aria-valuemin=0 aria-valuemax=100 ng-class=\"{'animate': animate, 'progress-bar-success': isOk, 'progress-bar-danger': isError, 'progress-bar-warning': isWarn}\" style=\"width: {{chartData.percentageUsed}}%\" tooltip=\"{{chartData.percentageUsed}}% Used\"><span ng-if=\"!usedLabelFormat || usedLabelFormat === 'actual'\" ng-style=\"{'max-width':layout.usedLabelWidth}\">{{chartData.used}} of {{chartData.total}} {{units}} Used</span> <span ng-if=\"usedLabelFormat === 'percent'\" ng-style=\"{'max-width':layout.usedLabelWidth}\">{{chartData.percentageUsed}}% Used</span></div><div class=\"progress-bar progress-bar-remaining\" role=progressbar aria-valuenow=75 aria-valuemin=0 aria-valuemax=100 style=\"width: {{100-chartData.percentageUsed}}%\" tooltip=\"{{100-chartData.percentageUsed}}% Available\"></div></div></div></span></div>"
4933
+ ) ;
4934
+
4935
+
4767
4936
$templateCache . put ( 'charts/utilization/utilization-chart.html' ,
4768
4937
"<div class=utilization-chart-pf><h3>{{config.title}}</h3><div class=current-values><h1 class=\"available-count pull-left\"><span>{{currentValue}}</span></h1><div class=\"available-text pull-left\"><div><span>{{currentText}}</span></div><div><span>of {{chartData.total}} {{config.units}}</span></div></div></div><div class=donut-chart-pf><div pf-donut-pct-chart config=donutConfig data=chartData center-label=centerLabel></div></div><div class=sparkline-chart><div pf-sparkline-chart config=sparklineConfig chart-data=chartData chart-height=sparklineChartHeight show-x-axis=showSparklineXAxis show-y-axis=showSparklineYAxis></div></div><span class=\"pull-left legend-text\">{{legendLeftText}}</span> <span class=\"pull-right legend-text\">{{legendRightText}}</span></div>"
4769
4938
) ;
0 commit comments