public static PlotResult CalculatePlot(double aspectRatio, DependencyGraph<string> graph, AssemblyFilterPreferences filterPreferences)
        {
            const double widthInches = 100;
            var heightInches = (double)(int)(widthInches / aspectRatio);

            // node [color=lightblue2, style=filled];
            // page=""8.5,11""
            // size=""7.5, 10""
            // ratio=All
            //                widthInches = 75;
            //                heightInches = 100;

            var extraCommands = $"size=\"{widthInches},{heightInches}\"\r\n    center=\"\"\r\n    ratio=All\r\n    node[width=.25,hight=.375,fontsize=12,color=lightblue2,style=filled]";
            var dotCommand = DotCommandBuilder.Generate(graph, filterPreferences, extraCommands);

            // a temp file to store image
            var tempFile = TemporaryFileManager.CreateTemporaryFile();

            // generate dot image
            var dot = new DOTClass();
            dot.ToPNG(dotCommand).Save(tempFile);
            var dotImage = Image.FromFile(tempFile);

            // generate SVG
            var svgXml = dot.ToSvg(dotCommand);

            return new PlotResult { DotCommand = dotCommand, Image = dotImage, SvgXml = svgXml };
        }
Exemplo n.º 2
0
        public FilterForm(AssemblyFilterPreferences filterPreferences)
        {
            _filterPreferences = filterPreferences;

            InitializeComponent();

            // populate tree
            // create any 'parent' nodes first
            foreach (var name in _filterPreferences.GetAllNames())
            {
                var bits = name.Split('.');
                var parent = _tree.Nodes;
                if (bits.Length > 1)
                {
                    for (var i = 0; i < bits.Length - 1; i++)
                    {
                        var bit = bits[i];
                        var bitNode = parent.ContainsKey(bit)
                            ? parent[bit]
                            : parent.Add(bit, bit);
                        parent = bitNode.Nodes;
                    }
                }
            }
            // create leaf nodes
            foreach (var name in _filterPreferences.GetAllNames())
            {
                var bits = name.Split('.');
                var parent = _tree.Nodes;
                for (var i = 0; i < bits.Length - 1; i++)
                    parent = parent[bits[i]].Nodes;
                var leafName = bits[bits.Length - 1];
                TreeNode leafNode;
                if (parent.ContainsKey(leafName))
                {
                    leafNode = parent[leafName].Nodes.Insert(0, leafName, "<exactly>");
                    leafNode.ToolTipText = $"Select's {name} without child namespaces";
                }
                else
                {
                    leafNode = parent.Add(leafName, leafName);
                }
                Debug.Assert(leafNode.Tag == null);
                leafNode.Tag = name;
            }

            // expand, one level deep only
            foreach (TreeNode node in _tree.Nodes)
                node.Expand();

            // select nodes which are included
            foreach (var name in _filterPreferences.GetIncludedNames())
                _tree.CheckNodeByTag(name, TriStateTreeView.CheckState.Checked);
        }
        public string GenerateDotCommand(DependencyGraph<string> graph, AssemblyFilterPreferences filterPreferences, string extraCommands)
        {
            var nodes = graph.GetNodes();

            // TODO can this first loop be replaced with LINQ, maybe with a zip?
            var idsByNameMap = new Dictionary<string, int>();
            var id = 1;
            foreach (var nodeName in nodes)
            {
                idsByNameMap.Add(nodeName, id);
                id++;
            }

            var commandText = new StringBuilder();
            commandText.Append("digraph G {\r\n");

            // handle extra commands
            if (extraCommands.Trim().Length > 0)
            {
                commandText.Append("    ");
                commandText.Append(extraCommands.Trim());
                commandText.Append("\r\n");
            }

            var nodeLabels = new StringBuilder();

            foreach (var dependant in nodes)
            {
                // make sure the dependant should be plotted
                if (!filterPreferences.IncludeInPlot(dependant))
                    continue;

                var dependantId = idsByNameMap[dependant];

                // 1 [label="SampleProject",shape=circle,hight=0.12,width=0.12,fontsize=1];
                nodeLabels.AppendFormat("    {0} [label=\"{1}\"];\r\n", dependantId, dependant);

                foreach (var dependency in graph.GetDependenciesForNode(dependant))
                {
                    var dependencyId = idsByNameMap[dependency];
                    if (!filterPreferences.IncludeInPlot(dependency))
                        continue;
                    commandText.AppendFormat("    {0} -> {1};\r\n", dependantId, dependencyId);
                }
            }

            commandText.Append(nodeLabels.ToString());
            commandText.Append("}");

            return commandText.ToString();
        }
 public static string Generate(DependencyGraph<string> graph, AssemblyFilterPreferences filterPreferences)
 {
     return Generate(graph, filterPreferences, string.Empty);
 }
Exemplo n.º 5
0
        public PlotResult CalculatePlot(double aspectRatio, DependencyGraph <string> graph, AssemblyFilterPreferences filterPreferences)
        {
            const double widthInches  = 100;
            var          heightInches = (double)(int)(widthInches / aspectRatio);

            // node [color=lightblue2, style=filled];
            // page=""8.5,11""
            // size=""7.5, 10""
            // ratio=All
            //                widthInches = 75;
            //                heightInches = 100;

            var extraCommands = string.Format("size=\"{0},{1}\"\r\n    center=\"\"\r\n    ratio=All\r\n    node[width=.25,hight=.375,fontsize=12,color=lightblue2,style=filled]",
                                              widthInches, heightInches);
            var dotCommand = new DotCommandBuilder().GenerateDotCommand(graph, filterPreferences, extraCommands);

            // a temp file to store image
            var tempFile = _tempFileManager.CreateTemporaryFile();

            // generate dot image
            var dot = new DOTClass();

            dot.ToPNG(dotCommand).Save(tempFile);
            var dotImage = Image.FromFile(tempFile);

            // generate SVG
            var svgXml = dot.ToSvg(dotCommand);

            return(new PlotResult {
                DotCommand = dotCommand, Image = dotImage, SvgXml = svgXml
            });
        }
Exemplo n.º 6
0
 public string GenerateDotCommand(DependencyGraph <string> graph, AssemblyFilterPreferences filterPreferences)
 {
     return(GenerateDotCommand(graph, filterPreferences, string.Empty));
 }