Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Basic Graph with SvgGraphWriter #248

Closed
ghost opened this issue Jul 24, 2020 · 2 comments
Closed

[Question] Basic Graph with SvgGraphWriter #248

ghost opened this issue Jul 24, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 24, 2020

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()
@ghost ghost changed the title Basic Graph with SvgGraphWriter [Question] Basic Graph with SvgGraphWriter Jul 24, 2020
@levnach
Copy link
Contributor

levnach commented Jul 24, 2020

`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)

@ghost
Copy link
Author

ghost commented Jul 24, 2020 via email

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant