Example #1
0
        /// <summary>
        /// Generates the dot code to be rendered with GraphViz
        /// </summary>
        /// <param name="outputFileName">output file name</param>
        /// <returns>corrected output file name</returns>
        /// <remarks>
        /// The output filename extension is automatically matched with the
        /// output file type.
        /// </remarks>
        public string Write(string outputFileName)
        {
            if (outputFileName == null)
            {
                throw new ArgumentNullException("outputFileName");
            }

            ClusterCount   = 0;
            m_StringWriter = new StringWriter();

            Output.WriteLine("digraph G {");

            String gf = GraphFormat.ToDot();

            if (gf.Length > 0)
            {
                Output.WriteLine(gf);
            }
            String vf = CommonVertexFormat.ToDot();

            if (vf.Length > 0)
            {
                Output.WriteLine("node [{0}];", vf);
            }
            String ef = CommonEdgeFormat.ToDot();

            if (ef.Length > 0)
            {
                Output.WriteLine("edge [{0}];", ef);
            }

            OnWriteGraph();

            // initialize vertex map
            VertexColorDictionary colors = new VertexColorDictionary();

            foreach (IVertex v in VisitedGraph.Vertices)
            {
                colors[v] = GraphColor.White;
            }
            EdgeColorDictionary edgeColors = new EdgeColorDictionary();

            foreach (IEdge e in VisitedGraph.Edges)
            {
                edgeColors[e] = GraphColor.White;
            }

            // write
            if (VisitedGraph is IClusteredGraph)
            {
                WriteClusters(colors, edgeColors, VisitedGraph as IClusteredGraph);
            }

            WriteVertices(colors, VisitedGraph.Vertices);
            WriteEdges(edgeColors, VisitedGraph.Edges);

            Output.WriteLine("}");

            return(m_Dot.Run(ImageType, Output.ToString(), outputFileName));
        }
        public string Generate(IDotEngine dot, string outputFileName)
        {
            if (dot == null)
            {
                throw new ArgumentNullException("dot");
            }
            if (outputFileName == null)
            {
                throw new ArgumentNullException("outputFileName");
            }

            this.vertexIds.Clear();

            this.output = new StringWriter();

            // build vertex id map
            int i = 0;

            foreach (TVertex v in this.VisitedGraph.Vertices)
            {
                this.vertexIds.Add(v, i++);
            }

            Output.WriteLine("digraph G {");

            String gf = GraphFormat.ToDot();

            if (gf.Length > 0)
            {
                Output.WriteLine(gf);
            }
            String vf = CommonVertexFormat.ToDot();

            if (vf.Length > 0)
            {
                Output.WriteLine("node [{0}];", vf);
            }
            String ef = CommonEdgeFormat.ToDot();

            if (ef.Length > 0)
            {
                Output.WriteLine("edge [{0}];", ef);
            }

            // initialize vertex map
            IDictionary <TVertex, GraphColor> colors = new Dictionary <TVertex, GraphColor>();

            foreach (var v in VisitedGraph.Vertices)
            {
                colors[v] = GraphColor.White;
            }
            IDictionary <TEdge, GraphColor> edgeColors = new Dictionary <TEdge, GraphColor>();

            foreach (var e in VisitedGraph.Edges)
            {
                edgeColors[e] = GraphColor.White;
            }

            WriteVertices(colors, VisitedGraph.Vertices);
            WriteEdges(edgeColors, VisitedGraph.Edges);

            Output.WriteLine("}");

            return(dot.Run(ImageType, Output.ToString(), outputFileName));
        }
        public string Generate()
        {
            ClusterCount = 0;
            this.vertexIds.Clear();
            this.output = new StringWriter();
            // build vertex id map
            int i = 0;

            foreach (TVertex v in this.VisitedGraph.Vertices)
            {
                this.vertexIds.Add(v, i++);
            }

            if (this.VisitedGraph.IsDirected)
            {
                this.Output.Write("digraph ");
            }
            else
            {
                this.Output.Write("graph ");
            }
            this.Output.Write(this.GraphFormat.Name);
            this.Output.WriteLine(" {");

            String gf = GraphFormat.ToDot();

            if (gf.Length > 0)
            {
                Output.WriteLine(gf);
            }
            String vf = CommonVertexFormat.ToDot();

            if (vf.Length > 0)
            {
                Output.WriteLine("node [{0}];", vf);
            }
            String ef = CommonEdgeFormat.ToDot();

            if (ef.Length > 0)
            {
                Output.WriteLine("edge [{0}];", ef);
            }

            // initialize vertex map
            var colors = new Dictionary <TVertex, GraphColor>();

            foreach (var v in VisitedGraph.Vertices)
            {
                colors[v] = GraphColor.White;
            }
            var edgeColors = new Dictionary <TEdge, GraphColor>();

            foreach (var e in VisitedGraph.Edges)
            {
                edgeColors[e] = GraphColor.White;
            }

            if (VisitedGraph is IClusteredGraph)
            {
                WriteClusters(colors, edgeColors, VisitedGraph as IClusteredGraph);
            }

            WriteVertices(colors, VisitedGraph.Vertices);
            WriteEdges(edgeColors, VisitedGraph.Edges);

            Output.WriteLine("}");
            return(Output.ToString());
        }