fix: resolve dark mode text visibility issue in knowledge graph view
- Replace hardcoded black text colors (#000) with dynamic theme-based colors - Add createSigmaSettings function to generate settings based on theme - Use labelColorDarkTheme (#B2EBF2) for dark mode and black (#000) for light mode - Update GraphViewer component to react to theme changes - Fixes issue where node and edge labels were invisible in dark mode Fixes: Dark mode text visibility in knowledge graph visualization
This commit is contained in:
parent
5f45ff56be
commit
20402f515f
1 changed files with 14 additions and 11 deletions
|
|
@ -23,12 +23,13 @@ import LegendButton from '@/components/graph/LegendButton'
|
||||||
|
|
||||||
import { useSettingsStore } from '@/stores/settings'
|
import { useSettingsStore } from '@/stores/settings'
|
||||||
import { useGraphStore } from '@/stores/graph'
|
import { useGraphStore } from '@/stores/graph'
|
||||||
|
import { labelColorDarkTheme } from '@/lib/constants'
|
||||||
|
|
||||||
import '@react-sigma/core/lib/style.css'
|
import '@react-sigma/core/lib/style.css'
|
||||||
import '@react-sigma/graph-search/lib/style.css'
|
import '@react-sigma/graph-search/lib/style.css'
|
||||||
|
|
||||||
// Sigma settings
|
// Function to create sigma settings based on theme
|
||||||
const defaultSigmaSettings: Partial<SigmaSettings> = {
|
const createSigmaSettings = (isDarkTheme: boolean): Partial<SigmaSettings> => ({
|
||||||
allowInvalidContainer: true,
|
allowInvalidContainer: true,
|
||||||
defaultNodeType: 'default',
|
defaultNodeType: 'default',
|
||||||
defaultEdgeType: 'curvedNoArrow',
|
defaultEdgeType: 'curvedNoArrow',
|
||||||
|
|
@ -47,18 +48,18 @@ const defaultSigmaSettings: Partial<SigmaSettings> = {
|
||||||
labelRenderedSizeThreshold: 12,
|
labelRenderedSizeThreshold: 12,
|
||||||
enableEdgeEvents: true,
|
enableEdgeEvents: true,
|
||||||
labelColor: {
|
labelColor: {
|
||||||
color: '#000',
|
color: isDarkTheme ? labelColorDarkTheme : '#000',
|
||||||
attribute: 'labelColor'
|
attribute: 'labelColor'
|
||||||
},
|
},
|
||||||
edgeLabelColor: {
|
edgeLabelColor: {
|
||||||
color: '#000',
|
color: isDarkTheme ? labelColorDarkTheme : '#000',
|
||||||
attribute: 'labelColor'
|
attribute: 'labelColor'
|
||||||
},
|
},
|
||||||
edgeLabelSize: 8,
|
edgeLabelSize: 8,
|
||||||
labelSize: 12
|
labelSize: 12
|
||||||
// minEdgeThickness: 2
|
// minEdgeThickness: 2
|
||||||
// labelFont: 'Lato, sans-serif'
|
// labelFont: 'Lato, sans-serif'
|
||||||
}
|
})
|
||||||
|
|
||||||
const GraphEvents = () => {
|
const GraphEvents = () => {
|
||||||
const registerEvents = useRegisterEvents()
|
const registerEvents = useRegisterEvents()
|
||||||
|
|
@ -107,7 +108,7 @@ const GraphEvents = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const GraphViewer = () => {
|
const GraphViewer = () => {
|
||||||
const [sigmaSettings, setSigmaSettings] = useState(defaultSigmaSettings)
|
const [sigmaSettings, setSigmaSettings] = useState<Partial<SigmaSettings>>({})
|
||||||
const sigmaRef = useRef<any>(null)
|
const sigmaRef = useRef<any>(null)
|
||||||
|
|
||||||
const selectedNode = useGraphStore.use.selectedNode()
|
const selectedNode = useGraphStore.use.selectedNode()
|
||||||
|
|
@ -119,13 +120,15 @@ const GraphViewer = () => {
|
||||||
const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar()
|
const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar()
|
||||||
const enableNodeDrag = useSettingsStore.use.enableNodeDrag()
|
const enableNodeDrag = useSettingsStore.use.enableNodeDrag()
|
||||||
const showLegend = useSettingsStore.use.showLegend()
|
const showLegend = useSettingsStore.use.showLegend()
|
||||||
|
const theme = useSettingsStore.use.theme()
|
||||||
|
|
||||||
// Initialize sigma settings once on component mount
|
// Initialize sigma settings based on theme
|
||||||
// All dynamic settings will be updated in GraphControl using useSetSettings
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSigmaSettings(defaultSigmaSettings)
|
const isDarkTheme = theme === 'dark'
|
||||||
console.log('Initialized sigma settings')
|
const settings = createSigmaSettings(isDarkTheme)
|
||||||
}, [])
|
setSigmaSettings(settings)
|
||||||
|
console.log('Initialized sigma settings for theme:', theme)
|
||||||
|
}, [theme])
|
||||||
|
|
||||||
// Clean up sigma instance when component unmounts
|
// Clean up sigma instance when component unmounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue