Fix linting and upate webui assets

This commit is contained in:
yangdx 2025-03-15 00:33:53 +08:00
parent fc4582b260
commit fdaf199b15
8 changed files with 154 additions and 154 deletions

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@
<link rel="icon" type="image/svg+xml" href="./logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<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">
</head>
<body>

View File

@ -14,7 +14,7 @@ const FocusOnNode = ({ node, move }: { node: string | null; move?: boolean }) =>
*/
useEffect(() => {
const graph = sigma.getGraph();
if (move) {
if (node && graph.hasNode(node)) {
try {

View File

@ -62,13 +62,13 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
} catch (error) {
console.error('Error setting graph on sigma instance:', error);
}
// 应用布局
assignLayout();
console.log('Layout applied to graph');
}
}, [sigma, sigmaGraph, assignLayout, maxIterations])
/**
* Ensure the sigma instance is set in the store
* This provides a backup in case the instance wasn't set in GraphViewer
@ -224,7 +224,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
} else {
const _selectedEdge = selectedEdge && graph.hasEdge(selectedEdge) ? selectedEdge : null;
const _focusedEdge = focusedEdge && graph.hasEdge(focusedEdge) ? focusedEdge : null;
if (_selectedEdge || _focusedEdge) {
if (edge === _selectedEdge) {
newData.color = Constants.edgeColorSelected

View File

@ -101,7 +101,7 @@ const refineNodeProperties = (node: RawNodeType): NodeType => {
// 获取所有边
const edges = state.sigmaGraph.edges(node.id)
// 处理每条边
for (const edgeId of edges) {
// 检查边是否还存在

View File

@ -147,7 +147,7 @@ const GraphViewer = () => {
useEffect(() => {
setSigmaSettings(defaultSigmaSettings)
}, [])
// Clean up sigma instance when component unmounts
useEffect(() => {
return () => {
@ -156,20 +156,20 @@ const GraphViewer = () => {
console.log('Cleared sigma instance on unmount');
};
}, []);
// Get the sigmaGraph from the store
const sigmaGraph = useGraphStore.use.sigmaGraph();
// Set the sigma instance in the graph store when it's available
// Using useLayoutEffect to ensure this runs before child components need the instance
useLayoutEffect(() => {
if (sigmaRef.current?.sigma) {
const instance = sigmaRef.current.sigma;
// Get the sigma instance from the ref and store it
console.log('Setting sigma instance in graph store (layout effect)');
useGraphStore.getState().setSigmaInstance(instance);
// If we also have a graph, bind it to the sigma instance
if (sigmaGraph) {
try {

View File

@ -446,7 +446,7 @@ const useLightrangeGraph = () => {
for (const edge of processedEdges) {
const sourceExists = existingNodeIds.has(edge.source) || nodesToAdd.has(edge.source);
const targetExists = existingNodeIds.has(edge.target) || nodesToAdd.has(edge.target);
if (sourceExists && targetExists) {
edgesToAdd.add(edge.id);
} else {
@ -462,14 +462,14 @@ const useLightrangeGraph = () => {
// STEP 2: Calculate node degrees and sizes
const nodeDegrees = new Map<string, number>();
// Calculate degrees from kept edges
for (const edgeId of edgesToAdd) {
const edge = processedEdges.find(e => e.id === edgeId)!;
nodeDegrees.set(edge.source, (nodeDegrees.get(edge.source) || 0) + 1);
nodeDegrees.set(edge.target, (nodeDegrees.get(edge.target) || 0) + 1);
}
// Add +1 to degree for nodes that had edges discarded
for (const nodeId of nodesWithDiscardedEdges) {
nodeDegrees.set(nodeId, (nodeDegrees.get(nodeId) || 0) + 1);
@ -482,7 +482,7 @@ const useLightrangeGraph = () => {
const degree = sigmaGraph.degree(node);
maxDegree = Math.max(maxDegree, degree);
});
// Update maxDegree with new node degrees
for (const [, degree] of nodeDegrees.entries()) {
maxDegree = Math.max(maxDegree, degree);
@ -497,30 +497,30 @@ const useLightrangeGraph = () => {
for (const nodeId of nodesToAdd) {
const newNode = processedNodes.find(n => n.id === nodeId)!;
const nodeDegree = nodeDegrees.get(nodeId) || 0;
// Calculate node size
const nodeSize = Math.round(
Constants.minNodeSize + scale * Math.pow((nodeDegree - minDegree) / range, 0.5)
);
// Get camera ratio from sigma instance for scale adjustment
const cameraRatio = useGraphStore.getState().sigmaInstance?.getCamera().ratio || 1;
// Calculate spread factor based on node size and number of nodes
const spreadFactor = Math.max(
nodeToExpand.size * 4, // Base on node size
Math.sqrt(nodesToAdd.size) * 10 // Scale with number of nodes
) / cameraRatio; // Adjust for zoom level
// Calculate angle for polar coordinates
const angle = 2 * Math.PI * (Array.from(nodesToAdd).indexOf(nodeId) / nodesToAdd.size);
// Calculate final position
const x = nodePositions[nodeId]?.x ||
const x = nodePositions[nodeId]?.x ||
(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);
// Add the new node to the sigma graph with calculated position
sigmaGraph.addNode(nodeId, {
label: newNode.labels.join(', '),
@ -539,7 +539,7 @@ const useLightrangeGraph = () => {
newNode.x = x;
newNode.y = y;
newNode.degree = nodeDegree;
// Add to nodes array
rawGraph.nodes.push(newNode);
// Update nodeIdMap
@ -550,7 +550,7 @@ const useLightrangeGraph = () => {
// Add new edges
for (const edgeId of edgesToAdd) {
const newEdge = processedEdges.find(e => e.id === edgeId)!;
// Skip if edge already exists
if (sigmaGraph.hasEdge(newEdge.source, newEdge.target)) {
continue;
@ -579,7 +579,7 @@ const useLightrangeGraph = () => {
if (sigmaGraph.hasNode(nodeId)) {
// Get the new degree of the expanded node
let expandedNodeDegree = sigmaGraph.degree(nodeId);
// Check if the expanded node had any discarded edges
if (nodesWithDiscardedEdges.has(nodeId)) {
expandedNodeDegree += 1; // Add +1 for discarded edges

View File

@ -189,7 +189,7 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
},
setMoveToSelectedNode: (moveToSelectedNode?: boolean) => set({ moveToSelectedNode }),
setSigmaInstance: (instance: any) => set({ sigmaInstance: instance }),
// Methods to set global flags
@ -447,7 +447,7 @@ const useGraphStoreBase = create<GraphState>()((set, get) => ({
// Rebuild the dynamic edge map
state.rawGraph.buildDynamicMap();
}
// 图形更新后会自动触发重新布局
} catch (error) {