@yggy-tech/graphraum 0.35.0 → 0.37.0

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +146 -1
  2. package/dist/index.js +1036 -15
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -80,6 +80,42 @@ interface GraphraumSetDataOptions {
80
80
  */
81
81
  fit?: boolean;
82
82
  }
83
+ type GraphraumNodeDragPhase = "start" | "move" | "end" | "cancel";
84
+ /** One step of a node drag. `cancel` carries the position the node was restored to (or left at). */
85
+ interface GraphraumNodeDragEvent {
86
+ nodeId: string;
87
+ phase: GraphraumNodeDragPhase;
88
+ position: GraphraumPosition;
89
+ }
90
+ interface GraphraumNodeDragOptions {
91
+ enabled: boolean;
92
+ }
93
+ interface GraphraumCameraPoint3d {
94
+ x: number;
95
+ y: number;
96
+ z: number;
97
+ }
98
+ /**
99
+ * A 2D view: where the camera looks and how much of the world it shows from top to bottom. The
100
+ * visible width follows the canvas aspect, so a state read on one canvas size fits another.
101
+ */
102
+ interface GraphraumCameraState2d {
103
+ center: {
104
+ x: number;
105
+ y: number;
106
+ };
107
+ mode: "2d";
108
+ /** World units from the top to the bottom edge of the canvas, with the current zoom applied. */
109
+ visibleHeight: number;
110
+ }
111
+ /** A 3D view: the camera position and the point it orbits and looks at. */
112
+ interface GraphraumCameraState3d {
113
+ mode: "3d";
114
+ position: GraphraumCameraPoint3d;
115
+ target: GraphraumCameraPoint3d;
116
+ }
117
+ /** The camera pose as plain JSON, for saving a view and restoring it with `setCameraState()`. */
118
+ type GraphraumCameraState = GraphraumCameraState2d | GraphraumCameraState3d;
83
119
  interface GraphraumDataPatch<NodeAttributes = undefined, EdgeAttributes = undefined> {
84
120
  addedNodes?: readonly GraphraumNode<NodeAttributes>[];
85
121
  addedEdges?: readonly GraphraumEdge<EdgeAttributes>[];
@@ -240,8 +276,60 @@ type GraphraumPickHit = {
240
276
  kind: "node";
241
277
  id: string;
242
278
  };
279
+ /** `linear`, cubic `easeIn` / `easeOut` / `easeInOut`, or a function from progress 0..1 to eased 0..1. */
280
+ type GraphraumEasing = "easeIn" | "easeInOut" | "easeOut" | "linear" | ((t: number) => number);
281
+ /** How depth of field animates focus moves and blur fades. */
282
+ interface GraphraumDepthOfFieldTransition {
283
+ /** Default 400; 0 jumps. `prefers-reduced-motion: reduce` always jumps. */
284
+ durationMs?: number;
285
+ /** Default `"easeInOut"`. */
286
+ easing?: GraphraumEasing;
287
+ }
288
+ /**
289
+ * Opt-in 3D depth of field. The focal plane follows the selection, so selected nodes stay sharp and
290
+ * the rest of the graph blurs with its distance from them, in front and behind, like a thin lens:
291
+ * the closer the camera is to the focus, the shallower the depth of field. A no-op in 2D. See
292
+ * `Graphraum.setDepthOfField`.
293
+ */
294
+ interface GraphraumDepthOfFieldOptions {
295
+ /** Default `false`. While disabled no extra passes or render targets exist. Toggling fades the blur. */
296
+ enabled?: boolean;
297
+ /**
298
+ * `"selection"` (default) focuses the mean position of the selected nodes and fades the blur out
299
+ * when nothing is selected. A number fixes the focal plane at that camera distance in world units.
300
+ */
301
+ focus?: "selection" | number;
302
+ /**
303
+ * Aperture, 0..1, default 0.5. A surface blurs by `strength * 24 * |d - f| / d` CSS pixels, where
304
+ * `d` is its camera distance and `f` the focal distance, clamped to `maxBlur`.
305
+ */
306
+ strength?: number;
307
+ /** Largest blur radius in CSS pixels. Default 12. */
308
+ maxBlur?: number;
309
+ /** Blur radii below this many CSS pixels render sharp, which widens the in-focus band. Default 0. */
310
+ minBlur?: number;
311
+ /** Camera-to-focus distance in world units up to which `strength` applies fully. Default 0. */
312
+ nearDistance?: number;
313
+ /** Camera-to-focus distance in world units at which the blur has faded out. Default `Infinity` (no fade). */
314
+ farDistance?: number;
315
+ /** Animation for focus moves between selections and for blur fades. */
316
+ transition?: GraphraumDepthOfFieldTransition;
317
+ }
318
+ /** Options for one `Graphraum.setDepthOfField` call. */
319
+ interface GraphraumDepthOfFieldUpdate {
320
+ /** Default `true`: fade the blur to the new strength over the transition. `false` jumps. */
321
+ animate?: boolean;
322
+ }
323
+ /**
324
+ * `off`: disabled. `inactive`: enabled with nothing to blur (2D mode, or no selection with
325
+ * `focus: "selection"`), so frames render directly. `active`: the last frame ran the blur passes.
326
+ * `unsupported`: enabled, but the WebGL context cannot run it, so frames render directly.
327
+ */
328
+ type GraphraumDepthOfFieldStatus = "active" | "inactive" | "off" | "unsupported";
243
329
  interface GraphraumOptions<NodeAttributes = undefined, EdgeAttributes = undefined> {
244
330
  antialias?: boolean;
331
+ /** Opt-in 3D depth of field; off by default. Change it later with `setDepthOfField`. */
332
+ depthOfField?: GraphraumDepthOfFieldOptions;
245
333
  maxVisibleEdges?: number;
246
334
  maxVisibleNodes?: number;
247
335
  maxPixelRatio?: number;
@@ -274,6 +362,7 @@ interface GraphraumDiagnostics {
274
362
  aggregatedNodeClusters: number;
275
363
  autoOrbit: GraphraumAutoOrbitStatus;
276
364
  cpuFrameMilliseconds: number;
365
+ depthOfField: GraphraumDepthOfFieldStatus;
277
366
  gpuFrameMilliseconds: number | null;
278
367
  gpuDrawCalls: number;
279
368
  gpuGeometries: number;
@@ -532,12 +621,23 @@ declare class Graphraum<NodeAttributes = undefined, EdgeAttributes = undefined>
532
621
  /** True only during the orbit's own `controls.update(dt)`; see `handleViewChange`. */
533
622
  private orbitUpdating;
534
623
  private destroyed;
624
+ private canvasWidth;
625
+ private canvasHeight;
535
626
  private cpuFrameMilliseconds;
536
627
  private gpuFrameMilliseconds;
537
628
  private gpuTimer;
538
629
  private readonly viewListeners;
539
630
  private readonly focusListeners;
631
+ private readonly nodeDragListeners;
632
+ private readonly nodeDrag;
540
633
  private lastHoveredNodeId;
634
+ private readonly antialias;
635
+ private depthOfField;
636
+ private readonly depthOfFieldFocus;
637
+ /** Strength actually applied: fades toward `strength` while enabled and toward 0 when disabled. */
638
+ private readonly depthOfFieldStrength;
639
+ private depthOfFieldPass;
640
+ private depthOfFieldStatus;
541
641
  constructor(container: HTMLElement, options?: GraphraumOptions<NodeAttributes, EdgeAttributes>);
542
642
  /** Replaces the whole graph. Fits the camera unless `options.fit` is `false`. */
543
643
  setData(data: GraphraumData<NodeAttributes, EdgeAttributes>, options?: GraphraumSetDataOptions): void;
@@ -596,6 +696,19 @@ declare class Graphraum<NodeAttributes = undefined, EdgeAttributes = undefined>
596
696
  * before enabling it. Throws in 2D mode; `setMode("2d")` turns it off. Does nothing after `destroy()`.
597
697
  */
598
698
  setAutoOrbit(options: GraphraumAutoOrbitOptions | false): void;
699
+ /**
700
+ * Updates 3D depth of field; omitted fields keep their current values. Enabling, disabling and a
701
+ * new `strength` fade the blur over `transition` unless `update.animate` is `false`; a change
702
+ * during a fade continues from the blur shown last. With `focus: "selection"` the focal plane
703
+ * follows the mean position of the selected nodes, re-measured from the camera every frame, and
704
+ * moves over `transition` when the selection changes; with nothing selected the blur fades out.
705
+ * `prefers-reduced-motion: reduce` jumps. Resolves `true` when the blur reaches the new strength
706
+ * and `false` when a later call or `destroy()` interrupts the fade. While it blurs each frame adds
707
+ * three draw calls; disabled, or with nothing to blur, it costs nothing. A no-op in 2D. Picking
708
+ * and DOM overlays are unaffected. Throws for invalid values.
709
+ */
710
+ setDepthOfField(options: GraphraumDepthOfFieldOptions, update?: GraphraumDepthOfFieldUpdate): Promise<boolean>;
711
+ private depthOfFieldTargetStrength;
599
712
  getNodePresentation(nodeId: string): CompiledGraphraumPresentation | null;
600
713
  /** Returns canvas-relative screen coordinates for a node, or null when the node does not exist. */
601
714
  getNodeScreenPosition(nodeId: string): GraphraumScreenPosition | null;
@@ -614,6 +727,16 @@ declare class Graphraum<NodeAttributes = undefined, EdgeAttributes = undefined>
614
727
  createOverlay(options?: GraphraumOverlayOptions): GraphraumOverlay<NodeAttributes, EdgeAttributes>;
615
728
  /** Subscribes to camera and viewport changes. Returns an unsubscribe function. */
616
729
  onViewChange(listener: () => void): () => boolean;
730
+ /**
731
+ * Turns node dragging on or off (default off). A drag starts when the pointer moves past a small
732
+ * tolerance after a press on a node (a finger must rest on the node first, so a swipe still pans
733
+ * the camera), moves the node on a plane facing the camera, and ends on release. Escape or a
734
+ * cancelled pointer put the node back. Not available while the density LOD shows clusters.
735
+ */
736
+ setNodeDrag(options: GraphraumNodeDragOptions): void;
737
+ /** Subscribes to node drag steps (`start`, `move`, `end`, `cancel`). Returns an unsubscribe function. */
738
+ onNodeDrag(listener: (event: GraphraumNodeDragEvent) => void): () => boolean;
739
+ private createNodeDragHost;
617
740
  /** Subscribes to selection and hover changes that affect overlay focus chrome. */
618
741
  onFocusChange(listener: () => void): () => boolean;
619
742
  private notifyFocusChange;
@@ -644,6 +767,20 @@ declare class Graphraum<NodeAttributes = undefined, EdgeAttributes = undefined>
644
767
  * reduce` or a zero duration it jumps. Throws for an invalid duration or distance scale.
645
768
  */
646
769
  flyTo(options: GraphraumFlyToOptions): Promise<boolean>;
770
+ /**
771
+ * The camera pose as plain JSON. 2D reports the centre and the world height the canvas shows; 3D
772
+ * reports the camera position and the point it orbits. Pass it to `setCameraState()` to return
773
+ * to the same view, for example after reloading a saved one.
774
+ */
775
+ getCameraState(): GraphraumCameraState;
776
+ /**
777
+ * Puts the camera on a pose from `getCameraState()` at once, without fitting or animating, and
778
+ * cancels a running `flyTo`. Throws for a state of the other mode (switch with `setMode()` first)
779
+ * or with a non-finite number. 2D keeps the saved height and takes the width from the canvas, so a
780
+ * view saved on one canvas size fits another. 3D derives the clip planes from the pose so the whole
781
+ * graph stays in view. Apply it after the canvas has its size: a 2D resize to a new size refits.
782
+ */
783
+ setCameraState(state: GraphraumCameraState): void;
647
784
  /** Nodes whose id is in `nodeIds`, in graph order; every node when `nodeIds` is omitted. */
648
785
  private nodesWithIds;
649
786
  /** The closest front-view camera that frames `nodes` (issue #124); applies the container aspect. */
@@ -673,6 +810,14 @@ declare class Graphraum<NodeAttributes = undefined, EdgeAttributes = undefined>
673
810
  /** Renders a pending frame now instead of on the next animation frame. */
674
811
  private flushRender;
675
812
  private renderFrame;
813
+ /**
814
+ * Decides whether this frame blurs and records why in the diagnostics status. Returns null to
815
+ * render directly. Requests another frame while a fade or focus move runs; both end on their own.
816
+ */
817
+ private prepareDepthOfField;
818
+ /** Mean world position of the selected nodes, read every frame so a running layout keeps them in focus. */
819
+ private selectionFocusPoint;
820
+ private disposeDepthOfFieldPass;
676
821
  private stopAutoOrbit;
677
822
  /**
678
823
  * One orbit frame. `autoRotate` is on only for this `update(dt)` call: OrbitControls also calls
@@ -860,4 +1005,4 @@ declare function isTransparentGraphraumBackground(background: GraphraumBackgroun
860
1005
  /** Defines typed, serializable graph visuals without coupling application data to the render loop. */
861
1006
  declare function defineVisuals<NodeAttributes = undefined, EdgeAttributes = undefined>(visuals: GraphraumVisualMapper<NodeAttributes, EdgeAttributes>): GraphraumVisualMapper<NodeAttributes, EdgeAttributes>;
862
1007
  //#endregion
863
- export { type CompiledGraphraumPresentation, DEFAULT_ENDPOINT_ATTACH, DEFAULT_ENDPOINT_CLEARANCE, DEFAULT_FORCE_SETTINGS, type EndpointAttach, type EndpointOutline, type ForceLayoutRequest, type ForceSettings, type GraphologyEdgeAttributes, type GraphologyNodeAttributes, type GraphologyRenderer, Graphraum, type GraphraumAutoOrbitOptions, type GraphraumAutoOrbitStatus, type GraphraumBackground, type GraphraumColor, type GraphraumData, type GraphraumDataPatch, type GraphraumDiagnostics, type GraphraumEdge, type GraphraumEdgeEncoding, type GraphraumEdgeMarker, type GraphraumEdgeMarkerEnd, type GraphraumEdgePath, type GraphraumEdgeState, type GraphraumEdgeStyle, type GraphraumEdgeVisual, type GraphraumFlyToOptions, type GraphraumLabelCandidate, type GraphraumLayoutPositions, type GraphraumMode, type GraphraumNode, type GraphraumNodeEncoding, type GraphraumNodeGeometry, type GraphraumNodeShape, type GraphraumNodeState, type GraphraumNodeUpdate, type GraphraumNodeVisual, type GraphraumOptions, GraphraumOverlay, type GraphraumOverlayNode, type GraphraumOverlayOptions, type GraphraumPatternBackground, type GraphraumPickHit, type GraphraumPosition, type GraphraumPresentation, type GraphraumPresentationAction, type GraphraumPresentationProperty, type GraphraumPropertyValue, type GraphraumScreenPosition, type GraphraumSetDataOptions, type GraphraumTheme, type GraphraumThemeName, type GraphraumVisualMapper, type LabelBudgetCandidate, type RichNodePolicy, type SelectBudgetedLabelIdsInput, type SelectFocusLabelIdsInput, attachPointOnOutline, bindGraphology, boundOverlayIds, computeClusteredForcePositions, computeForcePositions, createForceSimulation, defineVisuals, forceIterationCount, graphraumEdgePaths, graphraumNodeShapes, graphraumTheme, graphraumThemeDark, graphraumThemeLight, graphraumThemes, isTransparentGraphraumBackground, normalizeGraphraumBackground, orderFocusNodeIds, resolveGraphraumTheme, selectBudgetedLabelIds, selectFocusLabelIds, selectRichNodeIds, trimEdgeEndpoints };
1008
+ export { type CompiledGraphraumPresentation, DEFAULT_ENDPOINT_ATTACH, DEFAULT_ENDPOINT_CLEARANCE, DEFAULT_FORCE_SETTINGS, type EndpointAttach, type EndpointOutline, type ForceLayoutRequest, type ForceSettings, type GraphologyEdgeAttributes, type GraphologyNodeAttributes, type GraphologyRenderer, Graphraum, type GraphraumAutoOrbitOptions, type GraphraumAutoOrbitStatus, type GraphraumBackground, type GraphraumCameraPoint3d, type GraphraumCameraState, type GraphraumCameraState2d, type GraphraumCameraState3d, type GraphraumColor, type GraphraumData, type GraphraumDataPatch, type GraphraumDepthOfFieldOptions, type GraphraumDepthOfFieldStatus, type GraphraumDepthOfFieldTransition, type GraphraumDepthOfFieldUpdate, type GraphraumDiagnostics, type GraphraumEasing, type GraphraumEdge, type GraphraumEdgeEncoding, type GraphraumEdgeMarker, type GraphraumEdgeMarkerEnd, type GraphraumEdgePath, type GraphraumEdgeState, type GraphraumEdgeStyle, type GraphraumEdgeVisual, type GraphraumFlyToOptions, type GraphraumLabelCandidate, type GraphraumLayoutPositions, type GraphraumMode, type GraphraumNode, type GraphraumNodeDragEvent, type GraphraumNodeDragOptions, type GraphraumNodeDragPhase, type GraphraumNodeEncoding, type GraphraumNodeGeometry, type GraphraumNodeShape, type GraphraumNodeState, type GraphraumNodeUpdate, type GraphraumNodeVisual, type GraphraumOptions, GraphraumOverlay, type GraphraumOverlayNode, type GraphraumOverlayOptions, type GraphraumPatternBackground, type GraphraumPickHit, type GraphraumPosition, type GraphraumPresentation, type GraphraumPresentationAction, type GraphraumPresentationProperty, type GraphraumPropertyValue, type GraphraumScreenPosition, type GraphraumSetDataOptions, type GraphraumTheme, type GraphraumThemeName, type GraphraumVisualMapper, type LabelBudgetCandidate, type RichNodePolicy, type SelectBudgetedLabelIdsInput, type SelectFocusLabelIdsInput, attachPointOnOutline, bindGraphology, boundOverlayIds, computeClusteredForcePositions, computeForcePositions, createForceSimulation, defineVisuals, forceIterationCount, graphraumEdgePaths, graphraumNodeShapes, graphraumTheme, graphraumThemeDark, graphraumThemeLight, graphraumThemes, isTransparentGraphraumBackground, normalizeGraphraumBackground, orderFocusNodeIds, resolveGraphraumTheme, selectBudgetedLabelIds, selectFocusLabelIds, selectRichNodeIds, trimEdgeEndpoints };