visualizeGraph

fun <T : Any> BaseGraph<T>.visualizeGraph(bidirectional: Boolean = false, finalPath: List<T> = finalPath(), screenTitle: String = "Graph visualizer (Click or space to pause and resume)", animationTicTimeOverride: Double? = null, closeOnEnd: Boolean = false, startPaused: Boolean = false, screenWidthOverride: Double? = null)

Visualizes the graph with Bruno Silva's JavaFXSmartGraph library.

The function visualizes nodes with edges using a force-directed algorithm. Then it animates the traversal of the graph, highlighting visited nodes and the final path from the start node to the target node if a search has been performed.

Example usage:

val graph = Graph(false)
graph.connect("A", "B")
graph.connect("A", "C")
graph.visualizeGraph(
bidirectional = true,
finalPath = listOf("A", "B"),
screenTitle = "GraphMateKT visualizeGraph example usage",
animationTicTimeOverride = 2000.0,
closeOnEnd = true,
startPaused = true,
screenWidthOverride = 300.0
)

NOTE: to use this visualizeGraph() function, the files smartgraph.css and smartgraph.properties must be added manually to the root of your project, as described in Bruno Silva's JavaFXSmartGraph repository: https://github.com/brunomnsilva/JavaFXSmartGraph

Parameters

bidirectional

If true, visualizes the graph as bidirectional, otherwise as directed.

finalPath

A list of nodes that can override the final path, and be animated instead. If not provided, the graph's own final path is used.

screenTitle

The title of the visualization window.

animationTicTimeOverride

Overrides the default animation speed in milliseconds.

closeOnEnd

If true, closes the visualization window when the animation ends.

startPaused

If true, starts the visualization in a paused state.

screenWidthOverride

Overrides the default screen width for the visualization.

Throws

IllegalStateException

If the graph is improperly configured for visualization.