Make graph generic (#43160)

* Make graph generic

* change Node<T>[] to Array<Node<T>>

* fix missing semicolon

* fix missing whitespace
This commit is contained in:
Rikkert Koppes 2020-03-20 15:31:53 +00:00 committed by GitHub
parent a19b27a0a8
commit 18a399b465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@
export as namespace dagre;
export namespace graphlib {
class Graph {
class Graph<T = {}> {
constructor(opt?: {directed?: boolean, multigraph?: boolean, compound?: boolean});
graph(): GraphLabel;
@ -33,19 +33,19 @@ export namespace graphlib {
children(parentName: string): string|undefined;
hasNode(name: string): boolean;
neighbors(name: string): Node[]|undefined;
node(id: string|Label): Node;
neighbors(name: string): Array<Node<T>>|undefined;
node(id: string|Label): Node<T>;
nodeCount(): number;
nodes(): string[];
parent(childName: string): string|undefined;
predecessors(name: string): Node[]|undefined;
predecessors(name: string): Array<Node<T>>|undefined;
removeNode(name: string): Graph;
setDefaultNodeLabel(callback: string|((nodeId: string) => string|Label)): Graph;
setNode(name: string, label: string|Label): Graph;
setParent(childName: string, parentName: string): void;
sinks(): Node[];
sources(): Node[];
successors(name: string): Node[]|undefined;
sinks(): Array<Node<T>>;
sources(): Array<Node<T>>;
successors(name: string): Array<Node<T>>|undefined;
}
namespace json {
@ -116,10 +116,9 @@ export interface GraphEdge {
[key: string]: any;
}
export interface Node {
export type Node<T = {}> = T & {
x: number;
y: number;
width: number;
height: number;
[key: string]: any;
}
};