Skip to content

Commit

Permalink
fix: add excludeShapes options for manhattan router (#3334)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Mar 2, 2023
1 parent 2285e55 commit c76a23b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/x6/src/registry/router/manhattan/obstacle-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ 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
}
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)
Expand Down
6 changes: 6 additions & 0 deletions packages/x6/src/registry/router/manhattan/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -139,6 +144,7 @@ export const defaults: ManhattanRouterOptions = {
perpendicular: true,
excludeTerminals: [],
excludeNodes: [],
excludeShapes: [],
startDirections: ['top', 'right', 'bottom', 'left'],
endDirections: ['top', 'right', 'bottom', 'left'],
directionMap: {
Expand Down
1 change: 0 additions & 1 deletion sites/x6-sites/docs/api/registry/router.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 路由配置一致。 |
Expand Down

0 comments on commit c76a23b

Please sign in to comment.