refactor: 重构前端代码并增加注释
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import type { GraphLayoutConfig } from '../types/graph';
|
||||
import { DEFAULT_LAYOUT } from '../config/layout';
|
||||
|
||||
/**
|
||||
* 知识图谱布局管理 Hook
|
||||
* 负责布局状态的管理和切换
|
||||
*/
|
||||
export const useGraphLayout = () => {
|
||||
const [layout, setLayout] = useState<GraphLayoutConfig>(DEFAULT_LAYOUT);
|
||||
|
||||
// 切换布局类型(目前只支持 force 力导向布局)
|
||||
const handleLayoutChange = useCallback((newLayoutType: GraphLayoutConfig['type']) => {
|
||||
setLayout({ type: newLayoutType });
|
||||
}, []);
|
||||
|
||||
return {
|
||||
layout,
|
||||
handleLayoutChange,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user