Code coverage report for src/charts/heatmap/heatmap-legend.component.js

Statements: 90.48% (19 / 21)      Branches: 83.33% (10 / 12)      Functions: 100% (4 / 4)      Lines: 90.48% (19 / 21)      Ignored: none     

All files » src/charts/heatmap/ » heatmap-legend.component.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 481               9   9 9   9 9     9 9 9     9 1   9 1   9 36         9     9 9     9            
angular.module('patternfly.charts').component('pfHeatmapLegend', {
  bindings: {
    legend: '<?',
    legendColors: '<?'
  },
  templateUrl: 'charts/heatmap/heatmap-legend.html',
  controller: function () {
    'use strict';
    var ctrl = this;
 
    var heatmapColorPatternDefaults = ['#d4f0fa', '#F9D67A', '#EC7A08', '#CE0000'];
    var legendLabelDefaults = ['< 70%', '70-80%', '80-90%', '> 90%'];
 
    ctrl.$onInit = function () {
      ctrl.updateAll();
    };
 
    ctrl.updateAll = function () {
      var items = [];
      var index;
 
      //Allow overriding of defaults
      if (!ctrl.legendColors) {
        ctrl.legendColors = heatmapColorPatternDefaults;
      }
      if (!ctrl.legend) {
        ctrl.legend = legendLabelDefaults;
      }
      for (index = ctrl.legend.length - 1; index >= 0; index--) {
        items.push({
          text: ctrl.legend[index],
          color: ctrl.legendColors[index]
        });
      }
      ctrl.legendItems = items;
    };
 
    ctrl.$onChanges = function (changesObj) {
      Iif (changesObj.legend && !changesObj.legend.isFirstChange()) {
        ctrl.updateAll();
      }
      Iif (changesObj.legendColors && !changesObj.legendColors.isFirstChange()) {
        ctrl.updateAll();
      }
    };
  }
});