diff --git a/app/lib/src/graph/tree_canvas.dart b/app/lib/src/graph/tree_canvas.dart index c8156c5..52737b4 100644 --- a/app/lib/src/graph/tree_canvas.dart +++ b/app/lib/src/graph/tree_canvas.dart @@ -198,8 +198,9 @@ Iterable _shown(TreeItem t) sync* { } /// Opens levels breadth-first while the canvas stays readable (about `budget` items), so a -/// small graph shows whole and a large one its top levels. -void expandInitial(TreeItem root, {int budget = 150}) { +/// small graph shows whole and a large one its top levels. Small branches (up to `small` +/// children) always open: a crowded centre must not leave them folded. +void expandInitial(TreeItem root, {int budget = 150, int small = 12}) { root.expanded = true; var shown = 1 + root.children.length; var level = root.children; @@ -207,7 +208,9 @@ void expandInitial(TreeItem root, {int budget = 150}) { final next = []; for (final t in level) { if (t.children.isEmpty) continue; - if (shown + t.children.length > budget) continue; + if (t.children.length > small && shown + t.children.length > budget) { + continue; + } t.expanded = true; shown += t.children.length; next.addAll(t.children); diff --git a/app/test/graph_view_test.dart b/app/test/graph_view_test.dart index 1a41624..bbfdae3 100644 --- a/app/test/graph_view_test.dart +++ b/app/test/graph_view_test.dart @@ -398,6 +398,17 @@ void main() { expect(hub.expanded, isFalse); }); + test('small branches open even when the centre is crowded', () { + final root = TreeItem('Graph'); + for (var i = 0; i < 300; i++) { + root.children.add(TreeItem('Note $i', global: i)); + } + final ns = TreeItem('Anthropic')..children.add(TreeItem('Claude')); + root.children.add(ns); + expandInitial(root); + expect(ns.expanded, isTrue); + }); + testWidgets('branches expand and collapse in the canvas', (tester) async { await pumpGraph(tester, _HubBackend(bigHub())); await mode(tester, 'Tree');