Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sample for using Graph# in Winforms

Tags:

c#

graph

winforms

Can anyone point me to an example of how to use Graph# via ElementHost in a winforms application (c#).

Especially loading *.gml - files and showing the Graph-control.

Any help appreciated.

like image 339
ralf.w. Avatar asked Jun 16 '11 19:06

ralf.w.


People also ask

What sampling is with the use of graphs?

Graph sampling is a technique to pick a subset of vertices and/ or edges from original graph. It has a wide spectrum of applications, e.g. survey hidden population in sociology [54], visualize social graph [29], scale down Internet AS graph [27], graph sparsification [8], etc.

What are the 3 commonly used graphs?

Three types of graphs are used in this course: line graphs, pie graphs, and bar graphs.


1 Answers

The basic idea is to create a WPF user control, that encapsulates a Graph # canvas. This user control is what you would then display in the ElementHost.

I have put together a small sample application that demonstrates this by basically exposing the GraphSharp.Sample.TestCompoundLayout window as user control.

http://cl.ly/0w350230200g0w0o2R2N

I also added loading from GML files which basically boils down to this function:

        var graph = new CompoundGraph<object, IEdge<object>>();

        try
        {
            //open the file of the graph
            var reader = XmlReader.Create(fileName);

            //create the serializer
            var serializer = new GraphMLDeserializer<object, IEdge<object>, CompoundGraph<object, IEdge<object>>>();


            //deserialize the graph
            serializer.Deserialize(reader, graph,
                                   id => id, (source, target, id) => new Edge<object>(source, target)
                );

        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        layout.Graph = graph;
        layout.UpdateLayout();
like image 136
Frank Avatar answered Oct 16 '22 23:10

Frank