@cosmos.gl/graph 2.7.0-beta.1 → 2.7.0-beta.3

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 (41) hide show
  1. package/dist/{index-B1_1MjaX.js → index-u8g06ZrC.js} +14137 -14174
  2. package/dist/index-u8g06ZrC.js.map +1 -0
  3. package/dist/index.js +11 -10
  4. package/dist/index.min.js +59 -74
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/{config.d.ts → src/config.d.ts} +0 -16
  7. package/dist/{helper.d.ts → src/helper.d.ts} +10 -0
  8. package/dist/{index.d.ts → src/index.d.ts} +33 -1
  9. package/dist/{modules → src/modules}/Clusters/index.d.ts +6 -4
  10. package/dist/{modules → src/modules}/ForceCenter/index.d.ts +5 -4
  11. package/dist/{modules → src/modules}/ForceGravity/index.d.ts +5 -2
  12. package/dist/{modules → src/modules}/ForceLink/index.d.ts +5 -2
  13. package/dist/{modules → src/modules}/ForceManyBody/index.d.ts +5 -4
  14. package/dist/{modules → src/modules}/ForceMouse/index.d.ts +5 -2
  15. package/dist/{modules → src/modules}/Lines/index.d.ts +5 -0
  16. package/dist/{modules → src/modules}/Points/index.d.ts +4 -4
  17. package/dist/src/modules/Shared/buffer.d.ts +1 -0
  18. package/dist/src/modules/Shared/texture-utils.d.ts +8 -0
  19. package/dist/src/modules/Shared/uniform-utils.d.ts +11 -0
  20. package/dist/{modules → src/modules}/Store/index.d.ts +7 -1
  21. package/dist/{variables.d.ts → src/variables.d.ts} +0 -2
  22. package/dist/vite.config.d.ts +2 -0
  23. package/dist/{webgl-device-DzkMihDq.js → webgl-device-BeV8-7_B.js} +204 -194
  24. package/dist/webgl-device-BeV8-7_B.js.map +1 -0
  25. package/package.json +7 -7
  26. package/dist/index-B1_1MjaX.js.map +0 -1
  27. package/dist/modules/ForceManyBody/quadtree-frag-shader.d.ts +0 -1
  28. package/dist/modules/ForceManyBodyQuadtree/index.d.ts +0 -15
  29. package/dist/modules/ForceManyBodyQuadtree/quadtree-frag-shader.d.ts +0 -1
  30. package/dist/modules/Shared/buffer.d.ts +0 -8
  31. package/dist/webgl-device-DzkMihDq.js.map +0 -1
  32. /package/dist/{graph → src/graph}/utils/error-message.d.ts +0 -0
  33. /package/dist/{modules → src/modules}/Drag/index.d.ts +0 -0
  34. /package/dist/{modules → src/modules}/FPSMonitor/css.d.ts +0 -0
  35. /package/dist/{modules → src/modules}/FPSMonitor/index.d.ts +0 -0
  36. /package/dist/{modules → src/modules}/ForceLink/force-spring.d.ts +0 -0
  37. /package/dist/{modules → src/modules}/GraphData/index.d.ts +0 -0
  38. /package/dist/{modules → src/modules}/Lines/geometry.d.ts +0 -0
  39. /package/dist/{modules → src/modules}/Points/atlas-utils.d.ts +0 -0
  40. /package/dist/{modules → src/modules}/Zoom/index.d.ts +0 -0
  41. /package/dist/{modules → src/modules}/core-module.d.ts +0 -0
