Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't display non-visible highlight-adjacent nodes #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions src/main/kotlin/callgraph/Canvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,33 @@ class Canvas(private val callGraphToolWindow: CallGraphToolWindow): JPanel() {

// draw upstream/downstream edgesMap
val highlightedNodes = this.visibleNodes.filter { isNodeHighlighted(it) }.toSet()
val upstreamEdges = highlightedNodes.flatMap { it.inEdges.values }.toSet()
val downstreamEdges = highlightedNodes.flatMap { it.outEdges.values }.toSet()
upstreamEdges.forEach { drawNonLoopEdge(graphics2D, it, Colors.UPSTREAM_COLOR.color) }
downstreamEdges.forEach { drawNonLoopEdge(graphics2D, it, Colors.DOWNSTREAM_COLOR.color) }
val filteredUpstreamEdges = highlightedNodes.flatMap { it.inEdges.values }.toSet()
.filter { isNodeVisibleBasedOnVisibilityFilters(it.sourceNode) }
val filteredDownstreamEdges = highlightedNodes.flatMap { it.outEdges.values }.toSet()
.filter { isNodeVisibleBasedOnVisibilityFilters(it.sourceNode) }
filteredUpstreamEdges.forEach { drawNonLoopEdge(graphics2D, it, Colors.UPSTREAM_COLOR.color) }
filteredDownstreamEdges.forEach { drawNonLoopEdge(graphics2D, it, Colors.DOWNSTREAM_COLOR.color) }

// draw un-highlighted labels
val upstreamNodes = upstreamEdges.map { it.sourceNode }.toSet()
val downstreamNodes = downstreamEdges.map { it.targetNode }.toSet()
val filteredUpstreamNodes = filteredUpstreamEdges.map { it.sourceNode }.toSet()
val filteredDownstreamNodes = filteredDownstreamEdges.map { it.targetNode }.toSet()
val unHighlightedNodes = this.visibleNodes
.filter { !isNodeHighlighted(it) && !upstreamNodes.contains(it) && !downstreamNodes.contains(it) }
.filter { !isNodeHighlighted(it) && !filteredUpstreamNodes.contains(it)
&& !filteredDownstreamNodes.contains(it) }
.toSet()
unHighlightedNodes.forEach { drawNodeLabels(graphics2D, it, Colors.NEUTRAL_COLOR.color, false) }

// draw un-highlighted nodesMap (upstream/downstream nodesMap are excluded)
this.nodeShapesMap.clear()
unHighlightedNodes
.filter { !upstreamNodes.contains(it) && !downstreamNodes.contains(it) }
.filter { !filteredUpstreamNodes.contains(it) && !filteredDownstreamNodes.contains(it) }
.forEach { drawNode(graphics2D, it, Colors.UN_HIGHLIGHTED_COLOR.color) }

// draw upstream/downstream label and nodesMap
upstreamNodes.forEach { drawNodeLabels(graphics2D, it, Colors.UPSTREAM_COLOR.color, false) }
downstreamNodes.forEach { drawNodeLabels(graphics2D, it, Colors.DOWNSTREAM_COLOR.color, false) }
upstreamNodes.forEach { drawNode(graphics2D, it, Colors.UPSTREAM_COLOR.color) }
downstreamNodes.forEach { drawNode(graphics2D, it, Colors.DOWNSTREAM_COLOR.color) }
filteredUpstreamNodes.forEach { drawNodeLabels(graphics2D, it, Colors.UPSTREAM_COLOR.color, false) }
filteredDownstreamNodes.forEach { drawNodeLabels(graphics2D, it, Colors.DOWNSTREAM_COLOR.color, false) }
filteredUpstreamNodes.forEach { drawNode(graphics2D, it, Colors.UPSTREAM_COLOR.color) }
filteredDownstreamNodes.forEach { drawNode(graphics2D, it, Colors.DOWNSTREAM_COLOR.color) }

// draw highlighted node and label
this.visibleNodes
Expand Down Expand Up @@ -185,27 +188,28 @@ class Canvas(private val callGraphToolWindow: CallGraphToolWindow): JPanel() {

fun filterChangeHandler() {
this.visibleNodes.clear()
this.visibleNodes.addAll(this.graph.getNodes()
.filter { node ->
val method = node.method
val isVisibleAccessLevel = when {
Utils.isPublic(method) -> this.callGraphToolWindow.isFilterAccessPublicChecked()
Utils.isProtected(method) -> this.callGraphToolWindow.isFilterAccessProtectedChecked()
Utils.isPackageLocal(method) -> this.callGraphToolWindow.isFilterAccessPackageLocalChecked()
Utils.isPrivate(method) -> this.callGraphToolWindow.isFilterAccessPrivateChecked()
else -> true
}
val isExternalMethod = Utils.getSourceRoot(method.containingFile.virtualFile) == null
val isVisibleExternal = !isExternalMethod || this.callGraphToolWindow.isFilterExternalChecked()

isVisibleAccessLevel && isVisibleExternal
})
this.visibleNodes.addAll(this.graph.getNodes().filter(this::isNodeVisibleBasedOnVisibilityFilters))
this.visibleEdges.clear()
this.visibleEdges.addAll(graph.getEdges()
.filter { this.visibleNodes.contains(it.sourceNode) && this.visibleNodes.contains(it.targetNode) })
repaint()
}

private fun isNodeVisibleBasedOnVisibilityFilters(node: Node): Boolean {
val method = node.method
val isVisibleAccessLevel = when {
Utils.isPublic(method) -> this.callGraphToolWindow.isFilterAccessPublicChecked()
Utils.isProtected(method) -> this.callGraphToolWindow.isFilterAccessProtectedChecked()
Utils.isPackageLocal(method) -> this.callGraphToolWindow.isFilterAccessPackageLocalChecked()
Utils.isPrivate(method) -> this.callGraphToolWindow.isFilterAccessPrivateChecked()
else -> true
}
val isExternalMethod = Utils.getSourceRoot(method.containingFile.virtualFile) == null
val isVisibleExternal = !isExternalMethod || this.callGraphToolWindow.isFilterExternalChecked()

return isVisibleAccessLevel && isVisibleExternal
}

private fun toCameraView(point: Point2D.Float): Point2D.Float {
val canvasSize = this.callGraphToolWindow.getCanvasSize()
return Point2D.Float(
Expand Down