fix
This commit is contained in:
@@ -14,7 +14,9 @@ export function useLayout() {
|
||||
|
||||
const previousDirection = ref('LR')
|
||||
|
||||
function layout(nodes, edges, direction = 'LR') {
|
||||
function layout(nodes, edges, direction = 'LR', options) {
|
||||
const nodesep = options?.nodesep || 50 // 节点间距
|
||||
const ranksep = options?.ranksep || 50 // 层级间距
|
||||
// 验证和规范化方向参数
|
||||
const validDirections = ['TB', 'BT', 'LR', 'RL']
|
||||
const layoutDirection = validDirections.includes(direction) ? direction : 'LR'
|
||||
@@ -28,7 +30,11 @@ export function useLayout() {
|
||||
|
||||
// 根据方向判断是否为水平布局
|
||||
const isHorizontal = layoutDirection === 'LR' || layoutDirection === 'RL'
|
||||
dagreGraph.setGraph({ rankdir: layoutDirection })
|
||||
dagreGraph.setGraph({
|
||||
rankdir: layoutDirection,
|
||||
nodesep,
|
||||
ranksep,
|
||||
})
|
||||
|
||||
previousDirection.value = layoutDirection
|
||||
|
||||
@@ -47,7 +53,7 @@ export function useLayout() {
|
||||
}
|
||||
|
||||
dagre.layout(dagreGraph)
|
||||
|
||||
|
||||
// set nodes with updated positions
|
||||
return nodes.map((node) => {
|
||||
const nodeWithPosition = dagreGraph.node(node.id)
|
||||
@@ -125,20 +131,20 @@ export function findAndAddChild(items, targetId, newChild) {
|
||||
*/
|
||||
export function findAndRemoveChild(items, targetId) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i]
|
||||
|
||||
// 如果找到目标节点,从当前数组中删除
|
||||
if (item.id === targetId) {
|
||||
items.splice(i, 1)
|
||||
return true
|
||||
}
|
||||
|
||||
// 递归搜索子节点
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findAndRemoveChild(item.children, targetId)
|
||||
if (found) return true
|
||||
}
|
||||
const item = items[i]
|
||||
|
||||
// 如果找到目标节点,从当前数组中删除
|
||||
if (item.id === targetId) {
|
||||
items.splice(i, 1)
|
||||
return true
|
||||
}
|
||||
|
||||
// 递归搜索子节点
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findAndRemoveChild(item.children, targetId)
|
||||
if (found) return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user