Skip to content

Commit 239fbe9

Browse files
AllenBWcdcabrera
authored andcommitted
feat(pfUtilizationBarChart): Support for custom tooltip (#618)
1 parent e1a61a2 commit 239fbe9

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/charts/utilization-bar/utilization-bar-chart.component.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
* has been reached, the used donut arc will be red.
4141
* @param {string=} threshold-warning The percentage usage, when reached, denotes a warning. Valid values are 1-100. When the warning threshold
4242
* has been reached, the used donut arc will be orange.
43+
* @param {function(items)} avaliableTooltipFunction A passed in tooltip function which can be used to overwrite the default available tooltip behavior
44+
* @param {function(items)} usedTooltipFunction A passed in tooltip function which can be used to overwrite the default usedtooltip behavior
4345
*
4446
* @example
4547
<example module="patternfly.example">
@@ -49,12 +51,17 @@
4951
<label class="label-title">Default Layout, no Thresholds</label>
5052
<pf-utilization-bar-chart chart-data=data1 chart-title=title1 units=units1></pf-utilization-bar-chart>
5153
<br>
54+
<label class="label-title">Inline layout, Custom tooltips'</label>
55+
<pf-utilization-bar-chart chart-data=data1 chart-title=title1 units=units1
56+
available-tooltip-function="availableTooltip(title1, data1)"
57+
used-tooltip-function="usedTooltip(title1, data1)"></pf-utilization-bar-chart>
58+
<br>
5259
<label class="label-title">Inline Layouts with Error, Warning, and Ok Thresholds</label>
5360
<pf-utilization-bar-chart chart-data=data5 chart-title=title5 layout=layoutInline units=units5 threshold-error="85" threshold-warning="60">../utilization-trend/utilization-trend-chart-directive.js</pf-utilization-bar-chart>
5461
<pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInline units=units3 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
5562
<pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInline units=units2 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
5663
<br>
57-
<label class="label-title">layout='inline', footer-label-format='percent', and custom chart-footer labels</label>
64+
<label class="label-title">Inline layout, Footer label percent, and Custom chart footer labels</label>
5865
<pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInline footer-label-format='percent' units=units2 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
5966
<pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInline footer-label-format='percent' units=units3 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
6067
<pf-utilization-bar-chart chart-data=data4 chart-title=title4 chart-footer=footer1 layout=layoutInline units=units4 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
@@ -87,8 +94,8 @@
8794
'total': '24'
8895
};
8996
90-
$scope.title2 = 'Memory';
91-
$scope.units2 = 'GB';
97+
$scope.title2 = 'Memory';
98+
$scope.units2 = 'GB';
9299
93100
$scope.data2 = {
94101
'used': '25',
@@ -130,7 +137,12 @@
130137
131138
$scope.footer1 = '<strong>500 TB</strong> Total';
132139
$scope.footer2 = '<strong>450 of 500</strong> Total';
133-
140+
$scope.availableTooltip = function (title, data){
141+
return '<div>Title: ' + title + '</div><div>Available: ' + data.total + '</div>';
142+
};
143+
$scope.usedTooltip = function (title, data){
144+
return '<div>Title: ' + title + '</div><div>Usage: ' + data.used + 'MB</div>';
145+
};
134146
});
135147
</file>
136148
</example>
@@ -145,7 +157,9 @@ angular.module('patternfly.charts').component('pfUtilizationBarChart', {
145157
thresholdError: '=?',
146158
thresholdWarning: '=?',
147159
footerLabelFormat: '@?',
148-
layout: '=?'
160+
layout: '=?',
161+
usedTooltipFunction: '&?',
162+
availableTooltipFunction: '&?'
149163
},
150164

151165
templateUrl: 'charts/utilization-bar/utilization-bar-chart.html',
@@ -185,5 +199,13 @@ angular.module('patternfly.charts').component('pfUtilizationBarChart', {
185199
ctrl.updateAll();
186200
}
187201
};
202+
203+
ctrl.usedTooltipMessage = function () {
204+
return ctrl.usedTooltipFunction ? ctrl.usedTooltipFunction() : ctrl.chartData.percentageUsed + '% Used';
205+
};
206+
207+
ctrl.availableTooltipMessage = function () {
208+
return ctrl.availableTooltipFunction ? ctrl.availableTooltipFunction() : (100 - ctrl.chartData.percentageUsed) + '% Available';
209+
};
188210
}
189211
});

