2

我正在使用 GraphSharp 构建一些图表。我使用的代码用它的名字构造了顶点(见这张图片: http: //postimg.org/image/tn6km08an/)。

我想要做的是:“隐藏”节点的名称并将顶点布局更改为圆圈,而不是名称(类似于:http: //i.stack.imgur.com/s9wGx.png)。

此外,当鼠标指针悬停在节点上时,我想显示节点的名称(第一个 img 中的名称)。

可能吗?

这是我的代码:

xml:

<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>

.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;
    }
}

非常感谢。

4

0 回答 0