From c76a23b53425f5cbb7f767c0fe5510f3f81c417c Mon Sep 17 00:00:00 2001 From: vector Date: Thu, 2 Mar 2023 17:24:46 +0800 Subject: [PATCH] fix: add excludeShapes options for manhattan router (#3334) --- packages/x6/src/registry/router/manhattan/obstacle-map.ts | 6 +++++- packages/x6/src/registry/router/manhattan/options.ts | 6 ++++++ sites/x6-sites/docs/api/registry/router.zh.md | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/x6/src/registry/router/manhattan/obstacle-map.ts b/packages/x6/src/registry/router/manhattan/obstacle-map.ts index d1b2382120b..e3b643d52ec 100644 --- a/packages/x6/src/registry/router/manhattan/obstacle-map.ts +++ b/packages/x6/src/registry/router/manhattan/obstacle-map.ts @@ -74,6 +74,9 @@ export class ObstacleMap { const excludedTerminal = excludedTerminals.some( (cell) => cell.id === node.id, ) + const excludedShape = node.shape + ? options.excludeShapes.includes(node.shape) + : false const excludedNode = options.excludeNodes.some((item) => { if (typeof item === 'string') { return node.id === item @@ -81,7 +84,8 @@ export class ObstacleMap { return item === node }) const excludedAncestor = excludedAncestors.includes(node.id) - const excluded = excludedTerminal || excludedNode || excludedAncestor + const excluded = + excludedShape || excludedTerminal || excludedNode || excludedAncestor 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 c050768683d..c32bc312637 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 { */ excludeNodes: (Node | string)[] + /** + * Should certain types of nodes not be considered as obstacles? + */ + excludeShapes: string[] + /** * Possible starting directions from a node. */ @@ -139,6 +144,7 @@ export const defaults: ManhattanRouterOptions = { perpendicular: true, excludeTerminals: [], excludeNodes: [], + excludeShapes: [], startDirections: ['top', 'right', 'bottom', 'left'], endDirections: ['top', 'right', 'bottom', 'left'], directionMap: { diff --git a/sites/x6-sites/docs/api/registry/router.zh.md b/sites/x6-sites/docs/api/registry/router.zh.md index b8361b867cd..270e1f4d8d3 100644 --- a/sites/x6-sites/docs/api/registry/router.zh.md +++ b/sites/x6-sites/docs/api/registry/router.zh.md @@ -170,7 +170,6 @@ graph.addEdge({ | excludeTerminals | ('source' \| 'target')[] | 否 | `[]` | 忽略起始或终止节点,忽略后不参与障碍物计算。 | | excludeShapes | string[] | 否 | `[]` | 忽略指定形状的节点,忽略后不参与障碍物计算。 | | excludeNodes | Node[] | 否 | `[]` | 忽略的节点,忽略后不参与障碍物计算。 | -| excludeHiddenNodes | boolean | 否 | `false` | 忽略隐藏的节点,忽略后不参与障碍物计算。 | | startDirections | string[] | 否 | `['top', 'right', 'bottom', 'left']` | 支持从哪些方向开始路由。 | | endDirections | string[] | 否 | `['top', 'right', 'bottom', 'left']` | 支持从哪些方向结束路由。 | | padding | SideOptions | 否 | 20 | 设置锚点距离转角的最小距离,和 orth 路由配置一致。 |