Example #1
0
        /// <summary>
        ///     Saves the given <see cref="ITreeNode" /> to an image file.
        /// </summary>
        /// <param name="rootNode">The root node of the tree to be saved.</param>
        /// <param name="basePath">The path in which to save the given tree</param>
        /// <param name="fileName">The name of the image file to be saved (without extension)</param>
        /// <param name="formatVertex">The delegate used to format the vertexes.</param>
        /// <param name="formatEdge">The delegate used to format the edges.</param>
        /// <param name="imageType">The type of image file in which to save the tree.</param>
        /// <param name="timeout">The maximum time to wait for Graphviz to create the image file.</param>
        /// <returns>The path to file where the tree image file was saved.</returns>
        public static string ToGraphvizFile(
            this ITreeNode rootNode, string basePath, string fileName,
            FormatVertexEventHandler <Vertex> formatVertex,
            FormatEdgeAction <Vertex, Edge> formatEdge,
            GraphvizImageType imageType = GRAPHVIZ_IMAGE_TYPE, int timeout = GRAPHVIZ_TIMEOUT_MS)
        {
            var graph = new AdjacencyGraph <Vertex, Edge>();

            GraphAdd(rootNode, graph, new Dictionary <ITreeNode, Vertex>());

            var filePath = Path.Combine(basePath, $"{fileName}.dot");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var viz = new GraphvizAlgorithm <Vertex, Edge>(graph)
            {
                ImageType = imageType
            };

            if (formatVertex != null)
            {
                viz.FormatVertex += formatVertex;
            }
            if (formatEdge != null)
            {
                viz.FormatEdge += formatEdge;
            }
            return(viz.Generate(new FileDotEngine(timeout), filePath));
        }
Example #2
0
        public static void Visualize <TVertex, TEdge>(this IVertexAndEdgeListGraph <TVertex, TEdge> graph,
                                                      string fileName, FormatEdgeAction <TVertex, TEdge> edgeFormatter, string dir /*@"c:\temp\"*/)
            where TEdge : IEdge <TVertex>
        {
            var fullFileName = Path.Combine(dir, fileName);
            var viz          = new GraphvizAlgorithm <TVertex, TEdge>(graph);

            viz.FormatVertex += VizFormatVertex;

            viz.FormatEdge += edgeFormatter;

            viz.Generate(new FileDotEngine(), fullFileName);
        }
Example #3
0
        public static void Visualize <TEdge>(this IEdgeListGraph <int, TEdge> graph,
                                             string dotProgramLocation, string outputFullFileName, FormatEdgeAction <int, TEdge> edgeFormatter)
            where TEdge : IEdge <int>
        {
            var viz = new GraphvizAlgorithm <int, TEdge>(graph);

            viz.FormatVertex += VizFormastring;

            viz.FormatEdge += edgeFormatter;

            viz.Generate(new FileDotEngine(dotProgramLocation), outputFullFileName);
        }