[Question] Basic Graph with SvgGraphWriter
Closed this issue · 2 comments
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()
`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.
[s.svg.txt](https://github.com/microsoft/automatic-graph-layout/files/4973721/s.svg.txt)