yangdx commited on
Commit
af95aa1
·
1 Parent(s): 9e8a018

Change to undirected graph

Browse files
lightrag_webui/src/features/GraphViewer.tsx CHANGED
@@ -31,7 +31,7 @@ import '@react-sigma/graph-search/lib/style.css'
31
  const defaultSigmaSettings: Partial<SigmaSettings> = {
32
  allowInvalidContainer: true,
33
  defaultNodeType: 'default',
34
- defaultEdgeType: 'curvedArrow',
35
  renderEdgeLabels: false,
36
  edgeProgramClasses: {
37
  arrow: EdgeArrowProgram,
 
31
  const defaultSigmaSettings: Partial<SigmaSettings> = {
32
  allowInvalidContainer: true,
33
  defaultNodeType: 'default',
34
+ defaultEdgeType: 'curvedNoArrow',
35
  renderEdgeLabels: false,
36
  edgeProgramClasses: {
37
  arrow: EdgeArrowProgram,
lightrag_webui/src/hooks/useLightragGraph.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import Graph, { DirectedGraph } from 'graphology'
2
  import { useCallback, useEffect, useRef } from 'react'
3
  import { useTranslation } from 'react-i18next'
4
  import { errorMessage } from '@/lib/utils'
@@ -303,7 +303,7 @@ const createSigmaGraph = (rawGraph: RawGraph | null) => {
303
  }
304
 
305
  // Create new graph instance
306
- const graph = new DirectedGraph()
307
 
308
  // Add nodes from raw graph data
309
  for (const rawNode of rawGraph?.nodes ?? []) {
@@ -329,10 +329,11 @@ const createSigmaGraph = (rawGraph: RawGraph | null) => {
329
  // Get weight from edge properties or default to 1
330
  const weight = rawEdge.properties?.weight !== undefined ? Number(rawEdge.properties.weight) : 1
331
 
332
- rawEdge.dynamicId = graph.addDirectedEdge(rawEdge.source, rawEdge.target, {
333
  label: rawEdge.properties?.keywords || undefined,
334
  size: weight, // Set initial size based on weight
335
  originalWeight: weight, // Store original weight for recalculation
 
336
  })
337
  }
338
 
@@ -486,7 +487,7 @@ const useLightrangeGraph = () => {
486
  // Check if data is empty or invalid
487
  if (!data || !data.nodes || data.nodes.length === 0) {
488
  // Create a graph with a single "Graph Is Empty" node
489
- const emptyGraph = new DirectedGraph();
490
 
491
  // Add a single node with "Graph Is Empty" label
492
  emptyGraph.addNode('empty-graph-node', {
@@ -726,7 +727,7 @@ const useLightrangeGraph = () => {
726
 
727
  // Helper function to update node sizes
728
  const updateNodeSizes = (
729
- sigmaGraph: DirectedGraph,
730
  nodesWithDiscardedEdges: Set<string>,
731
  minDegree: number,
732
  maxDegree: number
@@ -758,7 +759,7 @@ const useLightrangeGraph = () => {
758
 
759
  // Helper function to update edge sizes
760
  const updateEdgeSizes = (
761
- sigmaGraph: DirectedGraph,
762
  minWeight: number,
763
  maxWeight: number
764
  ) => {
@@ -866,9 +867,6 @@ const useLightrangeGraph = () => {
866
  if (sigmaGraph.hasEdge(newEdge.source, newEdge.target)) {
867
  continue;
868
  }
869
- if (sigmaGraph.hasEdge(newEdge.target, newEdge.source)) {
870
- continue;
871
- }
872
 
873
  // Get weight from edge properties or default to 1
874
  const weight = newEdge.properties?.weight !== undefined ? Number(newEdge.properties.weight) : 1;
@@ -878,10 +876,11 @@ const useLightrangeGraph = () => {
878
  maxWeight = Math.max(maxWeight, weight);
879
 
880
  // Add the edge to the sigma graph
881
- newEdge.dynamicId = sigmaGraph.addDirectedEdge(newEdge.source, newEdge.target, {
882
  label: newEdge.properties?.keywords || undefined,
883
  size: weight, // Set initial size based on weight
884
- originalWeight: weight // Store original weight for recalculation
 
885
  });
886
 
887
  // Add the edge to the raw graph
@@ -935,7 +934,7 @@ const useLightrangeGraph = () => {
935
  }, [nodeToExpand, sigmaGraph, rawGraph, t]);
936
 
937
  // Helper function to get all nodes that will be deleted
938
- const getNodesThatWillBeDeleted = useCallback((nodeId: string, graph: DirectedGraph) => {
939
  const nodesToDelete = new Set<string>([nodeId]);
940
 
941
  // Find all nodes that would become isolated after deletion
@@ -1063,7 +1062,7 @@ const useLightrangeGraph = () => {
1063
 
1064
  // If no graph exists yet, create a new one and store it
1065
  console.log('Creating new Sigma graph instance')
1066
- const graph = new DirectedGraph()
1067
  useGraphStore.getState().setSigmaGraph(graph)
1068
  return graph as Graph<NodeType, EdgeType>
1069
  }, [sigmaGraph])
 
1
+ import Graph, { UndirectedGraph } from 'graphology'
2
  import { useCallback, useEffect, useRef } from 'react'
3
  import { useTranslation } from 'react-i18next'
4
  import { errorMessage } from '@/lib/utils'
 
303
  }
304
 
305
  // Create new graph instance
306
+ const graph = new UndirectedGraph()
307
 
308
  // Add nodes from raw graph data
309
  for (const rawNode of rawGraph?.nodes ?? []) {
 
329
  // Get weight from edge properties or default to 1
330
  const weight = rawEdge.properties?.weight !== undefined ? Number(rawEdge.properties.weight) : 1
331
 
332
+ rawEdge.dynamicId = graph.addEdge(rawEdge.source, rawEdge.target, {
333
  label: rawEdge.properties?.keywords || undefined,
334
  size: weight, // Set initial size based on weight
335
  originalWeight: weight, // Store original weight for recalculation
336
+ type: 'curvedNoArrow' // Explicitly set edge type to no arrow
337
  })
338
  }
339
 
 
487
  // Check if data is empty or invalid
488
  if (!data || !data.nodes || data.nodes.length === 0) {
489
  // Create a graph with a single "Graph Is Empty" node
490
+ const emptyGraph = new UndirectedGraph();
491
 
492
  // Add a single node with "Graph Is Empty" label
493
  emptyGraph.addNode('empty-graph-node', {
 
727
 
728
  // Helper function to update node sizes
729
  const updateNodeSizes = (
730
+ sigmaGraph: UndirectedGraph,
731
  nodesWithDiscardedEdges: Set<string>,
732
  minDegree: number,
733
  maxDegree: number
 
759
 
760
  // Helper function to update edge sizes
761
  const updateEdgeSizes = (
762
+ sigmaGraph: UndirectedGraph,
763
  minWeight: number,
764
  maxWeight: number
765
  ) => {
 
867
  if (sigmaGraph.hasEdge(newEdge.source, newEdge.target)) {
868
  continue;
869
  }
 
 
 
870
 
871
  // Get weight from edge properties or default to 1
872
  const weight = newEdge.properties?.weight !== undefined ? Number(newEdge.properties.weight) : 1;
 
876
  maxWeight = Math.max(maxWeight, weight);
877
 
878
  // Add the edge to the sigma graph
879
+ newEdge.dynamicId = sigmaGraph.addEdge(newEdge.source, newEdge.target, {
880
  label: newEdge.properties?.keywords || undefined,
881
  size: weight, // Set initial size based on weight
882
+ originalWeight: weight, // Store original weight for recalculation
883
+ type: 'curvedNoArrow' // Explicitly set edge type to no arrow
884
  });
885
 
886
  // Add the edge to the raw graph
 
934
  }, [nodeToExpand, sigmaGraph, rawGraph, t]);
935
 
936
  // Helper function to get all nodes that will be deleted
937
+ const getNodesThatWillBeDeleted = useCallback((nodeId: string, graph: UndirectedGraph) => {
938
  const nodesToDelete = new Set<string>([nodeId]);
939
 
940
  // Find all nodes that would become isolated after deletion
 
1062
 
1063
  // If no graph exists yet, create a new one and store it
1064
  console.log('Creating new Sigma graph instance')
1065
+ const graph = new UndirectedGraph()
1066
  useGraphStore.getState().setSigmaGraph(graph)
1067
  return graph as Graph<NodeType, EdgeType>
1068
  }, [sigmaGraph])