d3-graph-controller
Version:
A TypeScript library for visualizing and simulating directed, interactive graphs.
67 lines (66 loc) • 2.46 kB
text/typescript
import { Callbacks } from './callbacks.mjs';
import { InitialGraphSettings } from './initial.mjs';
import { MarkerConfig } from './marker.mjs';
import { Modifiers } from './modifiers.mjs';
import { PositionInitializer } from './position.mjs';
import { SimulationConfig } from './simulation.mjs';
import { ZoomConfig } from './zoom.mjs';
import { NodeTypeToken } from '../model/graph.mjs';
import { GraphLink } from '../model/link.mjs';
import { GraphNode } from '../model/node.mjs';
export interface GraphConfig<T extends NodeTypeToken, Node extends GraphNode<T>, Link extends GraphLink<T, Node>> {
/**
* Set to true to enable automatic resizing.
* Warning: Do call shutdown(), once the controller is no longer required.
*/
readonly autoResize: boolean;
/**
* Callback configuration.
*/
readonly callbacks: Callbacks<T, Node>;
readonly hooks: {
afterZoom?: (scale: number, xOffset: number, yOffset: number) => void;
};
/**
* Initial settings of a controller.
*/
readonly initial: InitialGraphSettings<T, Node, Link>;
/**
* Marker configuration.
*/
readonly marker: MarkerConfig;
/**
* Low-level callbacks for modifying the underlying d3-selection.
*/
readonly modifiers: Modifiers<T, Node, Link>;
/**
* Define the radius of a node for the simulation and visualization.
* Can be a static number or a function receiving a node as its parameter.
*/
readonly nodeRadius: number | ((node: Node) => number);
/**
* Initializes a node's position in context of a graph's width and height.
*/
readonly positionInitializer: PositionInitializer<T, Node>;
/**
* Simulation configuration.
*/
readonly simulation: SimulationConfig<T, Node, Link>;
/**
* Zoom configuration.
*/
readonly zoom: ZoomConfig;
}
/**
* Utility type for deeply partial objects.
*/
export type DeepPartial<T> = {
readonly [P in keyof T]?: DeepPartial<T[P]>;
};
/**
* Define the configuration of a controller.
* Will be merged with the default configuration.
* @param config - The partial configuration.
* @returns The merged configuration.
*/
export declare function defineGraphConfig<T extends NodeTypeToken = NodeTypeToken, Node extends GraphNode<T> = GraphNode<T>, Link extends GraphLink<T, Node> = GraphLink<T, Node>>(config?: DeepPartial<GraphConfig<T, Node, Link>>): GraphConfig<T, Node, Link>;