Beispiel #1
0
            // returns a list of statements because we may need to declare node attribute statments
            // or other things to describe the WME
            public IEnumerable <Statement> GetStatement()
            {
                List <Statement> statements = new List <Statement>();

                if (IsIdentifier())
                {
                    // add an edge statement
                    EdgeStatement statement = EdgeStatement.EdgeBetweenNodes(ID, value);
                    statement.attributes.Add(new StringAttribute("label", attribute.Replace("-", "_")));
                    statements.Add(statement);
                }
                else
                {
                    // get a new id for the value
                    string newID = getNewID();
                    // make edge statement
                    EdgeStatement statement = EdgeStatement.EdgeBetweenNodes(ID, newID);
                    statement.attributes.Add(new StringAttribute("label", attribute.Replace("-", "_")));
                    statements.Add(statement);
                    // add a node attribute statement to label the child
                    NodeStatement nodeStatement = new NodeStatement(newID);
                    nodeStatement.attributes.Add(new StringAttribute("label", value.Replace("-", "_")));
                    statements.Add(nodeStatement);
                }
                return(statements);
            }
Beispiel #2
0
        private void AddChildren(ref List <IWriteTo> statements, IUIPerson person, IUIPerson partner, NodeStatement point, IEnumerable <IUIPerson> childrenOfCouple)
        {
            childrenOfCouple = childrenOfCouple.Where(x => !x.IsHidden);
            var childrenSubgraphStatements = new List <IWriteTo>();

            foreach (var child in childrenOfCouple)
            {
                var childNodeDict = new Dictionary <Id, Id> {
                    { "label", child.Label }, { "shape", "box" }, { "color", child.IsFemale ? "pink" : "blue" }, { "fillcolor", "white" }, { "style", "filled" }
                }.ToImmutableDictionary();
                var childNode = new NodeStatement(child.Id.ToString(), childNodeDict);

                var childToDotDict = new Dictionary <Id, Id> {
                    { "dir", "none" }
                }.ToImmutableDictionary();
                var childToDotStatement = new EdgeStatement(point.Id.Value, child.Id.ToString(), childToDotDict);

                childrenSubgraphStatements.Add(childNode);

                statements.Add(childToDotStatement);
            }

            var childrenSubgraphStatement = new SubgraphStatement("children" + (person.Id + "z" + partner.Id), childrenSubgraphStatements.ToImmutableList());

            statements.Add(childrenSubgraphStatement);
        }
Beispiel #3
0
 public EdgeStatement(NodeStatement fromNode, NodeStatement targetNode, IEnumerable <IAttribute> attributes = null, Port fromPort = null, Port targetPort = null)
 {
     FromNode   = fromNode;
     TargetNode = targetNode;
     Attributes = attributes;
     FromPort   = fromPort;
     TargetPort = targetPort;
 }
Beispiel #4
0
        private void AddPartner(ref List <IWriteTo> statements, IUIPerson person, NodeStatement personNode, IUIPerson partner)
        {
            if (partner.IsHidden)
            {
                return;
            }

            var edgeDictPoint = new Dictionary <Id, Id> {
                { "shape", "point" }, { "label", "" }
            }.ToImmutableDictionary();
            var point = new NodeStatement("partners" + (partner.Id + "z" + person.Id), edgeDictPoint);

            var partnerNodeDict = new Dictionary <Id, Id> {
                { "label", partner.Label }, { "shape", "box" }, { "color", partner.IsFemale ? "pink" : "blue" }, { "fillcolor", "white" }, { "style", "filled" }
            }.ToImmutableDictionary();
            var partnerNode = new NodeStatement(partner.Id.ToString(), partnerNodeDict);

            var edgeDictLinePersonToPoint = new Dictionary <Id, Id> {
                { "dir", "none" }
            }.ToImmutableDictionary();
            var linePersonToPoint = new EdgeStatement(person.Id.ToString(), point.Id.ToString(), edgeDictLinePersonToPoint);

            var linePartnerToPointDict = new Dictionary <Id, Id> {
                { "dir", "none" }
            }.ToImmutableDictionary();
            var linePartnerToPoint = new EdgeStatement(partner.Id.ToString(), point.Id.ToString(), linePartnerToPointDict);

            var parentSubgraphExists = statements.Where(x => x is SubgraphStatement).Select(y => ((SubgraphStatement)y).Name).Any(z => z.Value == "partners" + (partner.Id + "z" + person.Id) || z.Value == "partners" + (person.Id + "z" + partner.Id));

            if (!parentSubgraphExists)
            {
                var parentSubgraphStatements = new List <IWriteTo>();

                parentSubgraphStatements.Add(point);

                parentSubgraphStatements.Add(partnerNode);

                parentSubgraphStatements.Add(personNode);

                parentSubgraphStatements.Add(linePersonToPoint);

                parentSubgraphStatements.Add(linePartnerToPoint);

                var parentSubgraphStatement = new SubgraphStatement(point.Id.ToString(), parentSubgraphStatements.ToImmutableList());
                statements.Add(parentSubgraphStatement);

                var childrenSubgraphExists = statements.Where(x => x is SubgraphStatement).Select(y => ((SubgraphStatement)y).Name).Any(z => z.Value == "children" + (partner.Id + "z" + person.Id) || z.Value == "children" + (person.Id + "z" + partner.Id));
                if (!childrenSubgraphExists)
                {
                    var childrenOfCouple = person.Children.Where(x => x.Parents.Contains(partner) && x.Parents.Contains(person)).Where(x => !x.IsHidden);
                    childrenOfCouple = childrenOfCouple.OrderByDescending(x => x.GetAllDescendants().Count);
                    this.AddChildren(ref statements, person, partner, point, childrenOfCouple);
                }
            }
        }
