Skip to content

Commit

Permalink
#19 start working on the layout process
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Oct 28, 2018
1 parent 2836ca7 commit 89e70d7
Showing 1 changed file with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,47 @@ import org.ephyra.acropolis.report.api.IReportRunner
import org.ephyra.acropolis.report.api.model.Graph
import org.ephyra.acropolis.report.api.model.GraphContainer
import org.ephyra.acropolis.report.api.model.Node
import org.ephyra.acropolis.report.impl.render.DiagramRenderer
import org.springframework.stereotype.Component
import java.lang.IllegalStateException

@Component
private class ReportRunner : IReportRunner {
override fun run(graphContainer: GraphContainer) {
println("Running report")
buildNodeDepth(graphContainer.graph)
val depthMap = buildNodeDepth(graphContainer.graph)
val depthCounts = countDepths(depthMap)


val maxDepth = depthMap.values.max() ?: throw IllegalStateException("missing depth")
val maxCountAtDepth = depthCounts.values.max() ?: throw IllegalStateException("missing count")

val tileWidth = 300
val tileHeight = 350

val cardSeparationHorizontal = 75
val cardSeparationVertical = 35

val diagramPadding = 30

val diagramWidth = 2 * diagramPadding + (maxDepth + 1) * tileWidth + maxDepth * cardSeparationHorizontal
val diagramHeight = 2 * diagramPadding + (maxCountAtDepth + 1) * tileHeight + maxCountAtDepth * cardSeparationVertical

DiagramRenderer(diagramWidth, diagramHeight).use { renderer ->

}
}

private fun countDepths(depthMap: HashMap<Node, Int>): HashMap<Int, Int> {
val depthCounts = HashMap<Int, Int>()
depthMap.forEach { (_, v) ->
val t = depthCounts[v]
if (t == null) {
depthCounts[v] = 0
} else {
depthCounts[v] = t + 1
}
}
return depthCounts
}

fun buildNodeDepth(graph: Graph): HashMap<Node, Int> {
Expand Down Expand Up @@ -53,3 +85,8 @@ private class ReportRunner : IReportRunner {
}
}
}

class Position(
val x: Float,
val y: Float
)

0 comments on commit 89e70d7

Please sign in to comment.