diff --git a/packages/x6/src/registry/router/manhattan/obstacle-map.ts b/packages/x6/src/registry/router/manhattan/obstacle-map.ts index c049cf4636b..43ba70ebdb0 100644 --- a/packages/x6/src/registry/router/manhattan/obstacle-map.ts +++ b/packages/x6/src/registry/router/manhattan/obstacle-map.ts @@ -77,7 +77,8 @@ export class ObstacleMap { const excType = shape ? excludeShapes.includes(shape) : false const excTerminal = excludedTerminals.some((cell) => cell.id === node.id) const excAncestor = excludedAncestors.includes(node.id) - const excluded = excType || excTerminal || excAncestor + const excHidden = options.excludeHiddenNodes && !node.isVisible() + const excluded = excType || excTerminal || excAncestor || excHidden if (!excluded) { const bbox = node.getBBox().moveAndExpand(options.paddingBox) diff --git a/packages/x6/src/registry/router/manhattan/options.ts b/packages/x6/src/registry/router/manhattan/options.ts index 524eb3f01e2..fa034147faa 100644 --- a/packages/x6/src/registry/router/manhattan/options.ts +++ b/packages/x6/src/registry/router/manhattan/options.ts @@ -46,6 +46,11 @@ export interface ResolvedOptions { */ excludeShapes: string[] + /** + * Should certain hidden nodes not be considered as obstacles? + */ + excludeHiddenNodes: boolean + /** * Possible starting directions from a node. */ @@ -136,6 +141,7 @@ export const defaults: ManhattanRouterOptions = { perpendicular: true, excludeTerminals: [], excludeShapes: [], // ['text'] + excludeHiddenNodes: false, startDirections: ['top', 'right', 'bottom', 'left'], endDirections: ['top', 'right', 'bottom', 'left'], directionMap: { diff --git a/sites/x6-sites/docs/api/registry/router.en.md b/sites/x6-sites/docs/api/registry/router.en.md index f0312c3a449..600fea6f640 100644 --- a/sites/x6-sites/docs/api/registry/router.en.md +++ b/sites/x6-sites/docs/api/registry/router.en.md @@ -172,10 +172,12 @@ graph.addEdge({ | maximumLoops | number | 否 | `2000` | 最大迭代次数,到达最大迭代次数后将使用候补路由。 | | maxDirectionChange | number | 否 | `90` | 最大旋转角度。 | | excludeTerminals | ('source' \| 'target')[] | 否 | `[]` | 忽略起始或终止节点,忽略后不参与障碍物计算。 | -| excludeShapes | string[] | 否 | `[]` | 忽略指定节点名的节点,忽略后不参与障碍物计算。 | +| excludeShapes | string[] | 否 | `[]` | 忽略指定形状的节点,忽略后不参与障碍物计算。 | +| excludeHiddenNodes | boolean | 否 | `false` | 忽略隐藏的节点,忽略后不参与障碍物计算。 | | startDirections | string[] | 否 | `['top', 'right', 'bottom', 'left']` | 支持从哪些方向开始路由。 | | endDirections | string[] | 否 | `['top', 'right', 'bottom', 'left']` | 支持从哪些方向结束路由。 | + 例如: ```ts diff --git a/sites/x6-sites/docs/api/registry/router.zh.md b/sites/x6-sites/docs/api/registry/router.zh.md index a78145672f4..5bba59db94d 100644 --- a/sites/x6-sites/docs/api/registry/router.zh.md +++ b/sites/x6-sites/docs/api/registry/router.zh.md @@ -172,7 +172,8 @@ graph.addEdge({ | maximumLoops | number | 否 | `2000` | 最大迭代次数,到达最大迭代次数后将使用候补路由。 | | maxDirectionChange | number | 否 | `90` | 最大旋转角度。 | | excludeTerminals | ('source' \| 'target')[] | 否 | `[]` | 忽略起始或终止节点,忽略后不参与障碍物计算。 | -| excludeShapes | string[] | 否 | `[]` | 忽略指定节点名的节点,忽略后不参与障碍物计算。 | +| excludeShapes | string[] | 否 | `[]` | 忽略指定形状的节点,忽略后不参与障碍物计算。 | +| excludeHiddenNodes | boolean | 否 | `false` | 忽略隐藏的节点,忽略后不参与障碍物计算。 | | startDirections | string[] | 否 | `['top', 'right', 'bottom', 'left']` | 支持从哪些方向开始路由。 | | endDirections | string[] | 否 | `['top', 'right', 'bottom', 'left']` | 支持从哪些方向结束路由。 |