3d-force-graph.d.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { WebGLRendererParameters, Renderer, Scene, Camera, WebGLRenderer } from 'three';
  2. import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
  3. import { ThreeForceGraphGeneric } from 'three-forcegraph';
  4. interface ConfigOptions {
  5. controlType?: 'trackball' | 'orbit' | 'fly'
  6. rendererConfig?: WebGLRendererParameters,
  7. extraRenderers?: Renderer[]
  8. }
  9. type Accessor<In, Out> = Out | string | ((obj: In) => Out);
  10. type ObjAccessor<T> = Accessor<object, T>;
  11. type Coords = { x: number; y: number; z: number; };
  12. // don't surface these internal props from inner ThreeForceGraph
  13. type ExcludedInnerProps = 'onLoading' | 'onFinishLoading' | 'onUpdate' | 'onFinishUpdate' | 'tickFrame' | 'd3AlphaTarget';
  14. interface ForceGraph3DGenericInstance<ChainableInstance>
  15. extends Omit<ThreeForceGraphGeneric<ChainableInstance>, ExcludedInnerProps> {
  16. (element: HTMLElement): ChainableInstance;
  17. _destructor(): void;
  18. // Container layout
  19. width(): number;
  20. width(width: number): ChainableInstance;
  21. height(): number;
  22. height(height: number): ChainableInstance;
  23. backgroundColor(): string;
  24. backgroundColor(color: string): ChainableInstance;
  25. showNavInfo(): boolean;
  26. showNavInfo(enabled: boolean): ChainableInstance;
  27. // Labels
  28. nodeLabel(): ObjAccessor<string>;
  29. nodeLabel(textAccessor: ObjAccessor<string>): ChainableInstance;
  30. linkLabel(): ObjAccessor<string>;
  31. linkLabel(textAccessor: ObjAccessor<string>): ChainableInstance;
  32. // Interaction
  33. onNodeClick(callback: (node: object, event: MouseEvent) => void): ChainableInstance;
  34. onNodeRightClick(callback: (node: object, event: MouseEvent) => void): ChainableInstance;
  35. onNodeHover(callback: (node: object | null, previousNode: object | null) => void): ChainableInstance;
  36. onNodeDrag(callback: (node: object, translate: Coords) => void): ChainableInstance;
  37. onNodeDragEnd(callback: (node: object, translate: Coords) => void): ChainableInstance;
  38. onLinkClick(callback: (link: object, event: MouseEvent) => void): ChainableInstance;
  39. onLinkRightClick(callback: (link: object, event: MouseEvent) => void): ChainableInstance;
  40. onLinkHover(callback: (link: object | null, previousLink: object | null) => void): ChainableInstance;
  41. onBackgroundClick(callback: (event: MouseEvent) => void): ChainableInstance;
  42. onBackgroundRightClick(callback: (event: MouseEvent) => void): ChainableInstance;
  43. linkHoverPrecision(): number;
  44. linkHoverPrecision(precision: number): ChainableInstance;
  45. enablePointerInteraction(): boolean;
  46. enablePointerInteraction(enable: boolean): ChainableInstance;
  47. enableNodeDrag(): boolean;
  48. enableNodeDrag(enable: boolean): ChainableInstance;
  49. enableNavigationControls(): boolean;
  50. enableNavigationControls(enable: boolean): ChainableInstance;
  51. // Render control
  52. pauseAnimation(): ChainableInstance;
  53. resumeAnimation(): ChainableInstance;
  54. cameraPosition(): Coords;
  55. cameraPosition(position: Partial<Coords>, lookAt?: Coords, transitionMs?: number): ChainableInstance;
  56. zoomToFit(durationMs?: number, padding?: number, nodeFilter?: (node: object) => boolean): ChainableInstance;
  57. postProcessingComposer(): EffectComposer;
  58. scene(): Scene;
  59. camera(): Camera;
  60. renderer(): WebGLRenderer;
  61. controls(): object;
  62. // Utility
  63. graph2ScreenCoords(x: number, y: number, z: number): Coords;
  64. screen2GraphCoords(screenX: number, screenY: number, distance: number): Coords;
  65. }
  66. type ForceGraph3DInstance = ForceGraph3DGenericInstance<ForceGraph3DInstance>;
  67. declare function ForceGraph3D(configOptions?: ConfigOptions): ForceGraph3DInstance;
  68. export default ForceGraph3D;
  69. export { ConfigOptions, ForceGraph3DGenericInstance, ForceGraph3DInstance };