diff --git a/lightrag_webui/package.json b/lightrag_webui/package.json index d15a0aab..7ed9ffcb 100644 --- a/lightrag_webui/package.json +++ b/lightrag_webui/package.json @@ -43,6 +43,10 @@ "cmdk": "^1.0.4", "graphology": "^0.26.0", "graphology-generators": "^0.11.2", + "graphology-layout": "^0.6.1", + "graphology-layout-force": "^0.2.4", + "graphology-layout-forceatlas2": "^0.10.1", + "graphology-layout-noverlap": "^0.4.2", "i18next": "^24.2.2", "katex": "^0.16.22", "lucide-react": "^0.475.0", @@ -56,6 +60,7 @@ "react-markdown": "^9.1.0", "react-number-format": "^5.4.3", "react-router-dom": "^7.3.0", + "react-select": "^5.10.2", "react-syntax-highlighter": "^15.6.1", "rehype-katex": "^7.0.1", "rehype-react": "^8.0.0", diff --git a/lightrag_webui/src/components/graph/GraphControl.tsx b/lightrag_webui/src/components/graph/GraphControl.tsx index af7cf250..fc0114e9 100644 --- a/lightrag_webui/src/components/graph/GraphControl.tsx +++ b/lightrag_webui/src/components/graph/GraphControl.tsx @@ -2,7 +2,7 @@ import { useRegisterEvents, useSetSettings, useSigma } from '@react-sigma/core' import { AbstractGraph } from 'graphology-types' // import { useLayoutCircular } from '@react-sigma/layout-circular' import { useLayoutForceAtlas2 } from '@react-sigma/layout-forceatlas2' -import { useEffect } from 'react' +import { useEffect, useState } from 'react' // import useRandomGraph, { EdgeType, NodeType } from '@/hooks/useRandomGraph' import { EdgeType, NodeType } from '@/hooks/useLightragGraph' @@ -43,6 +43,20 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean }) const selectedEdge = useGraphStore.use.selectedEdge() const focusedEdge = useGraphStore.use.focusedEdge() const sigmaGraph = useGraphStore.use.sigmaGraph() + + // Track system theme changes when theme is set to 'system' + const [systemThemeIsDark, setSystemThemeIsDark] = useState(() => + window.matchMedia('(prefers-color-scheme: dark)').matches + ) + + useEffect(() => { + if (theme === 'system') { + const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)') + const handler = (e: MediaQueryListEvent) => setSystemThemeIsDark(e.matches) + mediaQuery.addEventListener('change', handler) + return () => mediaQuery.removeEventListener('change', handler) + } + }, [theme]) /** * When component mount or maxIterations changes @@ -194,7 +208,9 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean }) * => Setting the sigma reducers */ useEffect(() => { - const isDarkTheme = theme === 'dark' + // Check if dark mode is actually applied (handles both 'dark' theme and 'system' theme when OS is dark) + const isDarkTheme = theme === 'dark' || + (theme === 'system' && window.document.documentElement.classList.contains('dark')) const labelColor = isDarkTheme ? Constants.labelColorDarkTheme : undefined const edgeColor = isDarkTheme ? Constants.edgeColorDarkTheme : undefined @@ -298,6 +314,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean }) sigma, disableHoverEffect, theme, + systemThemeIsDark, hideUnselectedEdges, enableEdgeEvents, renderEdgeLabels, diff --git a/lightrag_webui/src/components/graph/Settings.tsx b/lightrag_webui/src/components/graph/Settings.tsx index 37a36305..41da2f22 100644 --- a/lightrag_webui/src/components/graph/Settings.tsx +++ b/lightrag_webui/src/components/graph/Settings.tsx @@ -7,8 +7,10 @@ import Input from '@/components/ui/Input' import { controlButtonVariant } from '@/lib/constants' import { useSettingsStore } from '@/stores/settings' +import { useGraphStore } from '@/stores/graph' +import useRandomGraph from '@/hooks/useRandomGraph' -import { SettingsIcon, Undo2 } from 'lucide-react' +import { SettingsIcon, Undo2, Shuffle } from 'lucide-react' import { useTranslation } from 'react-i18next'; /** @@ -163,6 +165,9 @@ export default function Settings() { const enableHealthCheck = useSettingsStore.use.enableHealthCheck() + // Random graph functionality for development/testing + const { randomGraph } = useRandomGraph() + const setEnableNodeDrag = useCallback( () => useSettingsStore.setState((pre) => ({ enableNodeDrag: !pre.enableNodeDrag })), [] @@ -228,6 +233,11 @@ export default function Settings() { useSettingsStore.setState({ graphLayoutMaxIterations: iterations }) }, []) + const handleGenerateRandomGraph = useCallback(() => { + const graph = randomGraph() + useGraphStore.getState().setSigmaGraph(graph) + }, [randomGraph]) + const { t } = useTranslation(); const saveSettings = () => setOpened(false); @@ -376,6 +386,24 @@ export default function Settings() { defaultValue={15} onEditFinished={setGraphLayoutMaxIterations} /> + + + {/* Development/Testing Section */} +
+ + +
+