コード例 #1
0
        private void ProcessNodeConnections(GraphvizTableRow row, GraphvizNode node)
        {
            if (ConnIndex <= 0)
            {
                return;
            }

            string connections = row[ConnIndex].Value;

            if (string.IsNullOrEmpty(connections))
            {
                return;
            }

            var nodes = connections.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var n in nodes)
            {
                string dest = n.Trim();
                if (!string.IsNullOrEmpty(dest))
                {
                    AddEdgeIfNotExist(node.Name, dest, GraphvizEdge.EdgeDir.Normal);
                }
            }
        }
コード例 #2
0
        private void ProcessNode(GraphvizTableRow row)
        {
            GraphvizNode node = AddNodeIfNotExist(row[0].Value);

            ProcessNodeAttributes(row, node);
            ProcessNodeConnections(row, node);
        }
コード例 #3
0
 public void Add(GraphvizTableRow row)
 {
     if (row != null)
     {
         Rows.Add(row);
     }
 }
コード例 #4
0
        private void ProcessEdge(GraphvizTableRow row)
        {
            string edges = row[0].Value;

            GraphvizEdge.EdgeDir dir = ToDir(edges);
            var nodes = edges.Split(new string[] { "<->", "->", "--" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < nodes.Length - 1; i++)
            {
                string from = nodes[i].Trim();
                string to   = nodes[i + 1].Trim();
                if (!string.IsNullOrEmpty(from) && !string.IsNullOrEmpty(to))
                {
                    GraphvizEdge edge = AddEdgeIfNotExist(from, to, dir);
                    ProcessEdgeAttributes(row, edge);
                }
            }
        }
コード例 #5
0
        private static GraphvizTableRow ToRow(string tableRow)
        {
            GraphvizTableRow row = new GraphvizTableRow();

            if (!IsTableRow(tableRow))
            {
                return(row);
            }

            var cells = tableRow.Split('|');

            for (int i = 1; i < cells.Length - 1; i++)
            {
                // create cells except first and last empty string
                row.Add(new GraphvizTableCell(cells[i].Trim()));
            }

            return(row);
        }
コード例 #6
0
        private void ProcessEdgeAttributes(GraphvizTableRow row, GraphvizEdge edge)
        {
            if (LabelIndex >= 0)
            {
                string label = row[LabelIndex]?.Value;
                edge.Label = label?.Trim();
            }

            if (ColorIndex >= 0)
            {
                string color = row[ColorIndex]?.Value;
                edge.Color = color?.Trim();
            }

            if (ShapeIndex >= 0)
            {
                string shape = row[ShapeIndex]?.Value;
                edge.ArrowHead = shape?.Trim();
            }
        }
コード例 #7
0
        private void ProcessNodeAttributes(GraphvizTableRow row, GraphvizNode node)
        {
            if (LabelIndex >= 0)
            {
                string label = row[LabelIndex]?.Value;
                node.Label = label?.Trim();
            }

            if (ShapeIndex >= 0)
            {
                string shape = row[ShapeIndex]?.Value;
                node.Shape = shape?.Trim();
            }

            if (ColorIndex >= 0)
            {
                string color = row[ColorIndex]?.Value;
                node.FillColor = color?.Trim();
            }
        }
コード例 #8
0
        private string MakeGraphvizDotContent(GraphvizTable table)
        {
            if ((table == null) || (table.RowCount < 2))
            {
                return(null);
            }

            GraphvizTableRow header = table[0];

            ShapeIndex = header.Index("Shape");
            LabelIndex = header.Index("Label");
            ConnIndex  = header.Index("Connections");
            ColorIndex = header.Index("Color");
            for (int i = 1; i < table.RowCount; i++)
            {
                GraphvizTableRow row    = table[i];
                bool?            isNode = row[0].IsDotNode();
                if (!isNode.HasValue)
                {
                    return(null);
                }

                if (isNode.Value)
                {
                    if (row[0].Value.Contains(":"))
                    {
                        DotModel.Add(new GraphvizRankNode(row[0].Value));
                    }
                    else
                    {
                        ProcessNode(row);
                    }
                }
                else
                {
                    ProcessEdge(row);
                }
            }

            return(DotModel.GetDotString());
        }