Source: volume/pivot.js

// Generated by CoffeeScript 1.12.7

/**
 * Spreadsheet pivot
 * @module
 */
'use strict';
app.directive('volumePivot', [
  'constantService', 'displayService', function(constants, display) {
    return {
      restrict: 'E',
      link: function($scope, $element) {
        var pivot;
        pivot = $scope.pivot;
        pivot.run = function(rows, opts) {
          var a, agediv, agemode, cols, d, data, disp, g, head, i, j, l, len, len1, len2, len3, len4, len5, len6, m, n, o, p, q, r, ref, ref1, ref2, ref3, row, s, t, u;
          cols = $scope.groups;
          head = [];
          for (j = 0, len = cols.length; j < len; j++) {
            g = cols[j];
            if (!(g.category.id !== 'asset')) {
              continue;
            }
            if (g.category.id === 'slot') {
              n = '';
            } else {
              n = g.category.name + ' ';
            }
            ref = g.metrics;
            for (o = 0, len1 = ref.length; o < len1; o++) {
              m = ref[o];
              if (m.id !== 'summary') {
                if (m.id === 'age') {
                  agemode = display.ageMode($scope.volume.summary.agemean);
                  head.push(n + m.name + ' (' + agemode + 's)');
                  agediv = constants.age[agemode];
                } else {
                  head.push(n + m.name);
                }
              }
            }
          }
          data = [head];
          disp = function(m, v) {
            if (v == null) {
              if (m.assumed) {
                return '\u2043default\u2043 (' + m.assumed + ')';
              } else {
                return '';
              }
            }
            switch (m.id) {
              case 'release':
                return constants.release[v];
              case 'age':
                return v / agediv;
              case 'top':
                if (v === 'global') {
                  return 'volume';
                } else {
                  return m.options[v];
                }
                break;
              default:
                if (m.type === 'void') {
                  return true;
                } else {
                  return v;
                }
            }
          };
          for (p = 0, len2 = rows.length; p < len2; p++) {
            row = rows[p];
            if (!((row != null ? row.filt : void 0) && row.key)) {
              continue;
            }
            data.push(d = []);
            for (q = 0, len3 = cols.length; q < len3; q++) {
              g = cols[q];
              if (!(g.category.id !== 'asset')) {
                continue;
              }
              l = row.list(g.category.id);
              switch (l.length) {
                case 0:
                  ref1 = g.metrics;
                  for (s = 0, len4 = ref1.length; s < len4; s++) {
                    m = ref1[s];
                    if (m.id !== 'summary') {
                      d.push('\u2043none\u2043');
                    }
                  }
                  break;
                case 1:
                  r = l[0];
                  ref2 = g.metrics;
                  for (t = 0, len5 = ref2.length; t < len5; t++) {
                    m = ref2[t];
                    if (m.id !== 'summary') {
                      d.push(disp(m, r[m.id]));
                    }
                  }
                  break;
                default:
                  ref3 = g.metrics;
                  for (u = 0, len6 = ref3.length; u < len6; u++) {
                    m = ref3[u];
                    if (!(m.id !== 'summary')) {
                      continue;
                    }
                    a = _.uniq((function() {
                      var len7, results, w;
                      results = [];
                      for (w = 0, len7 = l.length; w < len7; w++) {
                        i = l[w];
                        if (i[m.id] != null) {
                          results.push(i[m.id]);
                        }
                      }
                      return results;
                    })());
                    switch (a.length) {
                      case 0:
                        d.push(void 0);
                        break;
                      case 1:
                        d.push(disp(m, a[0]));
                        break;
                      default:
                        d.push('\u2043multiple\u2043');
                    }
                  }
              }
            }
          }
          $element.pivotUI(data, opts, opts != null);
          this.active = true;
        };
        pivot.clear = function() {
          this.active = false;
          return $element.empty();
        };
        pivot.get = function() {
          var j, k, len, opts, r, ref;
          if (!this.active) {
            return;
          }
          opts = $element.data('pivotUIOptions');
          r = {};
          ref = ['rendererName', 'cols', 'rows', 'aggregatorName', 'vals'];
          for (j = 0, len = ref.length; j < len; j++) {
            k = ref[j];
            if (k in opts) {
              r[k] = opts[k];
            }
          }
          return r;
        };
        if (typeof pivot.init === "function") {
          pivot.init();
        }
      }
    };
  }
]);

//# sourceMappingURL=pivot.js.map