Code coverage report for tracevis/lib/trace/exclude.js

Statements: 100% (33 / 33)      Branches: 100% (4 / 4)      Functions: 100% (20 / 20)      Lines: 100% (29 / 29)     

All files » tracevis/lib/trace/ » exclude.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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                2 81     2 81     2 13     2 21 175 33       29   29 23 38       29 20 29       4 4 4         33         2 29 76       2 29 76       2 66    
/*
 * Copyright 2013 LinkedIn, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
 
exports.userTasks = function(g) {
  excludeTasks(g, function(u) { return g.node(u).hidden; });
};
 
exports.systemTasks = function(g) {
  excludeTasks(g, function(u) { return g.node(u).systemHidden; });
};
 
exports.parentTasks = function(g) {
  excludeTasks(g, function(u) { return g.children(u).length; });
};
 
function excludeTasks(g, predicate) {
  g.eachNode(function(u) {
    if (predicate(u)) {
      if (g.children(u).length) {
        // Nodes in a deleted subgraph are automatically promoted to the parent,
        // but we need to take care to point edges to and from the node's sources
        // and sinks respectively.
        var sourceNodes = sources(g, u),
            sinkNodes = sinks(g, u);
        filterSuccessorEdges(g, g.inEdges(u)).forEach(function(e) {
          sourceNodes.forEach(function(v) {
            g.addEdge(null, g.source(e), v, { relationship: 'SUCCESSOR' });
          });
        });
 
        filterSuccessorEdges(g, g.outEdges(u)).forEach(function(e) {
          sinkNodes.forEach(function(v) {
            g.addEdge(null, v, g.target(e), { relationship: 'SUCCESSOR' });
          });
        });
      } else {
        filterSuccessorEdges(g, g.inEdges(u)).forEach(function(e) {
          filterSuccessorEdges(g, g.outEdges(u)).forEach(function(e2) {
            g.addEdge(null, g.source(e), g.target(e2), { relationship: 'SUCCESSOR' });
          });
        });
      }
 
      g.delNode(u);
    }
  });
}
 
function sources(g, parent) {
  return g.children(parent).filter(function(u) {
    return !g.inEdges(u).length;
  });
}
 
function sinks(g, parent) {
  return g.children(parent).filter(function(u) {
    return !g.outEdges(u).length;
  });
}
 
function filterSuccessorEdges(g, es) {
  return es.filter(function(e) { return g.edge(e).relationship === 'SUCCESSOR'; });
}