Package com.shyarnis.topsort.utils
Class GraphVisualizer
java.lang.Object
com.shyarnis.topsort.utils.GraphVisualizer
Utility class for visualizing directed graphs in GraphViz DOT format and rendering them to PNG.
This class provides static methods to:
- Convert a graph to DOT format representing the original edges
- Convert a topologically sorted list of nodes to a chained DOT graph
- Render DOT files to PNG using the external GraphViz tool
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
renderDotToPng
(String dotPath, String pngPath) Renders a GraphViz DOT file to a PNG image using the GraphViz CLI tool.static <T> void
visualizeOriginalGraph
(Graph<T> graph, String dotPath) Generates a GraphViz DOT representation of the original directed graph.static <T> void
visualizeSortedGraph
(List<T> sortedOrder, String dotPath) Generates a GraphViz DOT representation of a topologically sorted list of nodes, displaying them as a simple directed chain.
-
Method Details
-
visualizeOriginalGraph
Generates a GraphViz DOT representation of the original directed graph.- Type Parameters:
T
- the type of node in the graph- Parameters:
graph
- the directed graph to visualizedotPath
- the output path for the generated DOT file- Throws:
IOException
- if the DOT file cannot be written
-
visualizeSortedGraph
Generates a GraphViz DOT representation of a topologically sorted list of nodes, displaying them as a simple directed chain.- Type Parameters:
T
- the type of node- Parameters:
sortedOrder
- the list of nodes in topological orderdotPath
- the output path for the generated DOT file- Throws:
IOException
- if the DOT file cannot be written
-
renderDotToPng
public static void renderDotToPng(String dotPath, String pngPath) throws IOException, InterruptedException Renders a GraphViz DOT file to a PNG image using the GraphViz CLI tool.Requires the
dot
command to be installed and available in the system path.- Parameters:
dotPath
- the path to the input DOT filepngPath
- the path to the output PNG file- Throws:
IOException
- if the external process cannot be startedInterruptedException
- if the rendering process is interruptedRuntimeException
- if GraphViz fails to render the image
-