1111 */
1212
1313import type { GraphEdge , GraphNode } from '@bibgraph/types' ;
14- import { Group , SegmentedControl , Stack , Text , Tooltip } from '@mantine/core' ;
15- import { useCallback , useMemo } from 'react' ;
14+ import { Group , SegmentedControl , Text , Tooltip } from '@mantine/core' ;
15+ import { useMemo } from 'react' ;
1616
17- import { ICON_SIZE } from '@/config/style-constants' ;
1817import { findReachableNodes , type PathPreset } from '@/lib/path-presets' ;
1918
2019interface PathHighlightingPresetsProps {
@@ -66,9 +65,9 @@ export const PathHighlightingPresets: React.FC<PathHighlightingPresetsProps> = (
6665 pathTarget,
6766 nodes,
6867 edges,
69- onHighlightNodes,
70- onHighlightPath,
71- onClearHighlights,
68+ onHighlightNodes : _onHighlightNodes ,
69+ onHighlightPath : _onHighlightPath ,
70+ onClearHighlights : _onClearHighlights ,
7271} ) => {
7372 // Build graph adjacency map for pathfinding
7473 const graph = useMemo ( ( ) => {
@@ -92,57 +91,6 @@ export const PathHighlightingPresets: React.FC<PathHighlightingPresetsProps> = (
9291 return adjacency ;
9392 } , [ nodes , edges ] ) ;
9493
95- // Find and highlight paths based on preset
96- const applyPreset = useCallback ( ( ) => {
97- if ( ! pathSource && preset !== 'shortest' && preset !== 'all-paths' ) {
98- // For incoming/outgoing paths, we need at least source or target
99- return ;
100- }
101-
102- if ( preset === 'shortest' ) {
103- // Use existing shortest path logic (handled by pathSource/pathTarget)
104- if ( pathSource && pathTarget ) {
105- const path = findReachableNodes ( graph , pathSource , pathTarget , 1 ) ;
106- if ( path . length > 0 ) {
107- onHighlightPath ( path ) ;
108- }
109- }
110- } else if ( preset === 'outgoing-paths' ) {
111- // Find all nodes reachable from source
112- if ( pathSource ) {
113- const reachableNodes = findReachableNodes ( graph , pathSource ) ;
114- onHighlightNodes ( reachableNodes ) ;
115- }
116- } else if ( preset === 'incoming-paths' ) {
117- // Find all nodes that can reach target
118- // This requires reversing the graph
119- if ( pathTarget ) {
120- const reversedGraph = new Map < string , Set < string > > ( ) ;
121-
122- // Build reversed adjacency list
123- graph . forEach ( ( neighbors , nodeId ) => {
124- reversedGraph . set ( nodeId , new Set ( ) ) ;
125- } ) ;
126-
127- graph . forEach ( ( neighbors , fromNode ) => {
128- neighbors . forEach ( ( toNode ) => {
129- if ( reversedGraph . has ( toNode ) ) {
130- reversedGraph . get ( toNode ) ?. add ( fromNode ) ;
131- }
132- } ) ;
133- } ) ;
134-
135- const incomingNodes = findReachableNodes ( reversedGraph , pathTarget ) ;
136- onHighlightNodes ( incomingNodes ) ;
137- }
138- } else if ( preset === 'all-paths' && pathSource && pathTarget ) {
139- // Find all nodes on all paths between source and target
140- // This is a complex problem - for now, highlight nodes within 2 hops of shortest path
141- const pathNodes = findReachableNodes ( graph , pathSource , pathTarget , 3 ) ;
142- onHighlightNodes ( pathNodes ) ;
143- }
144- } , [ preset , pathSource , pathTarget , graph , onHighlightNodes , onHighlightPath ] ) ;
145-
14694 // Calculate path count
14795 const pathCount = useMemo ( ( ) => {
14896 if ( preset === 'shortest' || preset === 'all-paths' ) {
0 commit comments