【问题标题】:Visualize data structures such as trees and graphs in C# [closed]在 C# 中可视化数据结构,例如树和图 [关闭]
【发布时间】:2020-05-03 01:24:24
【问题描述】:

我正在使用带有 LINQPad 的 C#。是否有任何库或 NuGet 包可以让我可视化图形和树?

例如,如果我创建一个这样的树数据结构:

public class BinaryTree<T>()
{
    public T Value { get; set; }
    public BinaryTree<T> LeftChild { get; set; }
    public BinaryTree<T> RightChild { get; set; }

    //Other methods:
}

我想要一种简单的方式在我执行程序时显示它,例如,像这样:

什么库/包允许我这样做(或者是 LINQPad 和/或 Visual Studio 中内置的功能)?

【问题讨论】:

    标签: c# .net visual-studio linqpad


    【解决方案1】:

    您最好的选择可能是使用Microsoft Automatic Graph Layout。这就是 LINQPad 用于语法树可视化器的内容。

    在 LINQPad 5 中,您只需添加对 Microsoft.MSAGL.GraphViewerGDIGraph NuGet 包的引用即可使用此库。然后你可以这样做:

    var graph = new Graph ("graph");
    
    graph.AddEdge ("A", "B");
    graph.AddEdge ("B", "C");
    graph.AddEdge ("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green;
    
    new GViewer() { Graph = graph, ToolBarIsVisible = false }.Dump();
    

    不幸的是,这在 LINQPad 6(来自 .NET Core 3.1)中不起作用,因为 Microsoft.MSAGL.GraphViewerGDIGraph 是一个 .NET Framework 包,它依赖于在 .NET Core 3.1 中删除的 WinForms 工具栏控件。但是,MSAGL 是开源的,删除依赖项相当容易,就像我在这里所做的那样:

    https://github.com/albahari/automatic-graph-layout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-20
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-02
      相关资源
      最近更新 更多