microsoft / automatic-graph-layout

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

[Question] Basic Graph with SvgGraphWriter #248

Closed ghost closed 4 years ago

ghost commented 4 years ago

I am trying to create the simplest possible SVG rendering of a graph, using a single edge with two nodes, I have been reading sample code for the last hour, and hitting walls. Was hoping that some guidance could be provided.

        let graph = new Graph("Test")
        graph.AddEdge("a", "a to b", "b")
        use stream = new System.IO.MemoryStream()
        graph.CreateGeometryGraph() // otherwise NRE in SvgGraphWriter.TransformGraphByFlippingY
        let svgWriter = new SvgGraphWriter(stream, graph)
        svgWriter.Write()

This generates the following exception when svgWriter.Write() is called:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Msagl.Drawing.SvgGraphWriter.CurveStringTokens(ICurve iCurve)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.Msagl.Drawing.SvgGraphWriter.CurveString(ICurve iCurve)
   at Microsoft.Msagl.Drawing.SvgGraphWriter.WriteEdge(Edge edge)
   at Microsoft.Msagl.Drawing.SvgGraphWriter.WriteEdges()
   at Microsoft.Msagl.Drawing.SvgGraphWriter.Write()
levnach commented 4 years ago

`open System open Microsoft.Msagl.Drawing open Microsoft.Msagl.Layout.Layered open Microsoft.Msagl.Core.Geometry

[] let main argv = let graph = new Graph("Test") let mutable edge = graph.AddEdge("a", "a to b", "b") graph.CreateGeometryGraph() // otherwise NRE in SvgGraphWriter.TransformGraphByFlippingY

edge.SourceNode.Attr.Shape <- Shape.DrawFromGeometry; edge.TargetNode.Attr.Shape <- Shape.DrawFromGeometry; edge.GeometryEdge.Source.BoundaryCurve <- Microsoft.Msagl.Core.Geometry.Curves.CurveFactory.CreateCircle(10.0, new Point()) edge.TargetNode.GeometryNode.BoundaryCurve <- Microsoft.Msagl.Core.Geometry.Curves.CurveFactory.CreateCircle(10., new Point()) use stream = new System.IO.StreamWriter(@"c:\tmp\s.svg", false) let layout = new LayeredLayout(graph.GeometryGraph, new SugiyamaLayoutSettings()) layout.Run(); let svgWriter = new SvgGraphWriter(stream.BaseStream, graph) svgWriter.Write() 0 `

This seems working, but more code needed to create the label. Usually the viewers take care of filling the geometry.

<?xml version="1.0" encoding="utf-8"?>

s.svg.txt

ghost commented 4 years ago

Ahhhh! Ok this makes sense now, a little hand-raulic but that's ok! Thank you!

On Sat, 25 Jul 2020, 3:52 am Lev Nachmanson, notifications@github.com wrote:

`open System open Microsoft.Msagl.Drawing open Microsoft.Msagl.Layout.Layered open Microsoft.Msagl.Core.Geometry

[] let main argv = let graph = new Graph("Test") let mutable edge = graph.AddEdge("a", "a to b", "b") graph.CreateGeometryGraph() // otherwise NRE in SvgGraphWriter.TransformGraphByFlippingY

edge.SourceNode.Attr.Shape <- Shape.DrawFromGeometry; edge.TargetNode.Attr.Shape <- Shape.DrawFromGeometry; edge.GeometryEdge.Source.BoundaryCurve <- Microsoft.Msagl.Core.Geometry.Curves.CurveFactory.CreateCircle(10.0, new Point()) edge.TargetNode.GeometryNode.BoundaryCurve <- Microsoft.Msagl.Core.Geometry.Curves.CurveFactory.CreateCircle(10., new Point()) use stream = new System.IO.StreamWriter(@"c:\tmp\s.svg", false) let layout = new LayeredLayout(graph.GeometryGraph, new SugiyamaLayoutSettings()) layout.Run(); let svgWriter = new SvgGraphWriter(stream.BaseStream, graph) svgWriter.Write() 0 ` This seem working, but more code needed to create the label. Usually the viewers take care of filling the geometry.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/microsoft/automatic-graph-layout/issues/248#issuecomment-663658274, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMAM73EN4EMEGOX6HLF4YA3R5HC5BANCNFSM4PGL2HTQ .