src/charts/utilization-bar/utilization-bar-chart.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<div class="progress progress-label-top-right" ng-if="$ctrl.chartData.dataAvailable !== false">
55
<div class="progress-bar" aria-valuenow="{{$ctrl.chartData.percentageUsed}}" aria-valuemin="0" aria-valuemax="100" ng-class="{'animate': animate,
66
'progress-bar-success': $ctrl.isOk, 'progress-bar-danger': $ctrl.isError, 'progress-bar-warning': $ctrl.isWarn}"
7-
ng-style="{width:$ctrl.chartData.percentageUsed + '%'}" uib-tooltip="{{$ctrl.chartData.percentageUsed}}% Used" >
7+
ng-style="{width:$ctrl.chartData.percentageUsed + '%'}" uib-tooltip-html="'{{$ctrl.usedTooltipMessage()}}'" >
88
<span ng-if="$ctrl.chartFooter" ng-bind-html="$ctrl.chartFooter"></span>
99
<span ng-if="!$ctrl.chartFooter && (!$ctrl.footerLabelFormat || $ctrl.footerLabelFormat === 'actual')"><strong>{{$ctrl.chartData.used}} of {{$ctrl.chartData.total}} {{$ctrl.units}}</strong> Used</span>
1010
<span ng-if="!$ctrl.chartFooter && $ctrl.footerLabelFormat === 'percent'"><strong>{{$ctrl.chartData.percentageUsed}}%</strong> Used</span>
1111
</div>
1212
<div class="progress-bar progress-bar-remaining"
13-
ng-style="{width:(100 - $ctrl.chartData.percentageUsed) + '%'}" uib-tooltip="{{100 - $ctrl.chartData.percentageUsed}}% Available">
13+
ng-style="{width:(100 - $ctrl.chartData.percentageUsed) + '%'}" uib-tooltip-html="'{{$ctrl.availableTooltipMessage()}}'">
1414
</div>
1515
</div>
1616
</span>
@@ -21,13 +21,13 @@
2121
<div class="progress" ng-if="$ctrl.chartData.dataAvailable !== false">
2222
<div class="progress-bar" aria-valuenow="{{$ctrl.chartData.percentageUsed}}" aria-valuemin="0" aria-valuemax="100"
2323
ng-class="{'animate': $ctrl.animate, 'progress-bar-success': $ctrl.isOk, 'progress-bar-danger': $ctrl.isError, 'progress-bar-warning': $ctrl.isWarn}"
24-
ng-style="{width:$ctrl.chartData.percentageUsed + '%'}" uib-tooltip="{{$ctrl.chartData.percentageUsed}}% Used">
24+
ng-style="{width:$ctrl.chartData.percentageUsed + '%'}" uib-tooltip-html="'{{$ctrl.usedTooltipMessage()}}'">
2525
<span ng-if="$ctrl.chartFooter" ng-bind-html="$ctrl.chartFooter"></span>
2626
<span ng-if="(!$ctrl.chartFooter) && (!$ctrl.footerLabelFormat || $ctrl.footerLabelFormat === 'actual')" ng-style="{'max-width':$ctrl.layout.footerLabelWidth}"><strong>{{$ctrl.chartData.used}} {{$ctrl.units}}</strong> Used</span>
2727
<span ng-if="(!$ctrl.chartFooter) && $ctrl.footerLabelFormat === 'percent'" ng-style="{'max-width':$ctrl.layout.footerLabelWidth}"><strong>{{$ctrl.chartData.percentageUsed}}%</strong> Used</span>
2828
</div>
2929
<div class="progress-bar progress-bar-remaining"
30-
ng-style="{width:(100 - $ctrl.chartData.percentageUsed) + '%'}" uib-tooltip="{{100 - $ctrl.chartData.percentageUsed}}% Available">
30+
ng-style="{width:(100 - $ctrl.chartData.percentageUsed) + '%'}" uib-tooltip-html="'{{$ctrl.availableTooltipMessage()}}'">
3131
</div>
3232
</div>
3333
</div>

0 commit comments

Comments
 (0)