/// <summary> /// Формирует программу на языке DOT /// </summary> /// <param name="subGraph"></param> /// <returns></returns> public string Generate(SubGraph subGraph) { Graph g; if (subGraph is Graph) { g =(Graph) subGraph; } else { g = new Graph(); g.AddSubGraph(subGraph); } return GraphRender.Create(g).GenerateGraphScript(); }
/// <summary> /// Формирует программу на языке DOT /// </summary> /// <param name="subGraph"></param> /// <returns></returns> public string Generate(SubGraph subGraph) { Graph g; if (subGraph is Graph) { g = (Graph)subGraph; } else { g = new Graph(); g.AddSubGraph(subGraph); } return(GraphRender.Create(g).GenerateGraphScript()); }
private void WriteGraphBody(SubGraph g) { WriteGraphAttributes(g); WriteDefaultNode(g); WriteDefaultEdge(g); foreach (var n in g.Nodes) { WriteNode(n); } foreach (var sg in g.SubGraphs) { WriteSubgraph(sg); } foreach (var edge in g.Edges) { WriteEdge(edge); } }
/// <summary> /// Перемещает узлы по подграфам /// </summary> public void MoveNodesToSubgraphs() { foreach (var n in Nodes.ToArray()) { if (!string.IsNullOrWhiteSpace(n.SubgraphCode)) { var sg = ResolveSubgraph(n.SubgraphCode); if (null == sg) { sg = new SubGraph { Code = n.SubgraphCode, Parent = this }; SubGraphs.Add(sg); } sg.Nodes.Add(n); n.Parent = sg; Nodes.Remove(n); } } }
/// <summary> /// /// </summary> /// <param name="subgraph"></param> public SubGraph AddSubGraph(SubGraph subgraph) { var existed = ResolveSubgraph(subgraph.Code); if (null != existed) { existed.Merge(subgraph); } else { existed = new SubGraph {Code = subgraph.Code}; existed.Merge(subgraph); } foreach (var n in subgraph.Nodes) { AddNode(n); } foreach (var e in subgraph.Edges) { AddEdge(e); } foreach (var s in subgraph.SubGraphs) { existed.AddSubGraph(s); } return existed; }
private void CheckoutNamespace(Graph graph, string ns) { if (string.IsNullOrWhiteSpace(ns)) return; var parts = ns.Split('.'); var fullns = ""; SubGraph parent = graph; foreach (var p in parts) { fullns += p + "__"; SubGraph ex = null; if (null == (ex=parent.ResolveSubgraph(fullns))) { parent.SubGraphs.Add((ex=new SubGraph{Code = fullns,Label = p})); } parent = ex; } }
/// <summary> /// Перемещает узлы по подграфам /// </summary> public void MoveNodesToSubgraphs() { foreach (var n in Nodes.ToArray()) { if (!string.IsNullOrWhiteSpace(n.SubgraphCode)) { var sg = ResolveSubgraph(n.SubgraphCode); if (null == sg) { sg = new SubGraph {Code = n.SubgraphCode, Parent = this}; SubGraphs.Add(sg); } sg.Nodes.Add(n); n.Parent = sg; Nodes.Remove(n); } } }
private void WriteSubgraph(SubGraph sg) { OpenSubgraph(sg); WriteGraphBody(sg); CloseSubgraph(); }