UNPKG

d3-graph-controller

Version:

A TypeScript library for visualizing and simulating directed, interactive graphs.

117 lines (116 loc) 3.76 kB
import { GraphConfig } from './config/config.mjs'; import { LinkFilter } from './config/filter.mjs'; import { Graph, NodeTypeToken } from './model/graph.mjs'; import { GraphLink } from './model/link.mjs'; import { GraphNode } from './model/node.mjs'; /** * Controller for a graph view. */ export declare class GraphController<T extends NodeTypeToken = NodeTypeToken, Node extends GraphNode<T> = GraphNode<T>, Link extends GraphLink<T, Node> = GraphLink<T, Node>> { private readonly container; private readonly graph; private readonly config; /** * Array of all node types included in the controller's graph. */ readonly nodeTypes: T[]; private _nodeTypeFilter; private _includeUnlinked; private _linkFilter; private _showLinkLabels; private _showNodeLabels; private filteredGraph; private width; private height; private simulation; private canvas; private linkSelection; private nodeSelection; private markerSelection; private zoom; private drag; private xOffset; private yOffset; private scale; private focusedNode; private resizeObserver?; /** * Create a new controller and initialize the view. * @param container - The container the graph will be placed in. * @param graph - The graph of the controller. * @param config - The config of the controller. */ constructor(container: HTMLDivElement, graph: Graph<T, Node, Link>, config: GraphConfig<T, Node, Link>); /** * Get the current node type filter. * Only nodes whose type is included will be shown. */ get nodeTypeFilter(): T[]; /** * Get whether nodes without incoming or outgoing links will be shown or not. */ get includeUnlinked(): boolean; /** * Set whether nodes without incoming or outgoing links will be shown or not. * @param value - The value. */ set includeUnlinked(value: boolean); /** * Set a new link filter and update the controller's state. * @param value - The new link filter. */ set linkFilter(value: LinkFilter<T, Node, Link>); /** * Get the current link filter. * @returns - The current link filter. */ get linkFilter(): LinkFilter<T, Node, Link>; /** * Get whether node labels are shown or not. */ get showNodeLabels(): boolean; /** * Set whether node labels will be shown or not. * @param value - The value. */ set showNodeLabels(value: boolean); /** * Get whether link labels are shown or not. */ get showLinkLabels(): boolean; /** * Set whether link labels will be shown or not. * @param value - The value. */ set showLinkLabels(value: boolean); private get effectiveWidth(); private get effectiveHeight(); private get effectiveCenter(); /** * Resize the graph to fit its container. */ resize(): void; /** * Restart the controller. * @param alpha - The alpha value of the controller's simulation after the restart. */ restart(alpha: number): void; /** * Update the node type filter by either including or removing the specified type from the filter. * @param include - Whether the type will be included or removed from the filter. * @param nodeType - The type to be added or removed from the filter. */ filterNodesByType(include: boolean, nodeType: T): void; /** * Shut down the controller's simulation and (optional) automatic resizing. */ shutdown(): void; private initGraph; private onTick; private resetView; private onZoom; private applyZoom; private toggleNodeFocus; private focusNode; private filterGraph; }