private string GenerateSvg() { var g = new Graph(); g.ColorScheme = "svg"; g.RankDir = RankDirType.LR; foreach (var cls in Model.Classes.Values) { if (cls.TargetClass.Compiled.Attr("nosvg").ToBool()) { continue; } var n = new Node { Code = cls.Name, Label = cls.Name, Tooltip = cls.Comment, Shape = NodeShapeType.Box3d }; var dotcolor = cls.TargetClass.Compiled.Attr("dot-color"); if (!string.IsNullOrWhiteSpace(dotcolor)) { n.Style = NodeStyleType.Filled; n.FillColor = ColorAttribute.Single(Color.Create(dotcolor)); } g.AddNode(n); foreach (var r in cls.GetReferences()) { if (r.NoSql) { continue; } if (null == r.ReferenceClass.TargetClass) { continue; } if (r.ReferenceClass.TargetClass.Compiled.Attr("nosvg").ToBool()) { continue; } var e = new Edge { From = cls.Name, To = r.ReferenceClass.Name, ArrowHead = new Arrow { MainType = ArrowType.Normal } }; if (r.IsReverese) { e.ArrowTail = new Arrow { MainType = ArrowType.Diamond }; } g.AddEdge(e); } } var provider = new DotGraphProvider(); var render = GraphRender.Create(g); var script = render.GenerateGraphScript(); var svg = provider.Generate(script, new GraphOptions { Format = "svg" }); return(svg.ToString()); }
string render(Graph g, GraphOptions o = null) { var result = GraphRender.Create(g, o).GenerateGraphScript(); Console.WriteLine(result); Console.WriteLine(result.Replace("\"", "\"\"")); return(result); }
public void AutoGenerateSubgraph() { var g = new Graph(); var n = new Node { Code = "x", SubgraphCode = "cluster_0" }; g.Nodes.Add(n); g.AutoTune(); Assert.False(g.Nodes.Contains(n)); Assert.True(n.Parent != g); Console.WriteLine(GraphRender.Render(g)); }
/// <summary> /// Выполнение цели /// </summary> /// <param name="context"></param> public override void Execute(IBSharpContext context) { Project.Log.Info("Start GenerateClassGraphTask"); var graph = BuildGraph(context); var dot = GraphRender.Create(graph).GenerateGraphScript(); var dotfile = Path.Combine(Project.GetOutputDirectory(), "project.dot"); File.WriteAllText(dotfile, dot); var dotr = new DotGraphProvider(); var svg = dotr.Generate(dot, new GraphOptions()); var svgfile = Path.Combine(Project.GetOutputDirectory(), "project.svg"); File.WriteAllText(svgfile, (string)svg); Project.Log.Info("Finish GenerateClassGraphTask"); }
public void PushNodesToClusters() { var g = new Graph(); var c = new SubGraph { Code = "cluster_0" }; var n = new Node { Code = "x", SubgraphCode = "cluster_0" }; g.Nodes.Add(n); g.SubGraphs.Add(c); g.AutoTune(); Assert.True(c.Nodes.Contains(n)); Assert.True(n.Parent == c); Console.WriteLine(GraphRender.Render(g)); }
public void CorrectClusterCodes() { var g = new Graph(); var n = new Node { Code = "x", SubgraphCode = "0" }; var n2 = new Node { Code = "y", SubgraphCode = "cluster_0" }; g.Nodes.Add(n); g.Nodes.Add(n2); g.AutoTune(); Assert.False(g.Nodes.Contains(n)); Assert.True(n.Parent != g); Assert.AreEqual("cluster_0", n.Parent.Code); Assert.AreEqual(n2.Parent.Code, n.Parent.Code); Console.WriteLine(GraphRender.Render(g)); }
/// <summary> /// Формирует скрипт DOT /// </summary> /// <param name="parameters"></param> /// <returns></returns> public string GenerateGraphScript(GraphOptions parameters = null) { return(GraphRender.Create((Graph)BuildGraph(parameters), parameters).GenerateGraphScript()); }