Beispiel #5
0
        private static void DefineNode(ref List <Statement> statements, int nodeId, string title, string comment, Color nodeColor, Color textColor, bool outerBold, ushort maxLineLength)
        {
            Dictionary <Id, Id> nodeStyleSettings = null;
            Dictionary <Id, Id> nodeLabelSettings = null;

            nodeStyleSettings = new Dictionary <Id, Id>();
            //nodeStyleSettings.Add(new Id("color"), new Id("black"));

            nodeStyleSettings.Add(new Id("fillcolor"), new Id(Enum.GetName(typeof(Color), nodeColor)));

            nodeStyleSettings.Add(new Id("fontcolor"), new Id(Enum.GetName(typeof(Color), textColor)));

            if (outerBold)
            {
                nodeStyleSettings.Add(new Id("color"), new Id("red"));
                nodeStyleSettings.Add(new Id("penwidth"), new Id("2"));
            }

            nodeLabelSettings = new Dictionary <Id, Id>();


            title = string.Concat(title.Split(badChars, StringSplitOptions.RemoveEmptyEntries));
            if (string.IsNullOrWhiteSpace(comment))
            {
                nodeStyleSettings.Add(new Id("label"), new Id("{ " + Convert.ToString(nodeId) + " | " + GraphVizHelper.SplitInLines(title, maxLineLength) + "}"));
            }
            else
            {
                //nodeStyleSettings.Add(new Id("label"), new Id(Convert.ToString(nodeId) + " | { " + GraphVizHelper.SplitInLines(title, maxLineLength) + " | " + comment + " } "));
                nodeStyleSettings.Add(new Id("label"), new Id("{" + Convert.ToString(nodeId) + "| { " + GraphVizHelper.SplitInLines(title, maxLineLength) + " | " + comment + " } }"));

                //{ struct14 |{[CheckPoint] OSAL 2 - Date/Time and Reboot/Shutdown and USB\n management And Network management| Sprint 89 }}
                //struct12 |{ [CheckPoint] OSAL 2 - Date/Time and Reboot/Shutdown and USB\n management And Network management | Sprint 89 }
            }
            // nodeStyleSettings.Add(new Id("label"), new Id(@"two\nlines\nMore long lines\ncheck how this looks like")); FUNCIONA...
            //nodeStyleSettings.Add(new Id("label"), new Id("{<<TABLE>< TR >< TD > AAAA </ TD ></ TR >< TR >< TD > caption </ TD ></ TR ></ TABLE >>}")); NO FUNCIONA

            /*
             * <<TABLE>
             * <TR><TD>AAAA</TD></TR>
             * <TR><TD>caption</TD></TR>
             * </TABLE>>
             */

            var node = new NodeStatement(new Id(Convert.ToString(nodeId)), nodeStyleSettings.ToImmutableDictionary());

            statements.Add(node);
        }
Beispiel #6
0
        private NodeStatement CreateNode(SyntaxNode node)
        {
            var id = new NodeId(_nodeIndex.ToString());

            _idsDict.Add(node, id);
            var n = NodeStatement.For(id.Id).Set("label", node.Label);

            if (node.Shape == NodeShape.Square)
            {
                n = n.Set("shape", "box");
            }
            if (node.ChildNodes.TrueForAll(child => child.Sibling == null)) // If the children has no siblings, make the output edges drawn in order
            {
                n = n.Set("ordering", "out");
            }


            _nodeIndex++;
            return(n);
        }
Beispiel #7
0
        public async Task WriteFile(IEnumerable <IUIPerson> persons, string filename, RendererFormats renderFormat, bool transparent = true)
        {
            persons = persons.Where(x => !x.IsHidden).ToList();
            persons = persons.OrderByDescending(x => x.Parents.Count);

            List <IWriteTo> statements = new List <IWriteTo>();

            foreach (var person in persons)
            {
                var personNodeDict = new Dictionary <Id, Id> {
                    { "label", person.Label }, { "shape", "box" }, { "color", person.IsFemale ? "pink" : "blue" }, { "fillcolor", "white" }, { "style", "filled" }
                }.ToImmutableDictionary();
                var personNode = new NodeStatement(person.Id.ToString(), personNodeDict);

                var partners = person.Partners.Where(x => !x.IsHidden);
                partners = partners.OrderByDescending(x => x.Parents.Count);
                foreach (var partner in partners)
                {
                    this.AddPartner(ref statements, person, personNode, partner);
                }

                if (IsSingleParent(person, partners))
                {
                    this.AddChildren(ref statements, person, personNode, person.Children);
                }
            }

            var statementsImmutable = statements.ToImmutableList <IWriteTo>();
            var graph = new Graph(GraphKinds.Directed, "genealogy", statementsImmutable);

            graph = graph.Add(AttributeStatement.Graph.Set("rankdir", "TB"));
            graph = graph.Add(AttributeStatement.Graph.Set("nodesep", "0.5"));
            graph = graph.Add(AttributeStatement.Graph.Set("splines", "false"));

            if (transparent)
            {
                graph = graph.Add(AttributeStatement.Graph.Set("bgcolor", "transparent"));
            }

            await this.Render(graph, filename, renderFormat);
        }
 internal void visit(NodeStatement nodeStatement)
 {
     throw new NotImplementedException();
 }