Skip to content

Commit

Permalink
feat: expose getDescendantsData api (#6354)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx authored Sep 20, 2024
1 parent dfa22d0 commit b54d057
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/g6/__tests__/unit/runtime/graph/graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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' } }]);
Expand Down
12 changes: 12 additions & 0 deletions packages/g6/src/runtime/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,18 @@ export class Graph extends EventEmitter {
return this.context.model.getChildrenData(id);
}

/**
* <zh/> 获取节点或组合的后代元素数据
*
* <en/> Get the descendant element data of the node or combo
* @param id - <zh/> 节点或组合ID | <en/> node or combo ID
* @returns <zh/> 后代元素数据 | <en/> descendant element data
* @apiCategory data
*/
public getDescendantsData(id: ID): NodeLikeData[] {
return this.context.model.getDescendantsData(id);
}

/**
* <zh/> 获取指定状态下的节点数据
*
Expand Down

0 comments on commit b54d057

Please sign in to comment.