diff --git a/package.json b/package.json index 404287f..5377e78 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "sigma": "^3.0.2", "sonner": "^2.0.7", "three": "^0.183.2", + "three-spritetext": "^1.10.0", "zustand": "^5.0.11" }, "publishConfig": { diff --git a/src/pages/code-graph/components/Graph3DConfigDialog.tsx b/src/pages/code-graph/components/Graph3DConfigDialog.tsx new file mode 100644 index 0000000..3673df3 --- /dev/null +++ b/src/pages/code-graph/components/Graph3DConfigDialog.tsx @@ -0,0 +1,65 @@ +import { SlidersHorizontalIcon } from 'lucide-react'; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog'; +import { Checkbox } from '@/components/ui/checkbox'; +import { Button } from '@/components/ui/button'; +import { Graph3DConfig } from '../modules/graph3d-config'; + +interface Graph3DConfigDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + config: Graph3DConfig; + onUpdate: (patch: Partial) => void; + onReset: () => void; +} + +export function Graph3DConfigDialog({ open, onOpenChange, config, onUpdate, onReset }: Graph3DConfigDialogProps) { + return ( + + + + + + 3D 图谱配置 + + 配置 3D 力导向图的显示效果,设置自动保存到本地。 + + +
+ {/* ── 显示 ── */} +
+

显示

+
+ +
+
+ + {/* ── 其他配置暂留 ── */} +
+

其他(暂留)

+
+ 更多配置项开发中… +
+
+
+ +
+ + +
+
+
+ ); +} diff --git a/src/pages/code-graph/modules/graph3d-config.ts b/src/pages/code-graph/modules/graph3d-config.ts new file mode 100644 index 0000000..eeea0d3 --- /dev/null +++ b/src/pages/code-graph/modules/graph3d-config.ts @@ -0,0 +1,50 @@ +import { useState, useCallback } from 'react'; + +const STORAGE_KEY = 'code-graph-3d-config'; + +export interface Graph3DConfig { + /** 是否默认显示文字标签(SpriteText) */ + showLabels: boolean; + // 其他配置项暂留 +} + +const DEFAULT_CONFIG: Graph3DConfig = { + showLabels: true, +}; + +function loadConfig(): Graph3DConfig { + try { + const raw = localStorage.getItem(STORAGE_KEY); + if (!raw) return { ...DEFAULT_CONFIG }; + return { ...DEFAULT_CONFIG, ...JSON.parse(raw) }; + } catch { + return { ...DEFAULT_CONFIG }; + } +} + +function saveConfig(config: Graph3DConfig): void { + try { + localStorage.setItem(STORAGE_KEY, JSON.stringify(config)); + } catch { + // ignore + } +} + +export function useGraph3DConfig() { + const [config, setConfigState] = useState(() => loadConfig()); + + const updateConfig = useCallback((patch: Partial) => { + setConfigState((prev) => { + const next = { ...prev, ...patch }; + saveConfig(next); + return next; + }); + }, []); + + const resetConfig = useCallback(() => { + saveConfig(DEFAULT_CONFIG); + setConfigState({ ...DEFAULT_CONFIG }); + }, []); + + return { config, updateConfig, resetConfig }; +}