3d-force-graph 1.73.4 → 1.73.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -206,7 +206,7 @@ ForceGraph3d({ configOptions })(<domElement>)
206
206
 
207
207
  | Method | Description |
208
208
  | --- | --- |
209
- | <b>getGraphBbox</b>([<i>nodeFilterFn</i>]) | Returns the current bounding box of the nodes in the graph, formatted as `{ x: [<num>, <num>], y: [<num>, <num>], z: [<num>, <num>] }`. If no nodes are found, returns `null`. Accepts an optional argument to define a custom node filter: `node => <boolean>`, which should return a truthy value if the node is to be included. This can be useful to calculate the bounding box of a portion of the graph. ||
209
+ | <b>getGraphBbox</b>([<i>nodeFilterFn</i>]) | Returns the current bounding box of the nodes in the graph, formatted as `{ x: [<num>, <num>], y: [<num>, <num>], z: [<num>, <num>] }`. If no nodes are found, returns `null`. Accepts an optional argument to define a custom node filter: `node => <boolean>`, which should return a truthy value if the node is to be included. This can be useful to calculate the bounding box of a portion of the graph. |
210
210
  | <b>graph2ScreenCoords</b>(<i>x</i>, <i>y</i>, <i>z</i>) | Utility method to translate node coordinates to the viewport domain. Given a set of `x`,`y`,`z` graph coordinates, returns the current equivalent `{x, y}` in viewport coordinates. |
211
211
  | <b>screen2GraphCoords</b>(<i>x</i>, <i>y</i>, <i>distance</i>) | Utility method to translate viewport distance coordinates to the graph domain. Given a pair of `x`,`y` screen coordinates and distance from the camera, returns the current equivalent `{x, y, z}` in the domain of graph node coordinates. |
212
212
 
@@ -1,6 +1,6 @@
1
1
  import { WebGLRendererParameters, Renderer, Light, Scene, Camera, WebGLRenderer } from 'three';
2
2
  import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
3
- import { ThreeForceGraphGeneric } from 'three-forcegraph';
3
+ import { NodeObject, LinkObject, ThreeForceGraphGeneric } from 'three-forcegraph';
4
4
 
