Exemple #1
0
        public AsmdefGraphView(IEnumerable <AsmdefDependency> asmdefs) : base()
        {
            _dependencies = asmdefs.ToArray();
            // zoom可能に
            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            // 背景を黒に
            Insert(0, new GridBackground());
            // ドラッグによる移動可能に
            this.AddManipulator(new SelectionDragger());
            // ノードの追加
            asmdefNodeDict = new Dictionary <string, AsmdefNode>();
            foreach (var asmdef in asmdefs)
            {
                var node = new AsmdefNode(asmdef.DependsFrom);
                AddElement(node);
                asmdefNodeDict.Add(node.title, node);
            }

            // 依存先にラインを追加
            foreach (var asmdef in asmdefs)
            {
                if (!asmdefNodeDict.TryGetValue(asmdef.DependsFrom, out var fromNode))
                {
                    continue;
                }

                foreach (var dependents in asmdef.DependsTo)
                {
                    if (!asmdefNodeDict.TryGetValue(dependents, out var toNode))
                    {
                        continue;
                    }

                    var edge = fromNode.RightPort.ConnectTo(toNode.LeftPort);
                    contentContainer.Add(edge); // これが無いと線が表示されない
                }
            }
        }
        public AsmdefGraphView(IEnumerable <Assembly> assemblies)
        {
            var assemblyArr = assemblies.ToArray();

            // zoom可能に
            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            // 背景を黒に
            Insert(0, new GridBackground());
            // ドラッグによる移動可能に
            this.AddManipulator(new SelectionDragger());
            // ドラッグで描画範囲を動かせるように
            this.AddManipulator(new ContentDragger());
            // ノードの追加
            asmdefNodeDict = new Dictionary <string, IAsmdefNodeView>();
            foreach (var asm in assemblyArr)
            {
                var node = new AsmdefNode(asm.name, contentContainer);
                AddElement(node);
                asmdefNodeDict.Add(node.title, node);
            }
            // 依存の整理
            var nodeProfiles = assemblyArr
                               .Select((x, i) => new NodeProfile(new NodeId(i), x.name))
                               .ToDictionary(x => x.Name);
            var dependencies = new List <IDependencyNode>(nodeProfiles.Count);

            // 依存先の設定
            foreach (var asm in assemblyArr)
            {
                if (nodeProfiles.TryGetValue(asm.name, out var profile))
                {
                    var requireProfiles = asm.assemblyReferences
                                          .Where(x => nodeProfiles.ContainsKey(x.name))
                                          .Select(x => nodeProfiles[x.name]);
                    var dep = new HashSetDependencyNode(profile);
                    dep.SetRequireNodes(requireProfiles);
                    dependencies.Add(dep);
                }
            }
            // 依存元の設定
            NodeProcessor.SetBeRequiredNodes(dependencies);

            // 依存先にのみラインを追加
            foreach (var dep in dependencies)
            {
                if (!asmdefNodeDict.TryGetValue(dep.Profile.Name, out var fromNode))
                {
                    continue;
                }
                foreach (var dest in dep.Destinations)
                {
                    if (!asmdefNodeDict.TryGetValue(dest.Name, out var toNode))
                    {
                        continue;
                    }
                    fromNode.RightPort.Connect(toNode.LeftPort);
                }
            }

            // Portに接続数を追記
            foreach (var dep in dependencies)
            {
                if (asmdefNodeDict.TryGetValue(dep.Profile.Name, out var node))
                {
                    node.LeftPort.Label  = $"RefBy({dep.Sources.Count})";
                    node.RightPort.Label = $"RefTo({dep.Destinations.Count})";
                }
            }

            // ノードの場所を整列
            var sortStrategy = new AlignSortStrategy(AlignParam.Default(), Vector2.zero);
            var sortedNode   = sortStrategy.Sort(dependencies);

            foreach (var node in sortedNode)
            {
                if (asmdefNodeDict.TryGetValue(node.Profile.Name, out var nodeView))
                {
                    nodeView.SetPositionXY(node.Position);
                }
            }
        }