public void Constructor() { var font = new GraphvizFont("TestFont", 12.5f); Assert.AreEqual("TestFont", font.Name); Assert.AreEqual(12.5f, font.SizeInPoints); font = new GraphvizFont("OtherFont", 22.0f); Assert.AreEqual("OtherFont", font.Name); Assert.AreEqual(22.0f, font.SizeInPoints); }
private static void AssertEqual(Font font, GraphvizFont qFont) { if (font is null) { Assert.IsNull(qFont); } else { Assert.AreEqual(qFont.Name, font.Name); Assert.AreEqual(qFont.SizeInPoints, font.SizeInPoints); } }
// ReSharper restore UnusedAutoPropertyAccessor.Local /// <summary> /// Renders the change details as SVG directed graph. /// </summary> /// <param name="renderer">SVG renderer to use.</param> /// <returns><see cref="XElement"/> containing SVG fragment for adding to browser view.</returns> public async Task <XElement> RenderSvg(ISvgRenderer renderer) { var graph = this.GenerateChangeGraph(); var dotGraph = graph.ToGraphviz( algorithm => { var font = new GraphvizFont("Arial", 9); algorithm.CommonVertexFormat.Font = font; algorithm.CommonEdgeFormat.Font = font; algorithm.GraphFormat.RankDirection = GraphvizRankDirection.LR; algorithm.FormatVertex += (sender, args) => { args.VertexFormat.Label = args.Vertex.ToString(); args.VertexFormat.Shape = args.Vertex.Shape; if (args.Vertex is ResourceVertex rv) { args.VertexFormat.Label = rv.Label; args.VertexFormat.IsHtmlLabel = true; args.VertexFormat.Style = rv.Style; args.VertexFormat.FillColor = rv.FillColor; args.VertexFormat.FontColor = rv.FontColor; } }; algorithm.FormatEdge += (sender, args) => { args.EdgeFormat.Label.Value = args.Edge.Tag; }; }); var svg = await renderer.RenderSvg(dotGraph); if (svg != null) { // Now change the width and height attributes of the SVG to 100% so it becomes responsive in bootstrap if (svg.Attribute("width") != null) { svg.Attribute("width").Value = "100%"; } if (svg.Attribute("height") != null) { svg.Attribute("height").Value = "100%"; } } return(svg); }
public void ToGraphvizFont() { var font = new Font("Microsoft Sans Serif", 12.5f); GraphvizFont qFont = font.ToGraphvizFont(); AssertEqual(font, qFont); font = new Font("Comic Sans MS", 25.0f); qFont = font.ToGraphvizFont(); AssertEqual(font, qFont); // ReSharper disable ExpressionIsAlwaysNull font = null; qFont = font.ToGraphvizFont(); AssertEqual(font, qFont); // ReSharper restore ExpressionIsAlwaysNull }
public static Font ToFont([CanBeNull] this GraphvizFont font) { return(font is null ? null : new Font(font.Name, font.SizeInPoints)); }