sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
85 lines (84 loc) • 3.72 kB
TypeScript
export declare class Dag<Payload> implements DagIfc<Payload> {
roots: DagNodeIfc<Payload>[];
constructor();
toDebugString(): string;
/**
* Creates a DAG from a map giving the relationship between a node and its parent, and a data map containing the payload
* for each ID.
* @param hierarchy The map containing the hierarchy information
* @param data The map containing the payload information
*/
initFromFlatList(hierarchy: Map<string, string[]>, data: Map<string, Payload>, disabled: string[]): void;
/**
* A simple method to create a Dag from a map containing the hierarchy, and an array of items that are the payload
* and that have a getId() method to retrieve their ID
* @param hierarchy the map containing the hierarchy (id <-> list of parent ids)
* @param data the array containing the payload objects, each with a getId() function
*/
initFromIdableEntity(hierarchy: Map<string, string[]>, data: Array<Payload & {
getId(): string;
}>): void;
/**
* A simple method to create a Dag from only an array of items that are the payload
* and that have a getId() method to retrieve their ID, and a getParents() methods to retrieve their parents
* @param data the array containing the payload objects, each with a getId() function and a getParents() function
*/
initFromParentableAndIdAbleEntity(data: Array<Payload & {
getId(): string;
} & {
getParents(): string[];
}>, disabled: string[]): void;
initFlatTreeFromFlatList(data: Array<Payload & {
getId(): string;
}>): void;
traverseBreadthFirst(processor: (node: DagNodeIfc<Payload>) => void): void;
traverseDepthFirst(processor: (node: DagNodeIfc<Payload>) => void): void;
sort(compareFn: (a: Payload, b: Payload) => number): void;
}
export declare class DagNode<Payload> implements DagNodeIfc<Payload> {
id: string;
parents: DagNodeIfc<Payload>[];
children: DagNodeIfc<Payload>[];
disabled: boolean;
payload: Payload;
constructor(id: string, payload: Payload);
/**
* Adds this node under a new parent. Existing parents are kept
* @param parent the new parent or null to set a root node
*/
addUnder(parent: DagNodeIfc<Payload> | null): void;
/**
* Moves this node under a new parent. This will unlink the node from its existing parents
* @param parent the new parent or null to set a root node
*/
moveUnder(parent: DagNodeIfc<Payload> | null): void;
sort(compareFn: (a: Payload, b: Payload) => number): void;
toDebugString(depth: number): string;
traverseBreadthFirst(processor: (node: DagNodeIfc<Payload>) => void): void;
traverseDepthFirst(processor: (node: DagNodeIfc<Payload>) => void): void;
}
/**
* A node in a DAG. Just like a tree node, but with multiple parents
*/
export interface DagNodeIfc<Payload> {
id: string;
parents: DagNodeIfc<Payload>[];
children: DagNodeIfc<Payload>[];
disabled: boolean;
payload: Payload;
count?: number;
toDebugString(depth: number): string;
sort: (compareFn: (a: Payload, b: Payload) => number) => void;
traverseBreadthFirst: (processor: (node: DagNodeIfc<Payload>) => void) => void;
traverseDepthFirst: (processor: (node: DagNodeIfc<Payload>) => void) => void;
}
/**
* Directed Acyclic Graph
*/
export interface DagIfc<Payload> {
roots: DagNodeIfc<Payload>[];
toDebugString(): string;
sort: (compareFn: (a: Payload, b: Payload) => number) => void;
traverseBreadthFirst: (processor: (node: DagNodeIfc<Payload>) => void) => void;
traverseDepthFirst: (processor: (node: DagNodeIfc<Payload>) => void) => void;
}