mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-07-23 21:04:26 +08:00

### What problem does this PR solve? feat: add FlowHeader and delete edge #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
36 lines
957 B
TypeScript
36 lines
957 B
TypeScript
import { useCallback, useLayoutEffect } from 'react';
|
|
import { getLayoutedElements } from './elk-utils';
|
|
|
|
export const elkOptions = {
|
|
'elk.algorithm': 'layered',
|
|
'elk.layered.spacing.nodeNodeBetweenLayers': '100',
|
|
'elk.spacing.nodeNode': '80',
|
|
};
|
|
|
|
export const useLayoutGraph = (
|
|
initialNodes,
|
|
initialEdges,
|
|
setNodes,
|
|
setEdges,
|
|
) => {
|
|
const onLayout = useCallback(({ direction, useInitialNodes = false }) => {
|
|
const opts = { 'elk.direction': direction, ...elkOptions };
|
|
const ns = initialNodes;
|
|
const es = initialEdges;
|
|
|
|
getLayoutedElements(ns, es, opts).then(
|
|
({ nodes: layoutedNodes, edges: layoutedEdges }) => {
|
|
setNodes(layoutedNodes);
|
|
setEdges(layoutedEdges);
|
|
|
|
// window.requestAnimationFrame(() => fitView());
|
|
},
|
|
);
|
|
}, []);
|
|
|
|
// Calculate the initial layout on mount.
|
|
useLayoutEffect(() => {
|
|
onLayout({ direction: 'RIGHT', useInitialNodes: true });
|
|
}, [onLayout]);
|
|
};
|