Skip to content

Commit 71142e4

Browse files
authored
feat(layout): add comboFilter (#7244)
1 parent 3198bd4 commit 71142e4

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

packages/g6/src/layouts/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
RadialLayoutOptions,
1616
RandomLayoutOptions,
1717
} from '@antv/layout';
18-
import type { NodeData } from '../spec/data';
18+
import type { ComboData, NodeData } from '../spec/data';
1919
import type { BaseLayout } from './base-layout';
2020
import type { FishboneLayoutOptions } from './fishbone';
2121
import type { SnakeLayoutOptions } from './snake';
@@ -52,6 +52,14 @@ export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOpti
5252
* @returns <zh/> 是否参与布局 | <en/> Whether to participate in the layout
5353
*/
5454
nodeFilter?: (node: NodeData) => boolean;
55+
/**
56+
* <zh/> 参与该布局的combo元素
57+
*
58+
* <en/> Combos involved in the layout
59+
* @param node - <zh/> combo数据 | <en/> combo data
60+
* @returns <zh/> 是否参与布局 | <en/> Whether to participate in the layout
61+
*/
62+
comboFilter?: (combo: ComboData) => boolean;
5563
/**
5664
* <zh/> 使用前布局,在初始化元素前计算布局
5765
*

packages/g6/src/runtime/layout.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,12 @@ export class LayoutController {
296296
}
297297

298298
public getLayoutData(options: STDLayoutOptions): GraphData {
299-
const { nodeFilter = () => true, preLayout = false, isLayoutInvisibleNodes = false } = options;
299+
const {
300+
nodeFilter = () => true,
301+
comboFilter = () => true,
302+
preLayout = false,
303+
isLayoutInvisibleNodes = false,
304+
} = options;
300305
const { nodes, edges, combos } = this.context.model.getData();
301306

302307
const { element, model } = this.context;
@@ -320,9 +325,10 @@ export class LayoutController {
320325
};
321326

322327
const nodesToLayout = nodes.filter(filterFn);
328+
const combosToLayout = combos.filter(comboFilter);
323329

324330
const nodeLikeIdsMap = new Map<ID, NodeData>(nodesToLayout.map((node) => [idOf(node), node]));
325-
combos.forEach((combo) => nodeLikeIdsMap.set(idOf(combo), combo));
331+
combosToLayout.forEach((combo) => nodeLikeIdsMap.set(idOf(combo), combo));
326332

327333
const edgesToLayout = edges.filter(({ source, target }) => {
328334
return nodeLikeIdsMap.has(source) && nodeLikeIdsMap.has(target);
@@ -331,7 +337,7 @@ export class LayoutController {
331337
return {
332338
nodes: nodesToLayout,
333339
edges: edgesToLayout,
334-
combos,
340+
combos: combosToLayout,
335341
};
336342
}
337343

packages/site/docs/manual/layout/BaseLayout.en.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ This article introduces the common attribute configurations for built-in layouts
77

88
## General Configuration
99

10-
| Property | Description | Type | Default | Required |
11-
| ---------------------- | --------------------------------------------------------------------------------------- | --------------------------- | ---------- | -------- |
12-
| type | Layout type, name of built-in or custom layout | [Type](#Type) | - ||
13-
| isLayoutInvisibleNodes | Whether invisible nodes participate in the layout (takes effect when preLayout is true) | boolean | false | |
14-
| nodeFilter | Nodes participating in the layout | (node: NodeData) => boolean | () => true | |
15-
| preLayout | Use pre-layout, calculate layout before initializing elements | boolean | false | |
16-
| enableWorker | Whether to run the layout in a WebWorker | boolean | - | |
17-
| iterations | Number of iterations for iterative layout | number | - | |
10+
| Property | Description | Type | Default | Required |
11+
| ---------------------- | --------------------------------------------------------------------------------------- | ----------------------------- | ---------- | -------- |
12+
| type | Layout type, name of built-in or custom layout | [Type](#Type) | - ||
13+
| isLayoutInvisibleNodes | Whether invisible nodes participate in the layout (takes effect when preLayout is true) | boolean | false | |
14+
| nodeFilter | Nodes participating in the layout | (node: NodeData) => boolean | () => true | |
15+
| comboFilter | Combos participating in the layout | (combo: ComboData) => boolean | () => true | |
16+
| preLayout | Use pre-layout, calculate layout before initializing elements | boolean | false | |
17+
| enableWorker | Whether to run the layout in a WebWorker | boolean | - | |
18+
| iterations | Number of iterations for iterative layout | number | - | |
1819

1920
### Type
2021

packages/site/docs/manual/layout/BaseLayout.zh.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ order: 1
77

88
## 通用配置
99

10-
| 属性 | 描述 | 类型 | 默认值 | 必选 |
11-
| ---------------------- | ----------------------------------------------------- | --------------------------- | ---------- | ---- |
12-
| type | 布局类型,内置布局或自定义布局的名称 | [Type](#Type) | - ||
13-
| isLayoutInvisibleNodes | 不可见节点是否参与布局(当 preLayout 为 true 时生效) | boolean | false | |
14-
| nodeFilter | 参与该布局的节点 | (node: NodeData) => boolean | () => true | |
15-
| preLayout | 使用前布局,在初始化元素前计算布局 | boolean | false | |
16-
| enableWorker | 是否在 WebWorker 中运行布局 | boolean | - | |
17-
| iterations | 迭代布局的迭代次数 | number | - | |
10+
| 属性 | 描述 | 类型 | 默认值 | 必选 |
11+
| ---------------------- | ----------------------------------------------------- | ----------------------------- | ---------- | ---- |
12+
| type | 布局类型,内置布局或自定义布局的名称 | [Type](#Type) | - ||
13+
| isLayoutInvisibleNodes | 不可见节点是否参与布局(当 preLayout 为 true 时生效) | boolean | false | |
14+
| nodeFilter | 参与该布局的节点 | (node: NodeData) => boolean | () => true | |
15+
| comboFilter | 参与该布局的combo元素 | (combo: ComboData) => boolean | () => true | |
16+
| preLayout | 使用前布局,在初始化元素前计算布局 | boolean | false | |
17+
| enableWorker | 是否在 WebWorker 中运行布局 | boolean | - | |
18+
| iterations | 迭代布局的迭代次数 | number | - | |
1819

1920
### Type
2021

0 commit comments

Comments
 (0)