note-graph
Version:
a generic visualization tool designed to show the structure of the document space and the relations between each doc
75 lines (74 loc) • 3.18 kB
TypeScript
import { ForceGraphInstance, LinkObject, NodeObject } from 'force-graph';
import { NodeId, GraphViewModel, GraphViewData } from './type';
import { NoteGraphModel } from './note-graph-model';
import { RecursivePartial } from './util';
import { GraphViewStyle } from './theme';
export declare type LinkState = 'regular' | 'lessened' | 'highlighted';
export declare type NodeState = 'regular' | 'lessened' | 'highlighted';
interface GraphModelActions {
selectNode(model: GraphViewModel, id: NodeId | null | undefined, isAppend?: boolean): void;
highlightNode(model: GraphViewModel, id: NodeId | undefined): void;
}
declare type InteractionCallbackName = 'nodeClick' | 'linkClick' | 'backgroundClick' | 'backgroundRightClick';
export declare type GraphViewOptions = {
container: HTMLElement;
lazyInitView?: boolean;
graphModel?: NoteGraphModel;
style?: RecursivePartial<GraphViewStyle>;
width?: number;
height?: number;
enableNodeDrag?: boolean;
enableSmartZooming?: boolean;
};
/**
* The view of the graph.
* Wraps a d3 force-graph inside
*/
export declare class NoteGraphView {
options: GraphViewOptions;
container: HTMLElement;
forceGraph: ForceGraphInstance;
model: GraphViewModel;
style: GraphViewStyle;
private hasEngineStopped;
private engineStopSizingFn;
protected sizeScaler: import("d3-scale").ScaleLinear<number, number, never>;
protected labelAlphaScaler: import("d3-scale").ScaleLinear<number, number, never>;
protected currentDataModelEntry?: {
graphModel: NoteGraphModel;
unsub: () => void;
};
protected interactionCallbacks: Partial<Record<InteractionCallbackName, Array<(event: any) => void>>>;
protected hasInitialZoomToFit: boolean;
actions: GraphModelActions;
constructor(opts: GraphViewOptions);
protected initStyle(): void;
updateStyle(style: RecursivePartial<GraphViewStyle>): void;
refreshByStyle(): void;
linkWithGraphModel(graphModel: NoteGraphModel): void;
protected getColorOnContainer(name: any, fallback: any): string;
updateViewData(dataInput: GraphViewData): void;
updateCanvasSize(size: Partial<{
width: number;
height: number;
}>): void;
protected shouldDebugColor: boolean;
initView(): void;
protected initGraphSmartZooming(forceGraph: ForceGraphInstance): void;
protected getLinkNodeId(v: LinkObject['source']): string | number | NodeObject;
protected getNodeState(nodeId: any, model?: GraphViewModel): NodeState;
protected getLinkState(link: any, model?: GraphViewModel): LinkState;
protected getLinkColor(link: LinkObject, model: GraphViewModel): any;
protected updateViewModeInteractiveState(): void;
/**
* Select nodes to gain more initial attention
*/
setSelectedNodes(nodeIds: NodeId[], opts?: {
isAppend?: boolean;
shouldZoomToFit?: boolean;
}): void;
onInteraction(name: InteractionCallbackName, cb: any): () => void;
fireInteraction(name: InteractionCallbackName, payload: any): void;
dispose(): void;
}
export {};