diff --git a/packages/g6/__tests__/unit/runtime/graph/graph.spec.ts b/packages/g6/__tests__/unit/runtime/graph/graph.spec.ts
index c050d33030d..874c58a76f6 100644
--- a/packages/g6/__tests__/unit/runtime/graph/graph.spec.ts
+++ b/packages/g6/__tests__/unit/runtime/graph/graph.spec.ts
@@ -205,7 +205,8 @@ describe('Graph', () => {
expect(graph.getEdgeData().map(idOf)).toEqual(['edge-1']);
expect(graph.getComboData()).toEqual([]);
- graph.addComboData([{ id: 'combo-1', style: {} }]);
+ graph.addComboData([{ id: 'combo-2', style: {} }]);
+ graph.addComboData([{ id: 'combo-1', combo: 'combo-2', style: {} }]);
graph.addNodeData([
{ id: 'node-3', combo: 'combo-1' },
{ id: 'node-4', combo: 'combo-1' },
@@ -215,8 +216,10 @@ describe('Graph', () => {
expect(graph.getEdgeData().map(idOf)).toEqual(['edge-1', 'edge-2']);
expect(graph.getComboData('combo-1').id).toEqual('combo-1');
expect(graph.getComboData(['combo-1']).map(idOf)).toEqual(['combo-1']);
- expect(graph.getComboData().map(idOf)).toEqual(['combo-1']);
+ expect(graph.getComboData().map(idOf)).toEqual(['combo-2', 'combo-1']);
expect(graph.getChildrenData('combo-1').map(idOf)).toEqual(['node-3', 'node-4']);
+ expect(graph.getDescendantsData('combo-2').map(idOf)).toEqual(['combo-1', 'node-3', 'node-4']);
+ graph.removeComboData(['combo-2']);
graph.updateNodeData([{ id: 'node-3', style: { x: 100, y: 100 } }]);
graph.updateEdgeData([{ id: 'edge-2', style: { lineWidth: 10 } }]);
graph.updateComboData([{ id: 'combo-1', style: { stroke: 'red' } }]);
diff --git a/packages/g6/src/runtime/graph.ts b/packages/g6/src/runtime/graph.ts
index f0633b688b9..4f77867a603 100644
--- a/packages/g6/src/runtime/graph.ts
+++ b/packages/g6/src/runtime/graph.ts
@@ -966,6 +966,18 @@ export class Graph extends EventEmitter {
return this.context.model.getChildrenData(id);
}
+ /**
+ * 获取节点或组合的后代元素数据
+ *
+ * Get the descendant element data of the node or combo
+ * @param id - 节点或组合ID | node or combo ID
+ * @returns 后代元素数据 | descendant element data
+ * @apiCategory data
+ */
+ public getDescendantsData(id: ID): NodeLikeData[] {
+ return this.context.model.getDescendantsData(id);
+ }
+
/**
* 获取指定状态下的节点数据
*