Exemplo n.º 1
0
        public static ElementSourceDictionary Populate <TNodeSource, TChildNodeSource>(this
                                                                                       DirectedGraph graph,
                                                                                       IEnumerable <TNodeSource> nodes,
                                                                                       Func <TNodeSource, IEnumerable <TChildNodeSource> > linkedNodesFunction,
                                                                                       Func <TNodeSource, String> NodeUID,
                                                                                       Func <TNodeSource, String> NodeLabel,
                                                                                       Func <TChildNodeSource, String> ChildNodeUID,
                                                                                       Func <TChildNodeSource, String> ChildNodeLabel,
                                                                                       Boolean setProperties = true,
                                                                                       Boolean useFormatting = true)
        {
            ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary();

            foreach (TNodeSource node in nodes)
            {
                Node nodeA = graph.Nodes.AddOrGet(NodeUID(node), NodeLabel(node));
                ElementToSourceObject[nodeA].Add(node);

                graph.DeployPropertiesAndFormatting(nodeA, node, setProperties, useFormatting);

                // nodeA.DeployColor(node, NodeColor)

                var child_nodes = linkedNodesFunction(node);

                foreach (TChildNodeSource child in child_nodes)
                {
                    Node nodeB = graph.Nodes.AddOrGet(ChildNodeUID(child), ChildNodeLabel(child));

                    ElementToSourceObject[nodeB].Add(child);

                    graph.DeployPropertiesAndFormatting(nodeB, child, setProperties, useFormatting);

                    Link linkAK = graph.Links.AddOrGetLink(NodeUID(node), ChildNodeUID(child));


                    ElementToSourceObject[linkAK].Add(node);
                    ElementToSourceObject[linkAK].Add(child);
                }
            }
            if (graph is DirectedGraphWithSourceData graphWithData)
            {
                graphWithData.Sources.AddRange(ElementToSourceObject, true);
            }
            return(ElementToSourceObject);
        }
Exemplo n.º 2
0
        public static ListDictionary <GraphElement, Object> Link <TNodeASource, TNodeBSource>(this
                                                                                              DirectedGraph graph,
                                                                                              IEnumerable <TNodeASource> nodesA,
                                                                                              Func <TNodeASource, String> NodeAUID,
                                                                                              Func <TNodeASource, String> NodeALabel,
                                                                                              IEnumerable <TNodeBSource> nodesB,
                                                                                              Func <TNodeBSource, String> NodeBUID,
                                                                                              Func <TNodeBSource, String> NodeBLabel,
                                                                                              Func <TNodeASource, TNodeBSource, String> LinkABLabel,
                                                                                              Boolean setProperties = true,
                                                                                              Boolean useFormatting = true)
        {
            var nodeAIndex = nodesA.ToList();
            var nodeBIndex = nodesB.ToList();
            ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary();

            for (int i = 0; i < Math.Min(nodeAIndex.Count, nodeBIndex.Count); i++)
            {
                Node nodeA = graph.Nodes.AddOrGet(NodeAUID(nodeAIndex[i]), NodeALabel(nodeAIndex[i]));
                Node nodeB = graph.Nodes.AddOrGet(NodeBUID(nodeBIndex[i]), NodeBLabel(nodeBIndex[i]));

                graph.DeployPropertiesAndFormatting(nodeA, nodeAIndex[i], setProperties, useFormatting);
                graph.DeployPropertiesAndFormatting(nodeB, nodeBIndex[i], setProperties, useFormatting);

                ElementToSourceObject[nodeA].Add(nodeAIndex[i]);
                ElementToSourceObject[nodeB].Add(nodeBIndex[i]);

                Link linkAK = graph.Links.AddOrGetLink(NodeAUID(nodeAIndex[i]), NodeBUID(nodeBIndex[i]));
                linkAK.Label = LinkABLabel(nodeAIndex[i], nodeBIndex[i]);

                ElementToSourceObject[linkAK].Add(nodeAIndex[i]);
                ElementToSourceObject[linkAK].Add(nodeBIndex[i]);
            }



            if (graph is DirectedGraphWithSourceData graphWithData)
            {
                graphWithData.Sources.AddRange(ElementToSourceObject, true);
            }
            return(ElementToSourceObject);
        }