@@ -213,13 +213,6 @@ export interface GraphConfigInterface {
213
213
  * Default value: `0.25`
214
214
  */
215
215
  linkVisibilityMinTransparency?: number;
216
- /**
217
- * Use the classic quadtree algorithm for the Many-Body force.
218
- * This property will be applied only on component initialization and it
219
- * can't be changed using the `setConfig` method.
220
- * Default value: `false`
221
- */
222
- useClassicQuadtree?: boolean;
223
216
  /**
224
217
  * Decay coefficient. Use smaller values if you want the simulation to "cool down" slower.
225
218
  * Default value: `5000`
@@ -242,16 +235,9 @@ export interface GraphConfigInterface {
242
235
  simulationRepulsion?: number;
243
236
  /**
244
237
  * Decreases / increases the detalization of the Many-Body force calculations.
245
- * When `useClassicQuadtree` is set to `true`, this property corresponds to the Barnes–Hut approximation criterion.
246
238
  * Default value: `1.15`
247
239
  */
248
240
  simulationRepulsionTheta?: number;
249
- /**
250
- * Barnes–Hut approximation depth.
251
- * Can only be used when `useClassicQuadtree` is set `true`.
252
- * Default value: `12`
253
- */
254
- simulationRepulsionQuadtreeLevels?: number;
255
241
  /**
256
242
  * Link spring force coefficient.
257
243
  * Default value: `1`
@@ -588,13 +574,11 @@ export declare class GraphConfig implements GraphConfigInterface {
588
574
  scaleLinksOnZoom: boolean;
589
575
  linkVisibilityDistanceRange: number[];
590
576
  linkVisibilityMinTransparency: number;
591
- useClassicQuadtree: boolean;
592
577
  simulationDecay: number;
593
578
  simulationGravity: number;
594
579
  simulationCenter: number;
595
580
  simulationRepulsion: number;
596
581
  simulationRepulsionTheta: number;
597
- simulationRepulsionQuadtreeLevels: number;
598
582
  simulationLinkSpring: number;
599
583
  simulationLinkDistance: number;
600
584
  simulationLinkDistRandomVariationRange: number[];
@@ -43,8 +43,18 @@ export declare function rgbToBrightness(r: number, g: number, b: number): number
43
43
  * - Consider batching the migration to avoid inconsistencies
44
44
  *
45
45
  * Current status: Deprecated but still functional. Keeping for now until full migration can be planned.
46
+ *
47
+ * @note Cosmos currently supports WebGL only; support for other device types will be added later.
46
48
  */
47
49
  export declare function readPixels(device: Device, fbo: Framebuffer, sourceX?: number, sourceY?: number, sourceWidth?: number, sourceHeight?: number): Float32Array;
50
+ /**
51
+ * Returns the maximum point size supported by the device, scaled by pixel ratio.
52
+ * For WebGL devices, reads the limit from the context; for other device types, uses MAX_POINT_SIZE from Store.
53
+ * @param device - The luma.gl device
54
+ * @param pixelRatio - Device pixel ratio to scale the result
55
+ * @returns Maximum point size (device limit / pixelRatio)
56
+ */
57
+ export declare function getMaxPointSize(device: Device, pixelRatio: number): number;
48
58
  export declare function clamp(num: number, min: number, max: number): number;
49
59
  export declare function isNumber(value: number | undefined | null | typeof NaN): boolean;
50
60
  /**
@@ -1,13 +1,21 @@
1
+ import { Device } from '@luma.gl/core';
1
2
  import { GraphConfig, GraphConfigInterface } from './config';
2
3
  import { GraphData } from './modules/GraphData';
3
4
  export declare class Graph {
4
5
  config: GraphConfig;
5
6
  graph: GraphData;
7
+ /** Canvas element, assigned asynchronously during device initialization */
6
8
  private canvas;
7
9
  private attributionDivElement;
8
10
  private canvasD3Selection;
9
11
  private device;
10
12
  private deviceInitPromise;
13
+ /**
14
+ * Tracks whether this Graph instance owns the device and should destroy it on cleanup.
15
+ * Set to `true` when Graph creates its own device, `false` when using an external device.
16
+ * When `false`, the external device lifecycle is managed by the user.
17
+ */
18
+ private shouldDestroyDevice;
11
19
  private requestAnimationFrameId;
12
20
  private isRightClickMouse;
13
21
  private store;
@@ -33,6 +41,21 @@ export declare class Graph {
33
41
  * If the mouse is not on the Canvas, the `findHoveredPoint` or `findHoveredLine` method will not be executed.
34
42
  */
35
43
  private _isMouseOnCanvas;
44
+ /**
45
+ * Last mouse position for detecting significant mouse movement
46
+ */
47
+ private _lastMouseX;
48
+ private _lastMouseY;
49
+ /**
50
+ * Last checked mouse position for hover detection
51
+ */
52
+ private _lastCheckedMouseX;
53
+ private _lastCheckedMouseY;
54
+ /**
55
+ * Force hover detection on next frame, bypassing mouse movement check.
56
+ * Set when scene changes but mouse stays still (after simulation or zoom ends).
57
+ */
58
+ private _shouldForceHoverDetection;
36
59
  /**
37
60
  * After setting data and render graph at a first time, the fit logic will run
38
61
  * */
@@ -53,7 +76,7 @@ export declare class Graph {
53
76
  private isForceCenterUpdateNeeded;
54
77
  private isPointImageSizesUpdateNeeded;
55
78
  private _isDestroyed;
56
- constructor(div: HTMLDivElement, config?: GraphConfigInterface);
79
+ constructor(div: HTMLDivElement, config?: GraphConfigInterface, devicePromise?: Promise<Device>);
57
80
  /**
58
81
  * Returns the current simulation progress
59
82
  */
@@ -518,6 +541,15 @@ export declare class Graph {
518
541
  * @returns true if device was not ready and operation was queued, false if device is ready
519
542
  */
520
543
  private ensureDevice;
544
+ /**
545
+ * Validates that a device has the required HTMLCanvasElement canvas context.
546
+ * Cosmos requires an HTMLCanvasElement canvas context and does not support
547
+ * OffscreenCanvas or compute-only devices.
548
+ * @param device - The device to validate
549
+ * @returns The validated canvas context (guaranteed to be non-null and HTMLCanvasElement type)
550
+ * @throws Error if the device does not meet Cosmos requirements
551
+ */
552
+ private validateDevice;
521
553
  /**
522
554
  * Internal device creation method
523
555
  * Graph class decides what device to create with sensible defaults
@@ -1,9 +1,8 @@
1
- import { Framebuffer, RenderPass } from '@luma.gl/core';
1
+ import { Framebuffer } from '@luma.gl/core';
2
2
  import { CoreModule } from '../core-module';
3
3
  export declare class Clusters extends CoreModule {
4
4
  centermassFbo: Framebuffer | undefined;
5
5
  clusterCount: number | undefined;
6
- private clearCentermassCommand;
7
6
  private calculateCentermassCommand;
8
7
  private applyForcesCommand;
9
8
  private clusterTexture;
@@ -12,7 +11,6 @@ export declare class Clusters extends CoreModule {
12
11
  private centermassTexture;
13
12
  private pointIndices;
14
13
  private clustersTextureSize;
15
- private clearCentermassVertexCoordBuffer;
16
14
  private applyForcesVertexCoordBuffer;
17
15
  private previousPointsTextureSize;
18
16
  private previousClustersTextureSize;
@@ -22,6 +20,10 @@ export declare class Clusters extends CoreModule {
22
20
  create(): void;
23
21
  initPrograms(): void;
24
22
  calculateCentermass(): void;
25
- run(renderPass?: RenderPass): void;
23
+ run(): void;
24
+ /**
25
+ * Destruction order matters
26
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
27
+ */
26
28
  destroy(): void;
27
29
  }
@@ -1,19 +1,20 @@
1
- import { RenderPass } from '@luma.gl/core';
2
1
  import { CoreModule } from '../core-module';
3
2
  export declare class ForceCenter extends CoreModule {
4
3
  private centermassTexture;
5
4
  private centermassFbo;
6
5
  private pointIndices;
7
- private clearCentermassCommand;
8
6
  private calculateCentermassCommand;
9
7
  private runCommand;
10
- private clearVertexCoordBuffer;
11
8
  private forceVertexCoordBuffer;
12
9
  private calculateUniformStore;
13
10
  private forceUniformStore;
14
11
  private previousPointsTextureSize;
15
12
  create(): void;
16
13
  initPrograms(): void;
17
- run(renderPass?: RenderPass): void;
14
+ run(): void;
15
+ /**
16
+ * Destruction order matters
17
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
18
+ */
18
19
  destroy(): void;
19
20
  }
@@ -1,10 +1,13 @@
1
- import { RenderPass } from '@luma.gl/core';
2
1
  import { CoreModule } from '../core-module';
3
2
  export declare class ForceGravity extends CoreModule {
4
3
  private runCommand;
5
4
  private vertexCoordBuffer;
6
5
  private uniformStore;
7
6
  initPrograms(): void;
8
- run(renderPass?: RenderPass): void;
7
+ run(): void;
8
+ /**
9
+ * Destruction order matters
10
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
11
+ */
9
12
  destroy(): void;
10
13
  }
@@ -1,4 +1,3 @@
1
- import { RenderPass } from '@luma.gl/core';
2
1
  import { CoreModule } from '../core-module';
3
2
  export declare enum LinkDirection {
4
3
  OUTGOING = "outgoing",
@@ -20,6 +19,10 @@ export declare class ForceLink extends CoreModule {
20
19
  private randomDistanceTexture;
21
20
  create(direction: LinkDirection): void;
22
21
  initPrograms(): void;
23
- run(renderPass?: RenderPass): void;
22
+ run(): void;
23
+ /**
24
+ * Destruction order matters
25
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
26
+ */
24
27
  destroy(): void;
25
28
  }
@@ -1,15 +1,12 @@
1
- import { RenderPass } from '@luma.gl/core';
2
1
  import { CoreModule } from '../core-module';
3
2
  export declare class ForceManyBody extends CoreModule {
4
3
  private randomValuesTexture;
5
4
  private pointIndices;
6
5
  private levels;
7
6
  private levelTargets;
8
- private clearLevelsCommand;
9
7
  private calculateLevelsCommand;
10
8
  private forceCommand;
11
9
  private forceFromItsOwnCentermassCommand;
12
- private clearLevelsVertexCoordBuffer;
13
10
  private forceVertexCoordBuffer;
14
11
  private calculateLevelsUniformStore;
15
12
  private forceUniformStore;
@@ -18,7 +15,11 @@ export declare class ForceManyBody extends CoreModule {
18
15
  private previousSpaceSize;
19
16
  create(): void;
20
17
  initPrograms(): void;
21
- run(renderPass?: RenderPass): void;
18
+ run(): void;
19
+ /**
20
+ * Destruction order matters
21
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
22
+ */
22
23
  destroy(): void;
23
24
  private drawLevels;
24
25
  private drawForces;
@@ -1,10 +1,13 @@
1
- import { RenderPass } from '@luma.gl/core';
2
1
  import { CoreModule } from '../core-module';
3
2
  export declare class ForceMouse extends CoreModule {
4
3
  private runCommand;
5
4
  private vertexCoordBuffer;
6
5
  private uniformStore;
7
6
  initPrograms(): void;
8
- run(renderPass?: RenderPass): void;
7
+ run(): void;
8
+ /**
9
+ * Destruction order matters
10
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
11
+ */
9
12
  destroy(): void;
10
13
  }
@@ -28,4 +28,9 @@ export declare class Lines extends CoreModule {
28
28
  updateArrow(): void;
29
29
  updateCurveLineGeometry(): void;
30
30
  findHoveredLine(): void;
31
+ /**
32
+ * Destruction order matters
33
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
34
+ */
35
+ destroy(): void;
31
36
  }
@@ -33,16 +33,12 @@ export declare class Points extends CoreModule {
33
33
  private findPointsOnAreaSelectionCommand;
34
34
  private findPointsOnPolygonSelectionCommand;
35
35
  private findHoveredPointCommand;
36
- private clearHoveredFboCommand;
37
- private clearSampledPointsFboCommand;
38
36
  private fillSampledPointsFboCommand;
39
37
  private trackPointsCommand;
40
38
  private updatePositionVertexCoordBuffer;
41
39
  private dragPointVertexCoordBuffer;
42
40
  private findPointsOnAreaSelectionVertexCoordBuffer;
43
41
  private findPointsOnPolygonSelectionVertexCoordBuffer;
44
- private clearHoveredFboVertexCoordBuffer;
45
- private clearSampledPointsFboVertexCoordBuffer;
46
42
  private drawHighlightedVertexCoordBuffer;
47
43
  private trackPointsVertexCoordBuffer;
48
44
  private trackedIndices;
@@ -99,6 +95,10 @@ export declare class Points extends CoreModule {
99
95
  positions: number[];
100
96
  };
101
97
  getTrackedPositionsArray(): number[];
98
+ /**
99
+ * Destruction order matters
100
+ * Models -> Framebuffers -> Textures -> UniformStores -> Buffers
101
+ * */
102
102
  destroy(): void;
103
103
  private swapFbo;
104
104
  private rescaleInitialNodePositions;
@@ -0,0 +1 @@
1
+ export declare function createIndexesForBuffer(textureSize: number): Float32Array;
@@ -0,0 +1,8 @@
1
+ import { TextureFormat } from '@luma.gl/core';
2
+ /**
3
+ * Calculates bytesPerRow for texture uploads.
4
+ * @param format - Texture format
5
+ * @param width - Texture width in pixels
6
+ * @returns bytesPerRow in bytes
7
+ */
8
+ export declare function getBytesPerRow(format: TextureFormat, width: number): number;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Validates and normalizes array values to fixed-size tuples for shader uniforms.
3
+ */
4
+ /**
5
+ * Ensures a value is a vec2 tuple [number, number].
6
+ */
7
+ export declare function ensureVec2(arr: number[] | undefined, fallback: [number, number]): [number, number];
8
+ /**
9
+ * Ensures a value is a vec4 tuple [number, number, number, number].
10
+ */
11
+ export declare function ensureVec4(arr: number[] | undefined, fallback: [number, number, number, number]): [number, number, number, number];
@@ -8,6 +8,11 @@ export declare const MAX_POINT_SIZE = 64;
8
8
  * The `findHoveredItem` method will skip actual detection until this count is reached.
9
9
  */
10
10
  export declare const MAX_HOVER_DETECTION_DELAY = 4;
11
+ /**
12
+ * Minimum mouse movement threshold (in pixels) to trigger hover detection.
13
+ * If the mouse moves less than this distance, hover detection will be skipped to save performance.
14
+ */
15
+ export declare const MIN_MOUSE_MOVEMENT_THRESHOLD = 2;
11
16
  export type Hovered = {
12
17
  index: number;
13
18
  position: [number, number];
@@ -19,7 +24,7 @@ type Focused = {
19
24
  * Type alias for a 4x4 matrix stored as a 16-element array in column-major order.
20
25
  * Used for std140 uniform buffer layout compatibility.
21
26
  */
22
- type Mat4Array = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number];
27
+ export type Mat4Array = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number];
23
28
  export declare class Store {
24
29
  pointsTextureSize: number;
25
30
  linksTextureSize: number;
@@ -147,6 +152,7 @@ export declare class Store {
147
152
  /**
148
153
  * If the config parameter `spaceSize` exceeds the limits of WebGL,
149
154
  * it reduces the space size without changing the config parameter.
155
+ * Ensures `spaceSize` is always a positive number >= 2 (required for Math.log2).
150
156
  */
151
157
  adjustSpaceSize(configSpaceSize: number, webglMaxTextureSize: number): void;
152
158
  /**
@@ -30,14 +30,12 @@ export declare const defaultConfigValues: {
30
30
  hoveredLinkWidthIncrease: number;
31
31
  focusedPointRingColor: string;
32
32
  focusedPointIndex: undefined;
33
- useClassicQuadtree: boolean;
34
33
  simulation: {
35
34
  decay: number;
36
35
  gravity: number;
37
36
  center: number;
38
37
  repulsion: number;
39
38
  repulsionTheta: number;
40
- repulsionQuadtreeLevels: number;
41
39
  linkSpring: number;
42
40
  linkDistance: number;
43
41
  linkDistRandomVariationRange: number[];
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vite').UserConfigFnObject;
2
+ export default _default;