@@ -1147,10 +1147,22 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
11471147 return {
11481148 restrict : 'A' ,
11491149 scope : {
1150- legend : '=' ,
1151- legendColors : '='
1150+ legend : '=? ' ,
1151+ legendColors : '=? '
11521152 } ,
11531153 templateUrl : 'charts/heatmap/heatmap-legend.html' ,
1154+ controller : [ "$scope" , function ( $scope ) {
1155+ var heatmapColorPatternDefaults = [ '#d4f0fa' , '#F9D67A' , '#EC7A08' , '#CE0000' ] ;
1156+ var legendLabelDefaults = [ '< 70%' , '70-80%' , '80-90%' , '> 90%' ] ;
1157+
1158+ //Allow overriding of defaults
1159+ if ( ! $scope . legendColors ) {
1160+ $scope . legendColors = heatmapColorPatternDefaults ;
1161+ }
1162+ if ( ! $scope . legend ) {
1163+ $scope . legend = legendLabelDefaults ;
1164+ }
1165+ } ] ,
11541166 link : function ( $scope ) {
11551167 var items = [ ] ;
11561168 var index ;
@@ -1181,15 +1193,33 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
11811193 *
11821194 * @param {string= } height height of the chart (no units) - default: "200"
11831195 * @param {string= } chartTitle title of the chart
1196+ * @param {boolean= } showLegend flag to show the legend, defaults to true
11841197 * @param {array= } legendLabels the labels for the legend - defaults: ['< 70%', '70-80%' ,'80-90%', '> 90%']
11851198 * @param {array= } thresholds the threshold values for the heapmap - defaults: [0.7, 0.8, 0.9]
11861199 * @param {array= } heatmapColorPattern the colors that correspond to the various threshold values (lowest to hightest value ex: <70& to >90%) - defaults: ['#d4f0fa', '#F9D67A', '#EC7A08', '#CE0000']
11871200 * @param {function= } clickAction function(block) function to call when a block is clicked on
11881201 * @example
11891202 <example module="patternfly.charts">
1203+ <file name="index.html">
1204+ <div ng-controller="ChartCtrl" class="row">
1205+ <div class="col-md-5">
1206+ <div pf-heatmap id="id" chart-title="title" data="data" show-legend="showLegends"></div>
1207+ </div>
1208+ <div class="col-md-5">
1209+ <div pf-heatmap id="id" chart-title="titleAlt" data="data" show-legend="showLegends" legend-labels="legendLabels" heatmap-color-pattern="heatmapColorPattern" thresholds="thresholds" click-action="clickAction"></div>
1210+ </div>
1211+ <div class="col-md-12">
1212+ <form role="form">
1213+ <div class="form-group">
1214+ <label class="radio-inline">
1215+ <input type="checkbox" ng-model="showLegends">Show Legends</input>
1216+ </label>
1217+ </div>
1218+ </form>
1219+ </div>
1220+ </file>
11901221 <file name="script.js">
11911222 angular.module( 'patternfly.charts' ).controller( 'ChartCtrl', function( $scope) {
1192- $scope.title = 'Utilization - Using Defaults';
11931223 $scope.data = [
11941224 {'id': 9,'value': 0.96,'tooltip': 'Node 8 : My OpenShift Provider<br\>96% : 96 Used of 100 Total<br\>4 Available'},
11951225 {'id': 44, 'value': 0.94, 'tooltip': 'Node 19 : My Kubernetes Provider<br\>94% : 94 Used of 100 Total<br\>6 Available'},
@@ -1244,27 +1274,20 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
12441274 {'id': 51, 'value': 0.22, 'tooltip': 'Node 26 : My Kubernetes Provider<br\>22% : 22 Used of 100 Total<br\>78 Available'},
12451275 {'id': 14, 'value': 0.2, 'tooltip': 'Node 14 : My OpenShift Provider<br\>20% : 20 Used of 100 Total<br\>80 Available'}];
12461276
1277+ $scope.title = 'Utilization - Using Defaults';
12471278 $scope.titleAlt = 'Utilization - Overriding Defaults';
1279+
12481280 $scope.legendLabels = ['< 60%','70%', '70-80%' ,'80-90%', '> 90%'];
12491281 $scope.thresholds = [0.6, 0.7, 0.8, 0.9];
12501282 $scope.heatmapColorPattern = ['#d4f0fa', '#F9D67A', '#EC7A08', '#CE0000', '#f00'];
12511283
1284+ $scope.showLegends = true;
12521285 var clickAction = function (block) {
12531286 console.log(block);
12541287 };
12551288 $scope.clickAction = clickAction;
12561289 });
12571290 </file>
1258- <file name="index.html">
1259- <div ng-controller="ChartCtrl" class="row">
1260- <div class="col-md-4">
1261- <div pf-heatmap id="id" chart-title="title" data="data"></div>
1262- </div>
1263- <div class="col-md-4">
1264- <div pf-heatmap id="id" chart-title="titleAlt" data="data" legend-labels="legendLabels" heatmap-color-pattern="heatmapColorPattern" thresholds="thresholds" click-action="clickAction"></div>
1265- </div>
1266- </div>
1267- </file>
12681291 </example>
12691292 */
12701293angular . module ( 'patternfly.charts' ) . directive ( 'pfHeatmap' , [ "$compile" , function ( $compile ) {
@@ -1275,20 +1298,37 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
12751298 data : '=' ,
12761299 height : '=' ,
12771300 chartTitle : '=?' ,
1301+ showLegend : '=?' ,
12781302 legendLabels : '=?' ,
12791303 thresholds : '=?' ,
12801304 heatmapColorPattern : '=?' ,
12811305 clickAction : '=?'
12821306 } ,
12831307 templateUrl : 'charts/heatmap/heatmap.html' ,
1284- link : function ( scope , element , attrs ) {
1285- var thisComponent = element [ 0 ] . querySelector ( '.pf-heatmap-svg' ) ;
1286- var containerWidth , containerHeight , blockSize , numberOfRows ;
1308+ controller : [ "$scope" , function ( $scope ) {
12871309 var thresholdDefaults = [ 0.7 , 0.8 , 0.9 ] ;
12881310 var heatmapColorPatternDefaults = [ '#d4f0fa' , '#F9D67A' , '#EC7A08' , '#CE0000' ] ;
12891311 var legendLabelDefaults = [ '< 70%' , '70-80%' , '80-90%' , '> 90%' ] ;
12901312 var heightDefault = 200 ;
12911313
1314+ //Allow overriding of defaults
1315+ if ( ! $scope . thresholds ) {
1316+ $scope . thresholds = thresholdDefaults ;
1317+ }
1318+ if ( ! $scope . heatmapColorPattern ) {
1319+ $scope . heatmapColorPattern = heatmapColorPatternDefaults ;
1320+ }
1321+ if ( ! $scope . legendLabels ) {
1322+ $scope . legendLabels = legendLabelDefaults ;
1323+ }
1324+ $scope . height = $scope . height || heightDefault ;
1325+ $scope . showLegend = $scope . showLegend || ( $scope . showLegend === undefined ) ;
1326+ $scope . loadingDone = false ;
1327+ } ] ,
1328+ link : function ( scope , element , attrs ) {
1329+ var thisComponent = element [ 0 ] . querySelector ( '.pf-heatmap-svg' ) ;
1330+ var containerWidth , containerHeight , blockSize , numberOfRows ;
1331+
12921332 var setSizes = function ( ) {
12931333 var parentContainer = element [ 0 ] . querySelector ( '.heatmap-container' ) ;
12941334 containerWidth = parentContainer . clientWidth ;
@@ -1323,7 +1363,6 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
13231363 var data = scope . data ;
13241364 var blockPadding = 1 ;
13251365 var color = d3 . scale . threshold ( ) . domain ( scope . thresholds ) . range ( scope . heatmapColorPattern ) ;
1326- var component = thisComponent ;
13271366 var blocks ;
13281367 var highlightBlock = function ( block , active ) {
13291368 block . style ( 'fill-opacity' , active ? 1 : 0.4 ) ;
@@ -1368,15 +1407,6 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
13681407 } ) ;
13691408 } ;
13701409
1371- //Allow overriding of defaults
1372- scope . thresholds = angular . extend ( [ ] , thresholdDefaults , scope . thresholds ) ;
1373- scope . heatmapColorPattern = angular . extend ( [ ] , heatmapColorPatternDefaults , scope . heatmapColorPattern ) ;
1374- scope . legendLabels = angular . extend ( [ ] , legendLabelDefaults , scope . legendLabels ) ;
1375- scope . height = scope . height || heightDefault ;
1376-
1377- //Shows loading indicator
1378- scope . loadingDone = false ;
1379-
13801410 scope . $watch ( 'data' , function ( newVal , oldVal ) {
13811411 if ( typeof ( newVal ) !== 'undefined' ) {
13821412 scope . loadingDone = true ;
@@ -5228,7 +5258,7 @@ angular.module('patternfly.views').directive('pfDataToolbar', function () {
52285258
52295259
52305260 $templateCache . put ( 'charts/heatmap/heatmap.html' ,
5231- "<div class=pf-heatmap-container><h3>{{chartTitle}}</h3><div class=heatmap-container style=\"height: {{height}}px\"><svg class=pf-heatmap-svg></svg></div><div ng-if=!loadingDone class=\"spinner spinner-lg loading\"></div><div pf-heatmap-legend legend=legendLabels legend-colors=heatmapColorPattern></div></div>"
5261+ "<div class=pf-heatmap-container><h3>{{chartTitle}}</h3><div class=heatmap-container style=\"height: {{height}}px\"><svg class=pf-heatmap-svg></svg></div><div ng-if=!loadingDone class=\"spinner spinner-lg loading\"></div><div ng-if=showLegend pf-heatmap-legend legend=legendLabels legend-colors=heatmapColorPattern></div></div>"
52325262 ) ;
52335263
52345264
0 commit comments