Skip to content

Commit 237ccf0

Browse files
committed
refactor: remove unused UnflattenGraph method and related logic in DependencyGraphGenerator
1 parent a7ce1dd commit 237ccf0

File tree

2 files changed

+1
-97
lines changed

2 files changed

+1
-97
lines changed

CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CodeLineCounter.Models;
22
using CodeLineCounter.Services;
3+
using DotNetGraph.Attributes;
34
using DotNetGraph.Core;
45
using DotNetGraph.Extensions;
56
using Microsoft.CodeAnalysis.CSharp.Syntax;

CodeLineCounter/Services/DependencyGraphGenerator.cs

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,102 +18,7 @@ public class GraphvizUnflattenOptions
1818

1919
public static class DependencyGraphGenerator
2020
{
21-
public static void UnflattenGraph(DotGraph graph, GraphvizUnflattenOptions options)
22-
{
23-
var nodeDegrees = new Dictionary<string, int>();
24-
25-
DotNode? chainNode = null;
26-
int chainSize = 0;
27-
28-
// Extraire les arêtes du graphe
29-
List<DotEdge> edges;
30-
List<DotNode> nodes;
31-
ExtractNodesAndEdges(graph, out edges, out nodes);
32-
33-
// Calculer le degré de chaque nœud
34-
CalculateDegrees(nodeDegrees, edges, nodes);
35-
36-
// Traiter les nœuds du graphe
37-
foreach (var node in nodes)
38-
{
39-
DotIdentifier nodeId = node.Identifier;
40-
int degree = nodeDegrees[nodeId.Value];
41-
42-
if (degree == 0 && options.ChainLimit >= 1)
43-
{
44-
AddEdgeAndStyleToUnflatten(graph, options, ref chainNode, ref chainSize, node, nodeId);
45-
}
46-
else if (degree > 1 && options.MaxMinlen >= 1)
47-
{
48-
SetMinLenAttributeWhenUnflatting(options, edges, nodeId);
49-
}
50-
}
51-
}
52-
53-
private static void AddEdgeAndStyleToUnflatten(DotGraph graph, GraphvizUnflattenOptions options, ref DotNode? chainNode, ref int chainSize, DotNode node, DotIdentifier nodeId)
54-
{
55-
if (chainNode != null)
56-
{
57-
var edge = new DotEdge { From = chainNode.Identifier, To = nodeId, Style = DotEdgeStyle.Invis };
58-
graph.Elements.Add(edge);
59-
chainSize++;
60-
61-
if (chainSize < options.ChainLimit)
62-
chainNode = node;
63-
else
64-
{
65-
chainNode = null;
66-
chainSize = 0;
67-
}
68-
}
69-
else
70-
{
71-
chainNode = node;
72-
}
73-
}
74-
75-
private static void SetMinLenAttributeWhenUnflatting(GraphvizUnflattenOptions options, List<DotEdge> edges, DotIdentifier nodeId)
76-
{
77-
int cnt = 0;
78-
foreach (var edge in edges)
79-
{
80-
if (edge.To == nodeId && IsLeaf(edges, edge.From.Value))
81-
{
82-
DotAttribute minLen = edge.GetAttribute<DotAttribute>("minlen");
83-
minLen.Value = (cnt % options.MaxMinlen + 1).ToString();
84-
edge.SetAttribute("minLen", minLen);
85-
cnt++;
86-
}
87-
}
88-
}
8921

90-
private static void CalculateDegrees(Dictionary<string, int> nodeDegrees, List<DotEdge> edges, List<DotNode> nodes)
91-
{
92-
foreach (var nodeId in nodes.Select(node => node.Identifier.Value))
93-
{
94-
int degree = GetNodeDegree(edges, nodeId);
95-
nodeDegrees[nodeId] = degree;
96-
}
97-
}
98-
99-
private static void ExtractNodesAndEdges(DotGraph graph, out List<DotEdge> edges, out List<DotNode> nodes)
100-
{
101-
edges = graph.Elements.OfType<DotEdge>().ToList();
102-
nodes = graph.Elements.OfType<DotNode>().ToList();
103-
var subgraphes = graph.Elements.OfType<DotSubgraph>().ToList();
104-
edges.AddRange(subgraphes.SelectMany(s => s.Elements.OfType<DotEdge>()));
105-
nodes.AddRange(subgraphes.SelectMany(s => s.Elements.OfType<DotNode>()));
106-
}
107-
108-
private static int GetNodeDegree(List<DotEdge> edges, string nodeId)
109-
{
110-
return edges.Count(e => e.From.ToString() == nodeId || e.To.ToString() == nodeId);
111-
}
112-
113-
private static bool IsLeaf(List<DotEdge> edges, string nodeId)
114-
{
115-
return !edges.Any(e => e.From.ToString() == nodeId);
116-
}
11722
private static readonly RecyclableMemoryStreamManager MemoryStreamManager = new RecyclableMemoryStreamManager();
11823
public static DotGraph GenerateGraphOnly(List<DependencyRelation> dependencies, string? filterNamespace = null, string? filterAssembly = null)
11924
{
@@ -135,8 +40,6 @@ public static DotGraph GenerateGraphOnly(List<DependencyRelation> dependencies,
13540
// Add edges
13641
AddEdgesBetweenDependencies(filteredDependencies, graph);
13742

138-
UnflattenGraph(graph, new GraphvizUnflattenOptions { ChainLimit = 10, MaxMinlen = 10, DoFans = false });
139-
14043
return graph;
14144
}
14245

0 commit comments

Comments
 (0)