Render to SVG

Topics: graph
May 8, 2008 at 8:56 AM
Hello,

can someone please show me a way to produce a file with coordinates - I wanted to produce a SVG
and I am missing something - the manual is not helping, I am afraid...

AdjacencyGraph<Entity, TaggedEdge<Entity, Interactions>> ag = new AdjacencyGraph<Entity, TaggedEdge<Entity, Interactions>>();


Entity e1 = new Entity();
Entity e2 = new Entity();
Entity e3 = new Entity();
Interactions i1 = new Interactions();
Interactions i2 = new Interactions();
TaggedEdge<Entity, Interactions> te = new TaggedEdge<Entity, Interactions>(e1, e2, i1);
TaggedEdge<Entity, Interactions> te2 = new TaggedEdge<Entity, Interactions>(e2, e3, i2);


ag.AddVertex(e1);
ag.AddVertex(e2);
ag.AddVertex(e3);

ag.AddEdge(te);
ag.AddEdge(te2);

IVertexAndEdgeListGraph<Entity, TaggedEdge<Entity, Interactions>> temp = ag;

GraphvizAlgorithm<Entity, TaggedEdge<Entity, Interactions>> gviz = new GraphvizAlgorithm<Entity, TaggedEdge<Entity, Interactions>>(temp, @".\", QuickGraph.Graphviz.Dot.GraphvizImageType.Png);



gviz.Generate(new FileDotEngine(), "output");


Thx for your help - btw: how can I use the markups :D?
May 9, 2008 at 11:16 AM
Ok, great work but without a real documentation I feel so lost.

I have a Bidirectionalgraph I want to visualize -> I map it to a IVertexandEdgeListGraph

Then I instantiate the GraphvizAlgorithm with the IVertexandEdgeListGraph...

Generate.... I have an dot... but there's just 0 - 5 in it (for Vertices and TaggedEdges). I need e.g. the name
of the Vertices and Edges.

Please help me, thats really important :)

What am I missing?
May 10, 2008 at 10:58 PM
Your question is not very clear. But if you are trying to add a name to each vertex/edge, attach an event handler before calling Generate.

      graphviz.FormatVertex += new FormatVertexEventHandler<Entity>( FormatVertex );

with:

    private void FormatVertex( object sender , FormatVertexEventArgs<Node> e )
    {

      e.VertexFormatter.Label = e.Vertex.WhatEverPropertyStoresTheStringYouWantToDisplay;

    }



May 13, 2008 at 6:25 PM
Thx, I figured it out, but forgot to post :(

The framework is really great, but I think a wiki would be perfect. I had a hard time, teaching me the internals.


Jun 4, 2008 at 1:22 PM


MMF wrote:
Hello,

can someone please show me a way to produce a file with coordinates - I wanted to produce a SVG
and I am missing something - the manual is not helping, I am afraid...

AdjacencyGraph<Entity, TaggedEdge<Entity, Interactions>> ag = new AdjacencyGraph<Entity, TaggedEdge<Entity, Interactions>>();


Entity e1 = new Entity();
Entity e2 = new Entity();
Entity e3 = new Entity();
Interactions i1 = new Interactions();
Interactions i2 = new Interactions();
TaggedEdge<Entity, Interactions> te = new TaggedEdge<Entity, Interactions>(e1, e2, i1);
TaggedEdge<Entity, Interactions> te2 = new TaggedEdge<Entity, Interactions>(e2, e3, i2);


ag.AddVertex(e1);
ag.AddVertex(e2);
ag.AddVertex(e3);

ag.AddEdge(te);
ag.AddEdge(te2);

IVertexAndEdgeListGraph<Entity, TaggedEdge<Entity, Interactions>> temp = ag;

GraphvizAlgorithm<Entity, TaggedEdge<Entity, Interactions>> gviz = new GraphvizAlgorithm<Entity, TaggedEdge<Entity, Interactions>>(temp, @".\", QuickGraph.Graphviz.Dot.GraphvizImageType.Png);



gviz.Generate(new FileDotEngine(), "output");


Thx for your help - btw: how can I use the markups :D?


Hello : 
    what is the meaning of Entity ?
Mar 27, 2010 at 1:35 AM
MMF wrote:
Thx, I figured it out, but forgot to post :(

The framework is really great, but I think a wiki would be perfect. I had a hard time, teaching me the internals.


So did you manage to create and output file containing SVG markup? If so tell me how..

 

The following code has a resultant output file containing dot code:

 

using (StreamReader reader = new StreamReader(filename))
            {
                string outfile = Path.Combine(Path.GetDirectoryName(filename), @"testicle42.svg");

                using (StreamWriter writer = new StreamWriter(outfile))
                {
                    new QuickGraph.Graphviz.FileDotEngine().Run(
                        QuickGraph.Graphviz.Dot.GraphvizImageType.Svg, reader.ReadToEnd(), outfile);
                }
            }

 

Mar 27, 2010 at 2:49 AM

Never mind. I see in the FileDotEngine source that the imageType parameter is not used in the implementation. It's basically just wrapping a single IO call. Uber handy.