Skip to content

Commit 36c7024

Browse files
authored
refactor(graph): optimize graph api, improve docs (#6792)
1 parent 7c9763b commit 36c7024

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

packages/g6/src/runtime/graph.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ export class Graph extends EventEmitter {
554554
* const node1 = graph.getNodeData('node-1');
555555
* ```
556556
* @apiCategory data
557+
* @remarks
558+
* <zh/> 节点 id 必须存在,否则会抛出异常
559+
*
560+
* <en/> Node id must exist, otherwise an exception will be thrown
557561
*/
558562
public getNodeData(id: ID): NodeData;
559563
/**
@@ -567,12 +571,16 @@ export class Graph extends EventEmitter {
567571
* const [node1, node2] = graph.getNodeData(['node-1', 'node-2']);
568572
* ```
569573
* @apiCategory data
574+
* @remarks
575+
* <zh/> 数组中的每个节点 id 必须存在,否则将抛出异常
576+
*
577+
* <en/> Each node id in the array must exist, otherwise an exception will be thrown
570578
*/
571579
public getNodeData(ids: ID[]): NodeData[];
572580
public getNodeData(id?: ID | ID[]): NodeData | NodeData[] {
573581
if (id === undefined) return this.context.model.getNodeData();
574582
if (Array.isArray(id)) return this.context.model.getNodeData(id);
575-
return this.context.model.getNodeData([id])?.[0];
583+
return this.context.model.getNodeLikeDatum(id);
576584
}
577585

578586
/**
@@ -594,6 +602,10 @@ export class Graph extends EventEmitter {
594602
* const edge1 = graph.getEdgeData('edge-1');
595603
* ```
596604
* @apiCategory data
605+
* @remarks
606+
* <zh/> 边 id 必须存在,否则会抛出异常
607+
*
608+
* <en/> Edge id must exist, otherwise an exception will be thrown
597609
*/
598610
public getEdgeData(id: ID): EdgeData;
599611
/**
@@ -607,12 +619,16 @@ export class Graph extends EventEmitter {
607619
* const [edge1, edge2] = graph.getEdgeData(['edge-1', 'edge-2']);
608620
* ```
609621
* @apiCategory data
622+
* @remarks
623+
* <zh/> 数组中的每个边 id 必须存在,否则将抛出异常
624+
*
625+
* <en/> Each edge id in the array must exist, otherwise an exception will be thrown
610626
*/
611627
public getEdgeData(ids: ID[]): EdgeData[];
612628
public getEdgeData(id?: ID | ID[]): EdgeData | EdgeData[] {
613629
if (id === undefined) return this.context.model.getEdgeData();
614630
if (Array.isArray(id)) return this.context.model.getEdgeData(id);
615-
return this.context.model.getEdgeData([id])?.[0];
631+
return this.context.model.getEdgeDatum(id);
616632
}
617633

618634
/**
@@ -634,6 +650,10 @@ export class Graph extends EventEmitter {
634650
* const combo1 = graph.getComboData('combo-1');
635651
* ```
636652
* @apiCategory data
653+
* @remarks
654+
* <zh/> 组合 id 必须存在,否则会抛出异常
655+
*
656+
* <en/> Combo id must exist, otherwise an exception will be thrown
637657
*/
638658
public getComboData(id: ID): ComboData;
639659
/**
@@ -647,12 +667,16 @@ export class Graph extends EventEmitter {
647667
* const [combo1, combo2] = graph.getComboData(['combo-1', 'combo-2']);
648668
* ```
649669
* @apiCategory data
670+
* @remarks
671+
* <zh/> 数组中的每个组合 id 必须存在,否则将抛出异常
672+
*
673+
* <en/> Each combo id in the array must exist, otherwise an exception will be thrown
650674
*/
651675
public getComboData(ids: ID[]): ComboData[];
652676
public getComboData(id?: ID | ID[]): ComboData | ComboData[] {
653677
if (id === undefined) return this.context.model.getComboData();
654678
if (Array.isArray(id)) return this.context.model.getComboData(id);
655-
return this.context.model.getComboData([id])?.[0];
679+
return this.context.model.getNodeLikeDatum(id);
656680
}
657681

658682
/**

0 commit comments

Comments
 (0)