Exemplo n.º 1
0
        /// <summary>
        /// Computes the layout of the graph using Graphviz
        /// </summary>
        /// <remarks>
        /// </remarks>
        public void Compute()
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("digraph G{");
            sw.WriteLine("rankdir={0}",this.RankDirection);

            foreach(IVertex v in this.VisitedGraph.Vertices)
            {
                if (this.vertexSizes.Count==0)
                {
                    sw.WriteLine("{0} [shape=box];",v.ID);
                }
                else
                {
                    SizeF size = this.vertexSizes[v];
                    sw.WriteLine("{0} [shape=box, width={1}, height={2}, fixedsize=true];",
                        v.ID,
                        size.Width/this.DpiX,
                        size.Height/this.DpiY
                        );
                }
            }

            foreach(IEdge e in this.VisitedGraph.Edges)
            {
                sw.WriteLine("{0} -> {1} [label=\"{2}\"];",e.Source.ID,e.Target.ID, e.ID);
            }

            sw.WriteLine("}");

            System.Diagnostics.Debug.WriteLine(sw.ToString());

            // running graphviz
            NGraphviz.Helpers.Dot dot =new NGraphviz.Helpers.Dot(".");
            GraphLayout gl=dot.RunData(sw.ToString());

            // build vertex id map

            OnGraphSize(gl.Size);
            if (LayVertex!=null)
            {
                foreach(IVertex v in this.VisitedGraph.Vertices)
                {
                    VertexLayout vl = (VertexLayout)gl.Vertices[v.ID.ToString()];
                    OnLayVertex(v,vl.Pos);
                }
            }

            if (LayEdge!=null)
            {
                foreach(IEdge e in this.VisitedGraph.Edges)
                {
                    EdgeLayout el = (EdgeLayout)gl.Edges[e.ID.ToString()];
                    OnLayEdge(
                        e,
                        ConvertEdgePort(el.SourcePort),
                        ConvertEdgePort(el.TargetPort),
                        el.Keys);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Computes the layout of the graph using Graphviz
        /// </summary>
        /// <remarks>
        /// </remarks>
        public void Compute()
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("digraph G{");
            sw.WriteLine("rankdir={0}", this.RankDirection);

            foreach (IVertex v in this.VisitedGraph.Vertices)
            {
                if (this.vertexSizes.Count == 0)
                {
                    sw.WriteLine("{0} [shape=box];", v.ID);
                }
                else
                {
                    SizeF size = this.vertexSizes[v];
                    sw.WriteLine("{0} [shape=box, width={1}, height={2}, fixedsize=true];",
                                 v.ID,
                                 size.Width / this.DpiX,
                                 size.Height / this.DpiY
                                 );
                }
            }

            foreach (IEdge e in this.VisitedGraph.Edges)
            {
                sw.WriteLine("{0} -> {1} [label=\"{2}\"];", e.Source.ID, e.Target.ID, e.ID);
            }

            sw.WriteLine("}");

            System.Diagnostics.Debug.WriteLine(sw.ToString());

            // running graphviz
            NGraphviz.Helpers.Dot dot = new NGraphviz.Helpers.Dot(".");
            GraphLayout           gl  = dot.RunData(sw.ToString());

            // build vertex id map

            OnGraphSize(gl.Size);
            if (LayVertex != null)
            {
                foreach (IVertex v in this.VisitedGraph.Vertices)
                {
                    VertexLayout vl = (VertexLayout)gl.Vertices[v.ID.ToString()];
                    OnLayVertex(v, vl.Pos);
                }
            }

            if (LayEdge != null)
            {
                foreach (IEdge e in this.VisitedGraph.Edges)
                {
                    EdgeLayout el = (EdgeLayout)gl.Edges[e.ID.ToString()];
                    OnLayEdge(
                        e,
                        ConvertEdgePort(el.SourcePort),
                        ConvertEdgePort(el.TargetPort),
                        el.Keys);
                }
            }
        }