2

I'm using GraphSharp to construct some graphs. The code I'm using constructs the vertex with its names (see this image: http://postimg.org/image/tn6km08an/).

What I want to do is: "hide" the nodes' name and change the vertex layout to circles, instead the names (something like this: https://i.stack.imgur.com/s9wGx.png).

Furthermore, I want to show the nodes' name (the names from the first img) when the mouse pointer is over a node.

Is it possible?

Here is my code:

xaml:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
    xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
    Title="1-Step Network"
    Height="350" 
    Width="525"

    x:Name="root">
<Grid>
    <zoom:ZoomControl>
    <graphsharp:GraphLayout x:Name="graphLayout"
                           Graph="{Binding ElementName=root,Path=GraphToVisualize}"
                            LayoutAlgorithmType="ISOM"
                            OverlapRemovalAlgorithmType="FSA"
                            HighlightAlgorithmType="Simple"/>
    </zoom:ZoomControl>
</Grid>

The .cs

public partial class MainWindow : Window
{
    public IBidirectionalGraph<object, IEdge<object>> _graphToVisualize;
    //public IUndirectedGraph<object,IEdge<object>> _graphToVisualize;

    public IBidirectionalGraph<object, IEdge<object>> GraphToVisualize
    //public IUndirectedGraph<object, IEdge<object>> GraphToVisualize
    {
        get { return _graphToVisualize; }
    }

    public MainWindow(int[,] matrix, string[] names)
    {
        CreateGraphToVisualize(matrix, names);

        InitializeComponent();            
    }

    public void CreateGraphToVisualize(int[,] matrix, string[] names)
    {
        var g = new BidirectionalGraph<object, IEdge<object>>();
        //var g=new UndirectedGraph<object, IEdge<object>>();

        //add the vertices do the graph
        string[] vertices = new string[matrix.GetLength(0)];

        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            vertices[i] = names[i];
            g.AddVertex(vertices[i]);
        }

        /*add some edges to the graph
        g.AddEdge(new Edge<object>(vertices[0], vertices[1]));
        g.AddEdge(new Edge<object>(vertices[1], vertices[2]));
        g.AddEdge(new Edge<object>(vertices[2], vertices[3]));
        g.AddEdge(new Edge<object>(vertices[3], vertices[1]));
        g.AddEdge(new Edge<object>(vertices[1], vertices[4]));*/
        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                if (i == j) break;

                if(matrix[i,j]==1) g.AddEdge(new Edge<object>(vertices[i], vertices[j]));
            }
        }

        _graphToVisualize = g;
    }
}

Thank you very much.

anderici
  • 77
  • 1
  • 11

0 Answers0