mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-08-02 13:51:56 +00:00
Fix linting and upate webui assets
This commit is contained in:
parent
fc4582b260
commit
fdaf199b15
File diff suppressed because one or more lines are too long
@ -8,7 +8,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="./logo.png" />
|
<link rel="icon" type="image/svg+xml" href="./logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Lightrag</title>
|
<title>Lightrag</title>
|
||||||
<script type="module" crossorigin src="./assets/index-DeJuAbj6.js"></script>
|
<script type="module" crossorigin src="./assets/index-W9SNU3ES.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="./assets/index-BV5s8k-a.css">
|
<link rel="stylesheet" crossorigin href="./assets/index-BV5s8k-a.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -14,7 +14,7 @@ const FocusOnNode = ({ node, move }: { node: string | null; move?: boolean }) =>
|
|||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const graph = sigma.getGraph();
|
const graph = sigma.getGraph();
|
||||||
|
|
||||||
if (move) {
|
if (move) {
|
||||||
if (node && graph.hasNode(node)) {
|
if (node && graph.hasNode(node)) {
|
||||||
try {
|
try {
|
||||||
|
@ -62,13 +62,13 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error setting graph on sigma instance:', error);
|
console.error('Error setting graph on sigma instance:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用布局
|
// 应用布局
|
||||||
assignLayout();
|
assignLayout();
|
||||||
console.log('Layout applied to graph');
|
console.log('Layout applied to graph');
|
||||||
}
|
}
|
||||||
}, [sigma, sigmaGraph, assignLayout, maxIterations])
|
}, [sigma, sigmaGraph, assignLayout, maxIterations])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure the sigma instance is set in the store
|
* Ensure the sigma instance is set in the store
|
||||||
* This provides a backup in case the instance wasn't set in GraphViewer
|
* This provides a backup in case the instance wasn't set in GraphViewer
|
||||||
@ -224,7 +224,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
|
|||||||
} else {
|
} else {
|
||||||
const _selectedEdge = selectedEdge && graph.hasEdge(selectedEdge) ? selectedEdge : null;
|
const _selectedEdge = selectedEdge && graph.hasEdge(selectedEdge) ? selectedEdge : null;
|
||||||
const _focusedEdge = focusedEdge && graph.hasEdge(focusedEdge) ? focusedEdge : null;
|
const _focusedEdge = focusedEdge && graph.hasEdge(focusedEdge) ? focusedEdge : null;
|
||||||
|
|
||||||
if (_selectedEdge || _focusedEdge) {
|
if (_selectedEdge || _focusedEdge) {
|
||||||
if (edge === _selectedEdge) {
|
if (edge === _selectedEdge) {
|
||||||
newData.color = Constants.edgeColorSelected
|
newData.color = Constants.edgeColorSelected
|
||||||
|
@ -101,7 +101,7 @@ const refineNodeProperties = (node: RawNodeType): NodeType => {
|
|||||||
|
|
||||||
// 获取所有边
|
// 获取所有边
|
||||||
const edges = state.sigmaGraph.edges(node.id)
|
const edges = state.sigmaGraph.edges(node.id)
|
||||||
|
|
||||||
// 处理每条边
|
// 处理每条边
|
||||||
for (const edgeId of edges) {
|
for (const edgeId of edges) {
|
||||||
// 检查边是否还存在
|
// 检查边是否还存在
|
||||||
|
@ -147,7 +147,7 @@ const GraphViewer = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSigmaSettings(defaultSigmaSettings)
|
setSigmaSettings(defaultSigmaSettings)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Clean up sigma instance when component unmounts
|
// Clean up sigma instance when component unmounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
@ -156,20 +156,20 @@ const GraphViewer = () => {
|
|||||||
console.log('Cleared sigma instance on unmount');
|
console.log('Cleared sigma instance on unmount');
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Get the sigmaGraph from the store
|
// Get the sigmaGraph from the store
|
||||||
const sigmaGraph = useGraphStore.use.sigmaGraph();
|
const sigmaGraph = useGraphStore.use.sigmaGraph();
|
||||||
|
|
||||||
// Set the sigma instance in the graph store when it's available
|
// Set the sigma instance in the graph store when it's available
|
||||||
// Using useLayoutEffect to ensure this runs before child components need the instance
|
// Using useLayoutEffect to ensure this runs before child components need the instance
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (sigmaRef.current?.sigma) {
|
if (sigmaRef.current?.sigma) {
|
||||||
const instance = sigmaRef.current.sigma;
|
const instance = sigmaRef.current.sigma;
|
||||||
|
|
||||||
// Get the sigma instance from the ref and store it
|
// Get the sigma instance from the ref and store it
|
||||||
console.log('Setting sigma instance in graph store (layout effect)');
|
console.log('Setting sigma instance in graph store (layout effect)');
|
||||||
useGraphStore.getState().setSigmaInstance(instance);
|
useGraphStore.getState().setSigmaInstance(instance);
|
||||||
|
|
||||||
// If we also have a graph, bind it to the sigma instance
|
// If we also have a graph, bind it to the sigma instance
|
||||||
if (sigmaGraph) {
|
if (sigmaGraph) {
|
||||||
try {
|
try {
|
||||||
|
@ -446,7 +446,7 @@ const useLightrangeGraph = () => {
|
|||||||
for (const edge of processedEdges) {
|
for (const edge of processedEdges) {
|
||||||
const sourceExists = existingNodeIds.has(edge.source) || nodesToAdd.has(edge.source);
|
const sourceExists = existingNodeIds.has(edge.source) || nodesToAdd.has(edge.source);
|
||||||
const targetExists = existingNodeIds.has(edge.target) || nodesToAdd.has(edge.target);
|
const targetExists = existingNodeIds.has(edge.target) || nodesToAdd.has(edge.target);
|
||||||
|
|
||||||
if (sourceExists && targetExists) {
|
if (sourceExists && targetExists) {
|
||||||
edgesToAdd.add(edge.id);
|
edgesToAdd.add(edge.id);
|
||||||
} else {
|
} else {
|
||||||
@ -462,14 +462,14 @@ const useLightrangeGraph = () => {
|
|||||||
|
|
||||||
// STEP 2: Calculate node degrees and sizes
|
// STEP 2: Calculate node degrees and sizes
|
||||||
const nodeDegrees = new Map<string, number>();
|
const nodeDegrees = new Map<string, number>();
|
||||||
|
|
||||||
// Calculate degrees from kept edges
|
// Calculate degrees from kept edges
|
||||||
for (const edgeId of edgesToAdd) {
|
for (const edgeId of edgesToAdd) {
|
||||||
const edge = processedEdges.find(e => e.id === edgeId)!;
|
const edge = processedEdges.find(e => e.id === edgeId)!;
|
||||||
nodeDegrees.set(edge.source, (nodeDegrees.get(edge.source) || 0) + 1);
|
nodeDegrees.set(edge.source, (nodeDegrees.get(edge.source) || 0) + 1);
|
||||||
nodeDegrees.set(edge.target, (nodeDegrees.get(edge.target) || 0) + 1);
|
nodeDegrees.set(edge.target, (nodeDegrees.get(edge.target) || 0) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add +1 to degree for nodes that had edges discarded
|
// Add +1 to degree for nodes that had edges discarded
|
||||||
for (const nodeId of nodesWithDiscardedEdges) {
|
for (const nodeId of nodesWithDiscardedEdges) {
|
||||||
nodeDegrees.set(nodeId, (nodeDegrees.get(nodeId) || 0) + 1);
|
nodeDegrees.set(nodeId, (nodeDegrees.get(nodeId) || 0) + 1);
|
||||||
@ -482,7 +482,7 @@ const useLightrangeGraph = () => {
|
|||||||
const degree = sigmaGraph.degree(node);
|
const degree = sigmaGraph.degree(node);
|
||||||
maxDegree = Math.max(maxDegree, degree);
|
maxDegree = Math.max(maxDegree, degree);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update maxDegree with new node degrees
|
// Update maxDegree with new node degrees
|
||||||
for (const [, degree] of nodeDegrees.entries()) {
|
for (const [, degree] of nodeDegrees.entries()) {
|
||||||
maxDegree = Math.max(maxDegree, degree);
|
maxDegree = Math.max(maxDegree, degree);
|
||||||
@ -497,30 +497,30 @@ const useLightrangeGraph = () => {
|
|||||||
for (const nodeId of nodesToAdd) {
|
for (const nodeId of nodesToAdd) {
|
||||||
const newNode = processedNodes.find(n => n.id === nodeId)!;
|
const newNode = processedNodes.find(n => n.id === nodeId)!;
|
||||||
const nodeDegree = nodeDegrees.get(nodeId) || 0;
|
const nodeDegree = nodeDegrees.get(nodeId) || 0;
|
||||||
|
|
||||||
// Calculate node size
|
// Calculate node size
|
||||||
const nodeSize = Math.round(
|
const nodeSize = Math.round(
|
||||||
Constants.minNodeSize + scale * Math.pow((nodeDegree - minDegree) / range, 0.5)
|
Constants.minNodeSize + scale * Math.pow((nodeDegree - minDegree) / range, 0.5)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get camera ratio from sigma instance for scale adjustment
|
// Get camera ratio from sigma instance for scale adjustment
|
||||||
const cameraRatio = useGraphStore.getState().sigmaInstance?.getCamera().ratio || 1;
|
const cameraRatio = useGraphStore.getState().sigmaInstance?.getCamera().ratio || 1;
|
||||||
|
|
||||||
// Calculate spread factor based on node size and number of nodes
|
// Calculate spread factor based on node size and number of nodes
|
||||||
const spreadFactor = Math.max(
|
const spreadFactor = Math.max(
|
||||||
nodeToExpand.size * 4, // Base on node size
|
nodeToExpand.size * 4, // Base on node size
|
||||||
Math.sqrt(nodesToAdd.size) * 10 // Scale with number of nodes
|
Math.sqrt(nodesToAdd.size) * 10 // Scale with number of nodes
|
||||||
) / cameraRatio; // Adjust for zoom level
|
) / cameraRatio; // Adjust for zoom level
|
||||||
|
|
||||||
// Calculate angle for polar coordinates
|
// Calculate angle for polar coordinates
|
||||||
const angle = 2 * Math.PI * (Array.from(nodesToAdd).indexOf(nodeId) / nodesToAdd.size);
|
const angle = 2 * Math.PI * (Array.from(nodesToAdd).indexOf(nodeId) / nodesToAdd.size);
|
||||||
|
|
||||||
// Calculate final position
|
// Calculate final position
|
||||||
const x = nodePositions[nodeId]?.x ||
|
const x = nodePositions[nodeId]?.x ||
|
||||||
(nodePositions[nodeToExpand.id].x + Math.cos(angle) * spreadFactor);
|
(nodePositions[nodeToExpand.id].x + Math.cos(angle) * spreadFactor);
|
||||||
const y = nodePositions[nodeId]?.y ||
|
const y = nodePositions[nodeId]?.y ||
|
||||||
(nodePositions[nodeToExpand.id].y + Math.sin(angle) * spreadFactor);
|
(nodePositions[nodeToExpand.id].y + Math.sin(angle) * spreadFactor);
|
||||||
|
|
||||||
// Add the new node to the sigma graph with calculated position
|
// Add the new node to the sigma graph with calculated position
|
||||||
sigmaGraph.addNode(nodeId, {
|
sigmaGraph.addNode(nodeId, {
|
||||||
label: newNode.labels.join(', '),
|
label: newNode.labels.join(', '),
|
||||||
@ -539,7 +539,7 @@ const useLightrangeGraph = () => {
|
|||||||
newNode.x = x;
|
newNode.x = x;
|
||||||
newNode.y = y;
|
newNode.y = y;
|
||||||
newNode.degree = nodeDegree;
|
newNode.degree = nodeDegree;
|
||||||
|
|
||||||
// Add to nodes array
|
// Add to nodes array
|
||||||
rawGraph.nodes.push(newNode);
|
rawGraph.nodes.push(newNode);
|
||||||
// Update nodeIdMap
|
// Update nodeIdMap
|
||||||
@ -550,7 +550,7 @@ const useLightrangeGraph = () => {
|
|||||||
// Add new edges
|
// Add new edges
|
||||||
for (const edgeId of edgesToAdd) {
|
for (const edgeId of edgesToAdd) {
|
||||||
const newEdge = processedEdges.find(e => e.id === edgeId)!;
|
const newEdge = processedEdges.find(e => e.id === edgeId)!;
|
||||||
|
|
||||||
// Skip if edge already exists
|
// Skip if edge already exists
|
||||||
if (sigmaGraph.hasEdge(newEdge.source, newEdge.target)) {
|
if (sigmaGraph.hasEdge(newEdge.source, newEdge.target)) {
|
||||||
continue;
|
continue;
|
||||||
@ -579,7 +579,7 @@ const useLightrangeGraph = () => {
|
|||||||
if (sigmaGraph.hasNode(nodeId)) {
|
if (sigmaGraph.hasNode(nodeId)) {
|
||||||
// Get the new degree of the expanded node
|
// Get the new degree of the expanded node
|
||||||
let expandedNodeDegree = sigmaGraph.degree(nodeId);
|
let expandedNodeDegree = sigmaGraph.degree(nodeId);
|
||||||
|
|
||||||
// Check if the expanded node had any discarded edges
|
// Check if the expanded node had any discarded edges
|
||||||
if (nodesWithDiscardedEdges.has(nodeId)) {
|
if (nodesWithDiscardedEdges.has(nodeId)) {
|
||||||
expandedNodeDegree += 1; // Add +1 for discarded edges
|
expandedNodeDegree += 1; // Add +1 for discarded edges
|
||||||
|
@ -189,7 +189,7 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setMoveToSelectedNode: (moveToSelectedNode?: boolean) => set({ moveToSelectedNode }),
|
setMoveToSelectedNode: (moveToSelectedNode?: boolean) => set({ moveToSelectedNode }),
|
||||||
|
|
||||||
setSigmaInstance: (instance: any) => set({ sigmaInstance: instance }),
|
setSigmaInstance: (instance: any) => set({ sigmaInstance: instance }),
|
||||||
|
|
||||||
// Methods to set global flags
|
// Methods to set global flags
|
||||||
@ -447,7 +447,7 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
|
|||||||
// Rebuild the dynamic edge map
|
// Rebuild the dynamic edge map
|
||||||
state.rawGraph.buildDynamicMap();
|
state.rawGraph.buildDynamicMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 图形更新后会自动触发重新布局
|
// 图形更新后会自动触发重新布局
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user