summarize method
Builds a high-level summary for the full dependency graph.
Implementation
GraphSummary summarize(Map<String, DependencyNode> nodes) {
final Map<String, DependencyGraphMetrics> metrics = analyze(nodes);
final List<MapEntry<String, DependencyGraphMetrics>> ordered =
metrics.entries.toList()
..sort((MapEntry<String, DependencyGraphMetrics> a,
MapEntry<String, DependencyGraphMetrics> b) {
final int byDependents =
b.value.directDependents.compareTo(a.value.directDependents);
if (byDependents != 0) {
return byDependents;
}
return b.value.transitiveCount.compareTo(a.value.transitiveCount);
});
final int maxDepth = metrics.values.fold<int>(
0,
(int current, DependencyGraphMetrics value) =>
value.maxDepth > current ? value.maxDepth : current,
);
final int directCount =
nodes.values.where((DependencyNode node) => node.isDirect).length;
return GraphSummary(
maxDepth: maxDepth,
totalNodes: nodes.length,
directDependencyCount: directCount,
transitiveDependencyCount: nodes.length - directCount,
centralNodes: ordered
.take(10)
.map((MapEntry<String, DependencyGraphMetrics> entry) {
return <String, Object?>{
'name': entry.key,
'directDependents': entry.value.directDependents,
'transitiveCount': entry.value.transitiveCount,
'maxDepth': entry.value.maxDepth,
};
}).toList(growable: false),
);
}