features method
Every feature at depth, with its size and how it couples to the rest,
sorted by name. Only files under a lib/ take part, and only edges that
cross from one feature into another count.
Implementation
List<FeatureMetrics> features(int depth) {
final files = <String, int>{};
final afferent = <String, int>{};
final efferent = <String, int>{};
for (final entry in edges.entries) {
final from = featureOf(entry.key, depth);
if (from == null) continue;
files[from] = (files[from] ?? 0) + 1;
for (final target in entry.value) {
final to = featureOf(target, depth);
if (to == null || to == from) continue;
efferent[from] = (efferent[from] ?? 0) + 1;
afferent[to] = (afferent[to] ?? 0) + 1;
}
}
return [
for (final name in files.keys.toList()..sort())
FeatureMetrics(
name,
files: files[name]!,
afferent: afferent[name] ?? 0,
efferent: efferent[name] ?? 0,
),
];
}