5
5
  interface ConfigOptions {
6
6
  controlType?: 'trackball' | 'orbit' | 'fly'
@@ -9,15 +9,15 @@ interface ConfigOptions {
9
9
  }
10
10
 
11
11
  type Accessor<In, Out> = Out | string | ((obj: In) => Out);
12
- type ObjAccessor<T> = Accessor<object, T>;
12
+ type ObjAccessor<T, InT = object> = Accessor<InT, T>;
13
13
 
14
14
  type Coords = { x: number; y: number; z: number; };
15
15
 
16
16
  // don't surface these internal props from inner ThreeForceGraph
17
17
  type ExcludedInnerProps = 'onLoading' | 'onFinishLoading' | 'onUpdate' | 'onFinishUpdate' | 'tickFrame' | 'd3AlphaTarget' | 'resetCountdown';
18
18
 
19
- interface ForceGraph3DGenericInstance<ChainableInstance>
20
- extends Omit<ThreeForceGraphGeneric<ChainableInstance>, ExcludedInnerProps> {
19
+ interface ForceGraph3DGenericInstance<ChainableInstance, N extends NodeObject = NodeObject, L extends LinkObject<N> = LinkObject<N>>
20
+ extends Omit<ThreeForceGraphGeneric<ChainableInstance, N, L>, ExcludedInnerProps> {
21
21
  (element: HTMLElement): ChainableInstance;
22
22
  _destructor(): void;
23
23
 
@@ -32,20 +32,20 @@ interface ForceGraph3DGenericInstance<ChainableInstance>
32
32
  showNavInfo(enabled: boolean): ChainableInstance;
33
33
 
34
34
  // Labels
35
- nodeLabel(): ObjAccessor<string>;
36
- nodeLabel(textAccessor: ObjAccessor<string>): ChainableInstance;
37
- linkLabel(): ObjAccessor<string>;
38
- linkLabel(textAccessor: ObjAccessor<string>): ChainableInstance;
35
+ nodeLabel(): ObjAccessor<string, N>;
36
+ nodeLabel(textAccessor: ObjAccessor<string, N>): ChainableInstance;
37
+ linkLabel(): ObjAccessor<string, L>;
38
+ linkLabel(textAccessor: ObjAccessor<string, L>): ChainableInstance;
39
39
 
40
40
  // Interaction
41
- onNodeClick(callback: (node: object, event: MouseEvent) => void): ChainableInstance;
42
- onNodeRightClick(callback: (node: object, event: MouseEvent) => void): ChainableInstance;
43
- onNodeHover(callback: (node: object | null, previousNode: object | null) => void): ChainableInstance;
44
- onNodeDrag(callback: (node: object, translate: Coords) => void): ChainableInstance;
45
- onNodeDragEnd(callback: (node: object, translate: Coords) => void): ChainableInstance;
46
- onLinkClick(callback: (link: object, event: MouseEvent) => void): ChainableInstance;
47
- onLinkRightClick(callback: (link: object, event: MouseEvent) => void): ChainableInstance;
48
- onLinkHover(callback: (link: object | null, previousLink: object | null) => void): ChainableInstance;
41
+ onNodeClick(callback: (node: N, event: MouseEvent) => void): ChainableInstance;
42
+ onNodeRightClick(callback: (node: N, event: MouseEvent) => void): ChainableInstance;
43
+ onNodeHover(callback: (node: N | null, previousNode: N | null) => void): ChainableInstance;
44
+ onNodeDrag(callback: (node: N, translate: Coords) => void): ChainableInstance;
45
+ onNodeDragEnd(callback: (node: N, translate: Coords) => void): ChainableInstance;
46
+ onLinkClick(callback: (link: L, event: MouseEvent) => void): ChainableInstance;
47
+ onLinkRightClick(callback: (link: L, event: MouseEvent) => void): ChainableInstance;
48
+ onLinkHover(callback: (link: L | null, previousLink: L | null) => void): ChainableInstance;
49
49
  onBackgroundClick(callback: (event: MouseEvent) => void): ChainableInstance;
50
50
  onBackgroundRightClick(callback: (event: MouseEvent) => void): ChainableInstance;
51
51
  linkHoverPrecision(): number;
@@ -62,7 +62,7 @@ interface ForceGraph3DGenericInstance<ChainableInstance>
62
62
  resumeAnimation(): ChainableInstance;
63
63
  cameraPosition(): Coords;
64
64
  cameraPosition(position: Partial<Coords>, lookAt?: Coords, transitionMs?: number): ChainableInstance;
65
- zoomToFit(durationMs?: number, padding?: number, nodeFilter?: (node: object) => boolean): ChainableInstance;
65
+ zoomToFit(durationMs?: number, padding?: number, nodeFilter?: (node: N) => boolean): ChainableInstance;
66
66
  postProcessingComposer(): EffectComposer;
67
67
  lights(): Light[];
68
68
  lights(lights: Light[]): ChainableInstance;
@@ -76,8 +76,8 @@ interface ForceGraph3DGenericInstance<ChainableInstance>
76
76
  screen2GraphCoords(screenX: number, screenY: number, distance: number): Coords;
77
77
  }
78
78
 
79
- type ForceGraph3DInstance = ForceGraph3DGenericInstance<ForceGraph3DInstance>;
79
+ type ForceGraph3DInstance<NodeType = NodeObject, LinkType = LinkObject<NodeType>> = ForceGraph3DGenericInstance<ForceGraph3DInstance<NodeType, LinkType>, NodeType, LinkType>;
80
80
 
81
- declare function ForceGraph3D(configOptions?: ConfigOptions): ForceGraph3DInstance;
81
+ declare function ForceGraph3D<NodeType = NodeObject, LinkType = LinkObject<NodeType>>(configOptions?: ConfigOptions): ForceGraph3DInstance<NodeType, LinkType>;
82
82
 
83
83
  export { type ConfigOptions, type ForceGraph3DGenericInstance, type ForceGraph3DInstance, ForceGraph3D as default };