feat(graph): interactive GraphView — hover-highlight + click-to-open (T-323)
GraphView lays a VaultGraph out with the force solver, paints it, and wires hover (light the hovered node's neighbourhood, dim the rest) + click (onOpen with the node's vault path). A shared GraphViewport keeps hit-testing aligned with paint. Solver + model + painter + interactive view now stand; the pql link-data wiring, filter, and MultitabPane/slot registration are the remaining "integrate into the app" work. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -68,4 +68,16 @@ void main() {
|
||||
final tokens = await tokensFrom(tester);
|
||||
expect(await tester.runAsync(() => hasInk(GraphPainter(graph: const VaultGraph([], []), positions: const {}, tokens: tokens))), isFalse);
|
||||
});
|
||||
|
||||
group('hitTestNode', () {
|
||||
test('finds the node under the point, null when far or empty', () {
|
||||
final g = VaultGraph.fromOutlinks({'a.md': const []});
|
||||
// A single node lays out at the layout centre (400,300); an 800×600 canvas
|
||||
// over an 800×600 layout is scale 1, no offset → the node sits at (400,300).
|
||||
final pos = ForceLayout.compute(['a.md'], const []);
|
||||
expect(hitTestNode(g, pos, const Offset(400, 300), const Size(800, 600)), 'a.md');
|
||||
expect(hitTestNode(g, pos, const Offset(20, 20), const Size(800, 600)), isNull);
|
||||
expect(hitTestNode(g, const {}, Offset.zero, const Size(800, 600)), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:clide/builtin/graph/src/graph_view.dart';
|
||||
import 'package:clide/src/graph/vault_graph.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../helpers/kernel_fixture.dart';
|
||||
import '../../helpers/widget_harness.dart';
|
||||
|
||||
void main() {
|
||||
late KernelFixture f;
|
||||
setUp(() async => f = await KernelFixture.create());
|
||||
tearDown(() => f.dispose());
|
||||
|
||||
testWidgets('clicking a node opens it', (tester) async {
|
||||
String? opened;
|
||||
final g = VaultGraph.fromOutlinks({'only.md': const []});
|
||||
await tester.pumpWidget(
|
||||
anchoredHarness(
|
||||
f,
|
||||
SizedBox(
|
||||
width: 300,
|
||||
height: 300,
|
||||
child: GraphView(graph: g, layoutSize: const Size(300, 300), onOpen: (id) => opened = id),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
// A single node lays out at the centre → the view's centre.
|
||||
await tester.tap(find.byType(GraphView));
|
||||
expect(opened, 'only.md');
|
||||
});
|
||||
|
||||
testWidgets('renders an empty graph without error', (tester) async {
|
||||
await tester.pumpWidget(anchoredHarness(f, const SizedBox(width: 200, height: 200, child: GraphView(graph: VaultGraph([], [])))));
|
||||
await tester.pump();
|
||||
expect(find.byType(GraphView), findsOneWidget);
|
||||
await tester.tap(find.byType(GraphView)); // no node, no onOpen — must not throw
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user