aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/graph/RenderDiGraph.scala
diff options
context:
space:
mode:
authorchick2020-08-14 19:47:53 -0700
committerJack Koenig2020-08-14 19:47:53 -0700
commit6fc742bfaf5ee508a34189400a1a7dbffe3f1cac (patch)
tree2ed103ee80b0fba613c88a66af854ae9952610ce /src/main/scala/firrtl/graph/RenderDiGraph.scala
parentb516293f703c4de86397862fee1897aded2ae140 (diff)
All of src/ formatted with scalafmt
Diffstat (limited to 'src/main/scala/firrtl/graph/RenderDiGraph.scala')
-rw-r--r--src/main/scala/firrtl/graph/RenderDiGraph.scala78
1 files changed, 38 insertions, 40 deletions
diff --git a/src/main/scala/firrtl/graph/RenderDiGraph.scala b/src/main/scala/firrtl/graph/RenderDiGraph.scala
index b3c1373c..45be3a8f 100644
--- a/src/main/scala/firrtl/graph/RenderDiGraph.scala
+++ b/src/main/scala/firrtl/graph/RenderDiGraph.scala
@@ -16,7 +16,6 @@ import scala.collection.mutable
*/
class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankDir: String = "LR") {
-
/**
* override this to change the default way a node is displayed. Default is toString surrounded by double quotes
* This example changes the double quotes to brackets
@@ -38,8 +37,7 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
try {
diGraph.linearize
- }
- catch {
+ } catch {
case cyclicException: CyclicException =>
val node = cyclicException.node.asInstanceOf[T]
path = diGraph.findLoopAtNode(node)
@@ -61,31 +59,29 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
val loop = findOneLoop
- if(loop.nonEmpty) {
+ if (loop.nonEmpty) {
// Find all the children of the nodes in the loop
val childrenFound = diGraph.getEdgeMap.flatMap {
case (node, children) if loop.contains(node) => children
- case _ => Seq.empty
+ case _ => Seq.empty
}.toSet
// Create a new DiGraph containing only loop and direct children or parents
val edgeData = diGraph.getEdgeMap
- val newEdgeData = edgeData.flatMap { case (node, children) =>
- if(loop.contains(node)) {
- Some(node -> children)
- }
- else if(childrenFound.contains(node)) {
- Some(node -> children.intersect(loop))
- }
- else {
- val newChildren = children.intersect(loop)
- if(newChildren.nonEmpty) {
- Some(node -> newChildren)
- }
- else {
- None
- }
+ val newEdgeData = edgeData.flatMap {
+ case (node, children) =>
+ if (loop.contains(node)) {
+ Some(node -> children)
+ } else if (childrenFound.contains(node)) {
+ Some(node -> children.intersect(loop))
+ } else {
+ val newChildren = children.intersect(loop)
+ if (newChildren.nonEmpty) {
+ Some(node -> newChildren)
+ } else {
+ None
+ }
}
}
@@ -96,8 +92,7 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
}
}
newRenderer.toDotWithLoops(loop, getRankedNodes)
- }
- else {
+ } else {
""
}
}
@@ -114,10 +109,11 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
val edges = diGraph.getEdgeMap
- edges.foreach { case (parent, children) =>
- children.foreach { child =>
- s.append(s""" ${renderNode(parent)} -> ${renderNode(child)};""" + "\n")
- }
+ edges.foreach {
+ case (parent, children) =>
+ children.foreach { child =>
+ s.append(s""" ${renderNode(parent)} -> ${renderNode(child)};""" + "\n")
+ }
}
s.append("}\n")
s.toString
@@ -137,24 +133,25 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
val edges = diGraph.getEdgeMap
- edges.foreach { case (parent, children) =>
- allNodes += parent
- allNodes ++= children
+ edges.foreach {
+ case (parent, children) =>
+ allNodes += parent
+ allNodes ++= children
- children.foreach { child =>
- val highlight = if(loopedNodes.contains(parent) && loopedNodes.contains(child)) {
- "[color=red,penwidth=3.0]"
- }
- else {
- ""
+ children.foreach { child =>
+ val highlight = if (loopedNodes.contains(parent) && loopedNodes.contains(child)) {
+ "[color=red,penwidth=3.0]"
+ } else {
+ ""
+ }
+ s.append(s""" ${renderNode(parent)} -> ${renderNode(child)}$highlight;""" + "\n")
}
- s.append(s""" ${renderNode(parent)} -> ${renderNode(child)}$highlight;""" + "\n")
- }
}
val paredRankedNodes = rankedNodes.flatMap { nodes =>
val newNodes = nodes.filter(allNodes.contains)
- if(newNodes.nonEmpty) { Some(newNodes) } else { None }
+ if (newNodes.nonEmpty) { Some(newNodes) }
+ else { None }
}
paredRankedNodes.foreach { nodesAtRank =>
@@ -183,7 +180,7 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
diGraph.getEdges(node)
}.filterNot(alreadyVisited.contains).distinct
- if(nextNodes.nonEmpty) {
+ if (nextNodes.nonEmpty) {
walkByRank(nextNodes, rankNumber + 1)
}
}
@@ -191,6 +188,7 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
walkByRank(diGraph.findSources.toSeq)
rankNodes
}
+
/**
* Convert this graph into input for the graphviz dot program.
* It tries to align nodes in columns based
@@ -216,7 +214,7 @@ class RenderDiGraph[T <: Any](diGraph: DiGraph[T], graphName: String = "", rankD
children
}.filterNot(alreadyVisited.contains).distinct
- if(nextNodes.nonEmpty) {
+ if (nextNodes.nonEmpty) {
walkByRank(nextNodes, rankNumber + 1)
}
}