Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Graph.ReadGraphFromStream ignores subgraph

Open
#330 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp

Research direction

Start by reproducing the provided example with Graph.WriteToStream and Graph.ReadGraphFromStream, then inspect how the lone subgraph is reconstructed before assigning the result to gViewer.Graph. Compare this with the temporary-subgraph workaround. Done means a graph containing one subgraph renders that subgraph in gViewer after a stream round trip.

Written by the indexing model from the issue text.

Description

When only 1 subgraph is present in an XML stream the subgraph is not rendered in gviewer. The current workaround i've been using is to add a temporary subgraph before writing the graph to XML, then removing the temporary subgraph after reading the XML into a graph

See code for example

        Graph graph = new Graph("graph");
        var node1 = new Node("test1");
        graph.AddNode(node1);

        var subgraph = new Subgraph("subgraph1");
        graph.RootSubgraph.AddSubgraph(subgraph);
        subgraph.AddNode(node1);

        //uncommenting the next 2 lines will make subgraph1 appear. If left uncommented, subgraph1 will not appear
        //var subgraph2 = new Subgraph("delete") { IsVisible = false }; //IsVisible is not carried over in stream
        //graph.RootSubgraph.AddSubgraph(subgraph2);

        //write graph to xml
        string xml;
        using (var stream1 = new MemoryStream()) {
            graph.WriteToStream(stream1);
            stream1.Position = 0;
            using (var streamReader = new StreamReader(stream1)) {
                xml = streamReader.ReadToEnd();
            } 
        }

        //read graph from xml
        using (var stream = new MemoryStream()) {
            using (var streamWriter = new StreamWriter(stream)) {
                streamWriter.Write(xml);
                streamWriter.Flush();//otherwise you are risking empty stream
                stream.Position = 0;
                graph = Graph.ReadGraphFromStream(stream);
            }
        }

        //graph.RootSubgraph.RemoveSubgraph(graph.RootSubgraph.Subgraphs.Where(x => x.Id == "delete").FirstOrDefault());
        

        gViewer.Graph = graph;
Dominant language
C#
Stars
1.5k
Forks
319
PR merge metrics
No merged PRs in 30d

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/automatic-graph-layout

All issues in microsoft/automatic-graph-layout

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.