///// <summary>
        ///// Initializes a new instance of the <see cref="freeGraphAdapter{TNode}"/> class.
        ///// </summary>
        ///// <param name="_mainPrefix">The main prefix.</param>
        ///// <param name="prefixes">The prefixes.</param>
        //public freeGraphAdapter(String _mainPrefix, String[] prefixes)
        //{
        //    Deploy(new freeGraph(), null, _mainPrefix, prefixes);
        //}

        private void Deploy(freeGraph _graph, freeGraphTypedNodesRegister _source, String _mainPrefix, String[] prefixes)
        {
            graph = _graph;
            Int32 c = 0;

            mainPrefix = _mainPrefix.or("OBJ_");

            source = _source;
            if (source == null)
            {
                source = new freeGraphTypedNodesRegister();
            }

            if (prefixes == null)
            {
                return;
            }
            typePrefixes.Add(c, mainPrefix);

            c++;
            foreach (String p in prefixes)
            {
                typePrefixes.Add(c, p);
                c++;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="depthLimit">The depth limit.</param>
        /// <returns></returns>
        public override freeGraph Convert(T source, Int32 depthLimit = 500, IEnumerable <T> rootNodes = null)
        {
            freeGraph output = new freeGraph();

            output.DisableCheck = true;
            output.Id           = source.name;
            output.description  = "FreeGraph built from " + source.GetType().Name + ":GraphNodeBase graph";

            var nodes = source.getAllChildren(null, false, false, 1, depthLimit, true);

            Dictionary <T, freeGraphNodeBase> nodeDict = new Dictionary <T, freeGraphNodeBase>();

            foreach (var ch in nodes)
            {
                T   child = (T)ch;
                var node  = output.AddNewNode(GetNodeName(child), GetNodeWeight(child), GetNodeType(child));
                nodeDict.Add(child, node);
            }

            foreach (var ch in nodes)
            {
                if (ch.parent != null)
                {
                    T parent = (T)ch.parent;
                    T child  = (T)ch;
                    if ((parent != null) && (child != null))
                    {
                        freeGraphNodeBase gParent = nodeDict[parent];
                        freeGraphNodeBase gChild  = nodeDict[child];
                        var lnk = output.AddLink(gParent.name, gChild.name, GetLinkWeight(parent, child), GetLinkType(parent, child));
                        lnk.linkLabel = GetLinkLabel(parent, child);
                    }
                }
            }
            output.DisableCheck = false;
            output.RebuildIndex();
            return(output);
        }
Beispiel #3
0
        public override T Convert(freeGraph source, int depthLimit = 500, IEnumerable <freeGraphNodeBase> rootNodes = null)
        {
            T output = new T();

            output.name = source.Id;

            if (!source.Any())
            {
                return(output);
            }

            List <T>      nodes     = new List <T>();
            List <String> nodeNames = new List <string>();

            Dictionary <T, freeGraphNodeBase> next = new Dictionary <T, freeGraphNodeBase>();

            Boolean run = true;

            foreach (var io in rootNodes)
            {
                var tmp = new T();
                tmp.name = io.name;

                next.Add(tmp, io);
                output.Add(tmp);
            }

            //List<Node> next = new List<Node>();

            // next.AddRange(rootNodes.ConvertList<IObjectWithName,Node>());

            Int32 i = 0;

            while (run)
            {
                Dictionary <T, freeGraphNodeBase> newnext = new Dictionary <T, freeGraphNodeBase>();
                // List<T> newT = new ListItemType<();

                foreach (var pair in next)
                {
                    T tNode = new T();

                    tNode.name = pair.Value.name; // g.Id;

                    foreach (var ln in source.GetLinkedNodes(pair.Value.name, false))
                    {
                        if (!nodeNames.Contains(ln.name))
                        {
                            var tmp = new T();
                            tmp.name = ln.name;

                            newnext.Add(tmp, ln);
                            pair.Key.Add(tmp);
                        }
                        nodeNames.Add(ln.name);
                    }
                }
                i++;
                if (i > depthLimit)
                {
                    run = false;
                    break;
                }
                next = newnext;
                run  = next.Any();
            }

            return(output);
        }
Beispiel #4
0
 /// <summary>
 /// Converts to free graph -- from the specified node to its leafs (downwards)
 /// </summary>
 /// <param name="graph">The graph.</param>
 /// <param name="DepthLimit">The depth limit.</param>
 /// <returns></returns>
 public static DirectedGraph ConvertToDGML(this freeGraph graph)
 {
     return(GraphConversionTools.DefaultDMGLConverter.ConvertToDMGL(graph));
 }
        //public freeGraphLinkBase AddLink(IObjectWithNameWeightAndType NodeA, IObjectWithNameWeightAndType NodeB, Double w = 1, Int32 type = 0, operation onWeight = operation.assign, operation onType = operation.assign)
        //{

        //}

        //public List<freeGraphLinkBase> AddLinks(IObjectWithNameWeightAndType NodeA, IEnumerable<IObjectWithNameWeightAndType> NodeBs, Double w = 1, Int32 type = 0, operation onWeight = operation.assign, operation onType = operation.assign)
        //{

        //}

        /// <summary>
        /// Initializes a new instance of the <see cref="freeGraphAdapter{TNodeA}" /> class, attaches the graph and assigns prefixes for IDs of nodes, according to type number
        /// </summary>
        /// <param name="_graph">The graph.</param>
        /// <param name="_source">Source collection.</param>
        /// <param name="_mainPrefix">Main prefix for this type</param>
        /// <param name="prefixes">Prefixes for types</param>
        public freeGraphAdapter(freeGraph _graph, freeGraphTypedNodesRegister _source, String _mainPrefix, String[] prefixes)
        {
            Deploy(_graph, _source, _mainPrefix, prefixes);
        }
Beispiel #6
0
        public DirectedGraph ConvertToDMGL(freeGraph input)
        {
            DirectedGraph output = new DirectedGraph();

            output.Title = input.Id;

            // input.InverseWeights(false, true);

            nodeStyler = new NodeWeightStylerCategories(setup.NodeGradient, setup);
            linkStyler = new NodeWeightStylerCategories(setup.LinkGradient, setup);

            foreach (freeGraphNodeBase node in input.nodes)
            {
                try
                {
                    if (node != null)
                    {
                        var c = Categories.AddOrGetCategory(node.type.ToString(), "", "");
                        output.Categories.AddUnique(c);
                        nodeStyler.learn(node.type, node.weight);
                    }
                }
                catch (Exception ex)
                {
                    output.ConversionErrors.Add("Node learning-conversion: " + ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }

            foreach (var link in input.links)
            {
                try
                {
                    if (link != null)
                    {
                        var c = Categories.AddOrGetCategory(link.type.ToString(), "", "");
                        output.Categories.AddUnique(c);
                        linkStyler.learn(link.type, link.weight);
                    }
                }
                catch (Exception ex)
                {
                    output.ConversionErrors.Add("link learning-conversion: " + ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }

            foreach (freeGraphNodeBase node in input.nodes)
            {
                try
                {
                    if (node != null)
                    {
                        var nd = output.Nodes.AddNode(node.name);

                        nd.Category        = output.Categories[node.type].Id;
                        nd.Background      = nodeStyler.GetHexColor(node.weight, node.type);
                        nd.StrokeThinkness = nodeStyler.GetBorderThickness(node.weight, node.type);
                        nd.Stroke          = nodeStyler.GetHexColor(1, node.type);
                        nd.Label           = nd.Label + " (" + node.weight.ToString(setup.NodeWeightFormat) + ")";
                        if (setup.doAddNodeTypeToLabel)
                        {
                            nd.Label = nd.Label + " [" + node.type + "]";
                        }
                    }
                }
                catch (Exception ex)
                {
                    output.ConversionErrors.Add("Node conversion: " + ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }

            foreach (var link in input.links)
            {
                try
                {
                    if (link != null)
                    {
                        var nodeA = input.GetNode(link.nodeNameA);
                        var nodeB = input.GetNode(link.nodeNameB);

                        var lnk = new Link(link.nodeNameA, link.nodeNameB, false);

                        if (setup.doLinkDirectionFromLowerTypeToHigher)
                        {
                            if (nodeB.type < nodeA.type)
                            {
                                lnk = new Link(link.nodeNameB, link.nodeNameA, false);
                            }
                        }

                        if (setup.doAddLinkWeightInTheLabel)
                        {
                            lnk.Label = lnk.Label.add(link.weight.ToString(setup.LinkWeightFormat));
                        }
                        else
                        {
                            lnk.Label = link.linkLabel;
                        }

                        lnk.Category        = output.Categories[link.type].Id;
                        lnk.Stroke          = linkStyler.GetHexColor(link.weight, link.type);
                        lnk.StrokeThinkness = linkStyler.GetBorderThickness(link.weight, link.type);
                        output.Links.Add(lnk);
                    }
                }
                catch (Exception ex)
                {
                    output.ConversionErrors.Add("Link conversion: " + ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }

            output.Layout         = DGML.enums.GraphLayoutEnum.ForceDirected;
            output.GraphDirection = DGML.enums.GraphDirectionEnum.Sugiyama;

            return(output);
        }