| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var DEFAULT_NODE_ROW_SEPARATION = 130 | 5 var DEFAULT_NODE_ROW_SEPARATION = 130 |
| 6 | 6 |
| 7 var traceLayout = false; | 7 var traceLayout = false; |
| 8 | 8 |
| 9 function newGraphOccupation(graph){ | 9 function newGraphOccupation(graph){ |
| 10 var isSlotFilled = []; | 10 var isSlotFilled = []; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 s += " "; | 240 s += " "; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 console.log(s); | 243 console.log(s); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 return occupation; | 246 return occupation; |
| 247 } | 247 } |
| 248 | 248 |
| 249 function layoutNodeGraph(graph) { | 249 function layoutNodeGraph(graph) { |
| 250 graph.minGraphX = 0; | |
| 251 graph.maxGraphNodeX = 1; | |
| 252 graph.maxGraphX = 1; | |
| 253 graph.minGraphY = 0; | |
| 254 graph.maxGraphY = 1; | |
| 255 | |
| 256 // First determine the set of nodes that have no outputs. Those are the | 250 // First determine the set of nodes that have no outputs. Those are the |
| 257 // basis for bottom-up DFS to determine rank and node placement. | 251 // basis for bottom-up DFS to determine rank and node placement. |
| 258 var endNodesHasNoOutputs = []; | 252 var endNodesHasNoOutputs = []; |
| 259 var startNodesHasNoInputs = []; | 253 var startNodesHasNoInputs = []; |
| 260 graph.nodes.forEach(function(n, i){ | 254 graph.nodes.forEach(function(n, i){ |
| 261 endNodesHasNoOutputs[n.id] = true; | 255 endNodesHasNoOutputs[n.id] = true; |
| 262 startNodesHasNoInputs[n.id] = true; | 256 startNodesHasNoInputs[n.id] = true; |
| 263 }); | 257 }); |
| 264 graph.edges.forEach(function(e, i){ | 258 graph.edges.forEach(function(e, i){ |
| 265 endNodesHasNoOutputs[e.source.id] = false; | 259 endNodesHasNoOutputs[e.source.id] = false; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 nodeToPlace.x = occupation.occupyNode(nodeToPlace); | 409 nodeToPlace.x = occupation.occupyNode(nodeToPlace); |
| 416 if (traceLayout) { | 410 if (traceLayout) { |
| 417 console.log("Node " + nodeToPlace.id + " is placed between [" + nodeTo
Place.x + ", " + (nodeToPlace.x + nodeToPlace.getTotalNodeWidth()) + ")"); | 411 console.log("Node " + nodeToPlace.id + " is placed between [" + nodeTo
Place.x + ", " + (nodeToPlace.x + nodeToPlace.getTotalNodeWidth()) + ")"); |
| 418 } | 412 } |
| 419 var staggeredFlooredI = Math.floor(placedCount++ % 3); | 413 var staggeredFlooredI = Math.floor(placedCount++ % 3); |
| 420 var delta = MINIMUM_EDGE_SEPARATION * staggeredFlooredI | 414 var delta = MINIMUM_EDGE_SEPARATION * staggeredFlooredI |
| 421 nodeToPlace.outputApproach += delta; | 415 nodeToPlace.outputApproach += delta; |
| 422 } else { | 416 } else { |
| 423 nodeToPlace.x = 0; | 417 nodeToPlace.x = 0; |
| 424 } | 418 } |
| 425 | |
| 426 if (nodeToPlace.x < graph.minGraphX) { | |
| 427 graph.minGraphX = nodeToPlace.x; | |
| 428 } | |
| 429 if ((nodeToPlace.y - 50) < graph.minGraphY) { | |
| 430 graph.minGraphY = nodeToPlace.y - 50; | |
| 431 } | |
| 432 if ((nodeToPlace.x + nodeToPlace.getTotalNodeWidth()) > graph.maxGraphNode
X) { | |
| 433 graph.maxGraphNodeX = nodeToPlace.x + nodeToPlace.getTotalNodeWidth(); | |
| 434 } | |
| 435 if ((nodeToPlace.y + graph.getNodeHeight() + 50) > graph.maxGraphY) { | |
| 436 graph.maxGraphY = nodeToPlace.y + graph.getNodeHeight() + 50; | |
| 437 } | |
| 438 } | 419 } |
| 439 | 420 |
| 440 if (traceLayout) { | 421 if (traceLayout) { |
| 441 console.log("Before clearing nodes"); | 422 console.log("Before clearing nodes"); |
| 442 occupation.print(); | 423 occupation.print(); |
| 443 } | 424 } |
| 444 | 425 |
| 445 occupation.clearOccupiedNodes(); | 426 occupation.clearOccupiedNodes(); |
| 446 | 427 |
| 447 if (traceLayout) { | 428 if (traceLayout) { |
| 448 console.log("After clearing nodes"); | 429 console.log("After clearing nodes"); |
| 449 occupation.print(); | 430 occupation.print(); |
| 450 } | 431 } |
| 451 | 432 |
| 452 for (var i = 0; i < rankSet.length; ++i) { | 433 for (var i = 0; i < rankSet.length; ++i) { |
| 453 var node = rankSet[i]; | 434 var node = rankSet[i]; |
| 454 occupation.occupyNodeInputs(node); | 435 occupation.occupyNodeInputs(node); |
| 455 } | 436 } |
| 456 | 437 |
| 457 if (traceLayout) { | 438 if (traceLayout) { |
| 458 console.log("After occupying inputs"); | 439 console.log("After occupying inputs"); |
| 459 occupation.print(); | 440 occupation.print(); |
| 460 } | 441 } |
| 442 |
| 443 if (traceLayout) { |
| 444 console.log("After determining bounding box"); |
| 445 occupation.print(); |
| 446 } |
| 461 }); | 447 }); |
| 462 | 448 |
| 463 var backEdgeNumber = 0; | 449 graph.maxBackEdgeNumber = 0; |
| 464 graph.visibleEdges.each(function (e) { | 450 graph.visibleEdges.each(function (e) { |
| 465 if (e.isBackEdge()) { | 451 if (e.isBackEdge()) { |
| 466 e.backEdgeNumber = ++backEdgeNumber; | 452 e.backEdgeNumber = ++graph.maxBackEdgeNumber; |
| 467 } else { | 453 } else { |
| 468 e.backEdgeNumber = 0; | 454 e.backEdgeNumber = 0; |
| 469 } | 455 } |
| 470 }); | 456 }); |
| 471 | 457 |
| 458 redetermineGraphBoundingBox(graph); |
| 459 |
| 460 } |
| 461 |
| 462 function redetermineGraphBoundingBox(graph) { |
| 463 graph.minGraphX = 0; |
| 464 graph.maxGraphNodeX = 1; |
| 465 graph.maxGraphX = undefined; // see below |
| 466 graph.minGraphY = 0; |
| 467 graph.maxGraphY = 1; |
| 468 |
| 469 for (var i = 0; i < graph.nodes.length; ++i) { |
| 470 var node = graph.nodes[i]; |
| 471 |
| 472 if (!node.visible) { |
| 473 continue; |
| 474 } |
| 475 |
| 476 if (node.x < graph.minGraphX) { |
| 477 graph.minGraphX = node.x; |
| 478 } |
| 479 if ((node.x + node.getTotalNodeWidth()) > graph.maxGraphNodeX) { |
| 480 graph.maxGraphNodeX = node.x + node.getTotalNodeWidth(); |
| 481 } |
| 482 if ((node.y - 50) < graph.minGraphY) { |
| 483 graph.minGraphY = node.y - 50; |
| 484 } |
| 485 if ((node.y + graph.getNodeHeight() + 50) > graph.maxGraphY) { |
| 486 graph.maxGraphY = node.y + graph.getNodeHeight() + 50; |
| 487 } |
| 488 } |
| 489 |
| 472 graph.maxGraphX = graph.maxGraphNodeX + | 490 graph.maxGraphX = graph.maxGraphNodeX + |
| 473 backEdgeNumber * MINIMUM_EDGE_SEPARATION; | 491 graph.maxBackEdgeNumber * MINIMUM_EDGE_SEPARATION; |
| 492 |
| 474 } | 493 } |
| OLD | NEW |