yangdx
commited on
Commit
·
ff37d80
1
Parent(s):
dcae38a
Fix auto fit disabled afther zoom in or out manually
Browse files- Enhanced FocusOnNode component logic
- Added reset to default view when no node
- Updated mouse event handling for custom BBox
- Added sigmaRef for future use
- Triggered camera reset after graph updates
lightrag_webui/src/components/graph/FocusOnNode.tsx
CHANGED
@@ -13,15 +13,24 @@ const FocusOnNode = ({ node, move }: { node: string | null; move?: boolean }) =>
|
|
13 |
* When the selected item changes, highlighted the node and center the camera on it.
|
14 |
*/
|
15 |
useEffect(() => {
|
16 |
-
if (!node) return
|
17 |
-
sigma.getGraph().setNodeAttribute(node, 'highlighted', true)
|
18 |
if (move) {
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
useGraphStore.getState().setMoveToSelectedNode(false)
|
|
|
|
|
21 |
}
|
22 |
|
23 |
return () => {
|
24 |
-
|
|
|
|
|
25 |
}
|
26 |
}, [node, move, sigma, gotoNode])
|
27 |
|
|
|
13 |
* When the selected item changes, highlighted the node and center the camera on it.
|
14 |
*/
|
15 |
useEffect(() => {
|
|
|
|
|
16 |
if (move) {
|
17 |
+
if (node) {
|
18 |
+
sigma.getGraph().setNodeAttribute(node, 'highlighted', true)
|
19 |
+
gotoNode(node)
|
20 |
+
} else {
|
21 |
+
// If no node is selected but move is true, reset to default view
|
22 |
+
sigma.setCustomBBox(null)
|
23 |
+
sigma.getCamera().animate({ x: 0.5, y: 0.5, ratio: 1 }, { duration: 0 })
|
24 |
+
}
|
25 |
useGraphStore.getState().setMoveToSelectedNode(false)
|
26 |
+
} else if (node) {
|
27 |
+
sigma.getGraph().setNodeAttribute(node, 'highlighted', true)
|
28 |
}
|
29 |
|
30 |
return () => {
|
31 |
+
if (node) {
|
32 |
+
sigma.getGraph().setNodeAttribute(node, 'highlighted', false)
|
33 |
+
}
|
34 |
}
|
35 |
}, [node, move, sigma, gotoNode])
|
36 |
|
lightrag_webui/src/features/GraphViewer.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { useEffect, useState, useCallback, useMemo } from 'react'
|
2 |
// import { MiniMap } from '@react-sigma/minimap'
|
3 |
import { SigmaContainer, useRegisterEvents, useSigma } from '@react-sigma/core'
|
4 |
import { Settings as SigmaSettings } from 'sigma/settings'
|
@@ -91,8 +91,12 @@ const GraphEvents = () => {
|
|
91 |
}
|
92 |
},
|
93 |
// Disable the autoscale at the first down interaction
|
94 |
-
mousedown: () => {
|
95 |
-
if (
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
})
|
98 |
}, [registerEvents, sigma, draggedNode])
|
@@ -102,6 +106,7 @@ const GraphEvents = () => {
|
|
102 |
|
103 |
const GraphViewer = () => {
|
104 |
const [sigmaSettings, setSigmaSettings] = useState(defaultSigmaSettings)
|
|
|
105 |
|
106 |
const selectedNode = useGraphStore.use.selectedNode()
|
107 |
const focusedNode = useGraphStore.use.focusedNode()
|
@@ -144,7 +149,11 @@ const GraphViewer = () => {
|
|
144 |
)
|
145 |
|
146 |
return (
|
147 |
-
<SigmaContainer
|
|
|
|
|
|
|
|
|
148 |
<GraphControl />
|
149 |
|
150 |
{enableNodeDrag && <GraphEvents />}
|
|
|
1 |
+
import { useEffect, useState, useCallback, useMemo, useRef } from 'react'
|
2 |
// import { MiniMap } from '@react-sigma/minimap'
|
3 |
import { SigmaContainer, useRegisterEvents, useSigma } from '@react-sigma/core'
|
4 |
import { Settings as SigmaSettings } from 'sigma/settings'
|
|
|
91 |
}
|
92 |
},
|
93 |
// Disable the autoscale at the first down interaction
|
94 |
+
mousedown: (e) => {
|
95 |
+
// Only set custom BBox if it's a drag operation (mouse button is pressed)
|
96 |
+
const mouseEvent = e.original as MouseEvent;
|
97 |
+
if (mouseEvent.buttons !== 0 && !sigma.getCustomBBox()) {
|
98 |
+
sigma.setCustomBBox(sigma.getBBox())
|
99 |
+
}
|
100 |
}
|
101 |
})
|
102 |
}, [registerEvents, sigma, draggedNode])
|
|
|
106 |
|
107 |
const GraphViewer = () => {
|
108 |
const [sigmaSettings, setSigmaSettings] = useState(defaultSigmaSettings)
|
109 |
+
const sigmaRef = useRef<any>(null)
|
110 |
|
111 |
const selectedNode = useGraphStore.use.selectedNode()
|
112 |
const focusedNode = useGraphStore.use.focusedNode()
|
|
|
149 |
)
|
150 |
|
151 |
return (
|
152 |
+
<SigmaContainer
|
153 |
+
settings={sigmaSettings}
|
154 |
+
className="!bg-background !size-full overflow-hidden"
|
155 |
+
ref={sigmaRef}
|
156 |
+
>
|
157 |
<GraphControl />
|
158 |
|
159 |
{enableNodeDrag && <GraphEvents />}
|
lightrag_webui/src/hooks/useLightragGraph.tsx
CHANGED
@@ -254,6 +254,8 @@ const useLightrangeGraph = () => {
|
|
254 |
delete fetchStatusRef.current[fetchKey];
|
255 |
}
|
256 |
// Reset fetching state after all updates are complete
|
|
|
|
|
257 |
state.setIsFetching(false);
|
258 |
}).catch(() => {
|
259 |
// Reset fetching state and remove flag in case of error
|
|
|
254 |
delete fetchStatusRef.current[fetchKey];
|
255 |
}
|
256 |
// Reset fetching state after all updates are complete
|
257 |
+
// Reset camera view by triggering FocusOnNode component
|
258 |
+
state.setMoveToSelectedNode(true);
|
259 |
state.setIsFetching(false);
|
260 |
}).catch(() => {
|
261 |
// Reset fetching state and remove flag in case of error
|