fybdp-d3-kg
Version:
Knowledge Graph using React and D3.js
200 lines (199 loc) • 6.32 kB
TypeScript
/// <reference types="node" />
import EventEmitter from 'events';
import { BaseNode } from './elements/nodes/BaseNode';
import { BaseLink } from './elements/edges/BaseLink';
/**
* 出来各种布局和转换布局数据
*/
export declare class Layout extends EventEmitter {
graph: any;
nodes: BaseNode[];
links: BaseLink[];
neighbors: {};
parser: any;
edgeCreator: any;
category: number;
originData: any;
/**
* Parser Graph data
*/
constructor(graph: any, category: any);
/**
* Fetches model attributes
* Currently used for first binding or rendering
*
* @param {String} attr - attribute to return. Valid attributes are `links` or `nodes`.
* @return {Object|Array|null}
*/
get(attr: any): BaseNode[] | BaseLink[] | {
links: BaseLink[];
nodes: BaseNode[];
} | null;
/**
* 数据的入口函数需要格式化转成对象
* @param nodes
* @param links
*/
setData(data: any): void;
/**
* Updates entire model data set
* @param {Array} nodes - nodes data
* @param {Array} links - links data
*/
updateData(data: any): void;
private buildSimulationData;
/**
* Find node by id 计算链接时引用节点的唯一标识符
*
* @param {String} id
* @return {Node} node
*/
findNodeById(id: any): BaseNode | undefined;
/**
* Finds index of node either by it's unique identifier, e.g. `id` or the node data object itself.
*
* @param {String|Object} node - id or data object
* @return {Integer} index of matched node or `-1` if not found
*/
findNodeIndex(node: any): number;
/**
* Updates data on a specific node
*
* @param {String|Node} n - either `id` of node, or the object itself to update
* @param {Object} attrs - node data attributes to change. This is merged onto existing attributes, so you only need to pass in updated values.
* @return {this}
*/
updateNode(n: any, attrs: any): this;
/**
* Removes node _and_ its links from the graph.
*
* @param {Node} node
*/
removeNode(node: any): void;
/**
* Removes node by its `id`.
* @param {String} id - id of node to remove
*/
removeNodeById(id: any): void;
/**
* Finds links a given node has. Example results are `[{source: node, target: node}]`
*
* @param {Node} node
* @return {Array} of {@link Link} objets
*/
findLinks(node: any): any[];
/**
* count siblind links a given link
*
* @param {link } link
* @return {Number } count of sibling links
*/
countSiblingLinks(link: any): number;
/**
* find siblind links a given link
*
* @param {link } link
* @return {Array } siblings of links
*/
getSiblingLinks(link: any): any[];
/**
* Removes links for a given node
*
* @param {Node} node
*/
removeLinks(node: any): void;
isIndexBasedLink(link: any): boolean;
static isValidData(data: any): boolean;
/**
* Emits an event
*
* @private
* @param {String} eventName - Event Name, e.g. `update`
*/
publish(eventName: any, data?: object): void;
mapNeighbors(): void;
/**
* Examines the a relationship between the two given nodes. Will return `true` if there is a a source<->target relationship or if the nodes are equal, i.e. the same.
*
* @param {Node} a - first node
* @param {Node} b - second node
* @return {Boolean}
*/
areNeighbors(a: any, b: any): any;
/**
* Examines if there is a `source -> target` relationship between two specific nodes.
*
* @param {Node} a - first node
* @param {Node} b - second node
* @return {Boolean}
*/
isSourceNeighbor(a: any, b: any): boolean;
/**
* Examines if node a is includeed in node b's source tree, i.e. if a `source -> ... -> target` relationship between the two nodes.
*
* @param {Node} a - potential source node
* @param {Node} b - potential target node
* @return {Boolean}
*/
isDeepSourceNeighbor(a: any, b: any): boolean;
/**
* Examines if there is a `b -> a` relationship between two specific nodes.
*
* @param {Node} a - potential `target` node
* @param {Node} b - potential `source` node
* @return {Boolean}
*/
isTargetNeighbor(a: any, b: any): any;
/**
* Returns true if the nodes examined are equal, i.e. the same node
*
* @param {String} a - id of node A
* @param {String} b - id of node B
* @return {Boolean}
*/
isEqualNode(a: any, b: any): boolean;
/**
* Returns Array of nodes in the source tree of a specific node.
*
* @param {Node} n - node to get source tree
* @return {Array}
*/
findSources(n: any): any[];
/**
* Recursively finds all deep sources of a node, i.e. does not include direct source.
*
* @param {Node} n - node to get source tree
* @param {Array} [sources=[]]
* @param {Array} [level=0]
* @return {Array}
*/
findDeepSources(n: any, sources?: any[], level?: number): any[];
/**
* Returns `true` if link can be found in the node's source tree.
*
* @param {Link} link
* @param {Node} n
* @return {Boolean}
*/
isDeepSourceLink(link: any, n: any): boolean;
/**
* Returns relationship type between node and its neighbor. Will return one of the following:
* | Key | Relationship type |
* |:--|:--|
* | `'is-source'` | node -> neighbor |
* | `'is-deep-source'` | node -> … -> neighbor |
* | `'is-target'` | neighbor -> node |
* | `'is-same-node'` | node === neighbor |
* | `'has-no-relationship'` | There is no relationship between the two nodes |
*
* @param {Node} node
* @param {Node} neighbor
* @return {String}
*/
getRelationship(node: any, neighbor: any): string;
setEmpty(): void;
/**
* 销毁
*/
destroy(): void;
}