microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.36k stars 307 forks source link

Graph.Read ignores subgraph in Wpf #376

Open TihonchukArtyom89 opened 2 months ago

TihonchukArtyom89 commented 2 months ago

Hi! I am create a graph add nodes and edges, and put some nodes in a subgraph. Then I am write this graph to *.msagl file and open with Graph.Read from this file and bind it to DockPanel. It display graph with all nodes and edges, but without subgraph. Code:

      GraphViewer graphViewer = new GraphViewer();
      Graph graph = new();
      graphViewer.BindToPanel(graphViewerPanel);
      var a =graph.AddNode("A");
      var b = graph.AddNode("B");
      var c = graph.AddNode("C");
      var d = graph.AddNode("D");
      var f = graph.AddNode("F");
      b.Attr.Shape = Shape.Hexagon;
      var ab = graph.AddEdge(a.Id, b.Id);
      var fc = graph.AddEdge(f.Id, c.Id);
      var da = graph.AddEdge(d.Id, a.Id);
      var fa = graph.AddEdge(a.Id, f.Id);
      var s = new Subgraph("sub_Id");
      s.Attr.Color = Microsoft.Msagl.Drawing.Color.Red;
      s.Attr.FillColor = Microsoft.Msagl.Drawing.Color.Green;
      s.Attr.Shape = Shape.Box;
      s.Label.FontColor=Microsoft.Msagl.Drawing.Color.Black;
      s.Label.Text = "text subgraph";
      s.AddNode(a);
      s.AddNode(d);
      s.AddNode(f);
      graph.RootSubgraph.AddSubgraph(s);
      graph.Write("test_graph_with_subgraph.msagl");
      graph = Graph.Read("test_graph_with_subgraph.msagl");
      graphViewer.Graph = graph;