1// Copyright 2014 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5var MINIMUM_EDGE_SEPARATION = 20; 6 7function isEdgeInitiallyVisible(target, index, source, type) { 8 return type == "control" && (target.cfg || source.cfg); 9} 10 11var Edge = function(target, index, source, type) { 12 this.target = target; 13 this.source = source; 14 this.index = index; 15 this.type = type; 16 this.backEdgeNumber = 0; 17 this.visible = isEdgeInitiallyVisible(target, index, source, type); 18}; 19 20Edge.prototype.stringID = function() { 21 return this.source.id + "," + this.index + "," + this.target.id; 22}; 23 24Edge.prototype.isVisible = function() { 25 return this.visible && this.source.visible && this.target.visible; 26}; 27 28Edge.prototype.getInputHorizontalPosition = function(graph) { 29 if (this.backEdgeNumber > 0) { 30 return graph.maxGraphNodeX + this.backEdgeNumber * MINIMUM_EDGE_SEPARATION; 31 } 32 var source = this.source; 33 var target = this.target; 34 var index = this.index; 35 var input_x = target.x + target.getInputX(index); 36 var inputApproach = target.getInputApproach(this.index); 37 var outputApproach = source.getOutputApproach(graph); 38 if (inputApproach > outputApproach) { 39 return input_x; 40 } else { 41 var inputOffset = MINIMUM_EDGE_SEPARATION * (index + 1); 42 return (target.x < source.x) 43 ? (target.x + target.getTotalNodeWidth() + inputOffset) 44 : (target.x - inputOffset) 45 } 46} 47 48Edge.prototype.generatePath = function(graph) { 49 var target = this.target; 50 var source = this.source; 51 var input_x = target.x + target.getInputX(this.index); 52 var output_x = source.x + source.getOutputX(); 53 var output_y = source.y + DEFAULT_NODE_HEIGHT + DEFAULT_NODE_BUBBLE_RADIUS; 54 var inputApproach = target.getInputApproach(this.index); 55 var outputApproach = source.getOutputApproach(graph); 56 var horizontalPos = this.getInputHorizontalPosition(graph); 57 58 var result = "M" + output_x + "," + output_y + 59 "L" + output_x + "," + outputApproach + 60 "L" + horizontalPos + "," + outputApproach; 61 62 if (horizontalPos != input_x) { 63 result += "L" + horizontalPos + "," + inputApproach; 64 } else { 65 if (inputApproach < outputApproach) { 66 inputApproach = outputApproach; 67 } 68 } 69 70 result += "L" + input_x + "," + inputApproach + 71 "L" + input_x + "," + (target.y - DEFAULT_NODE_BUBBLE_RADIUS - 12); 72 return result; 73} 74 75Edge.prototype.isBackEdge = function() { 76 return this.target.hasBackEdges() && (this.target.rank < this.source.rank); 77} 78