@cosmos.gl/graph 2.2.0 → 2.3.0-beta.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 (31) hide show
  1. package/README.md +7 -7
  2. package/dist/config.d.ts +16 -0
  3. package/dist/index.d.ts +68 -7
  4. package/dist/index.js +1989 -1880
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.min.js +64 -55
  7. package/dist/index.min.js.map +1 -1
  8. package/dist/modules/Points/index.d.ts +11 -6
  9. package/dist/stories/clusters/{lasso-selection → polygon-selection}/index.d.ts +1 -1
  10. package/dist/stories/clusters/{lasso-selection/lasso.d.ts → polygon-selection/polygon.d.ts} +5 -5
  11. package/dist/stories/clusters.stories.d.ts +1 -1
  12. package/dist/variables.d.ts +2 -0
  13. package/package.json +1 -1
  14. package/src/config.ts +21 -0
  15. package/src/index.ts +115 -22
  16. package/src/modules/Lines/draw-curve-line.frag +2 -1
  17. package/src/modules/Lines/draw-curve-line.vert +9 -3
  18. package/src/modules/Lines/index.ts +1 -0
  19. package/src/modules/Points/draw-highlighted.vert +2 -1
  20. package/src/modules/Points/draw-points.vert +2 -1
  21. package/src/modules/Points/{find-points-on-lasso-selection.frag → find-points-on-polygon-selection.frag} +8 -8
  22. package/src/modules/Points/index.ts +68 -25
  23. package/src/stories/2. configuration.mdx +2 -0
  24. package/src/stories/3. api-reference.mdx +82 -27
  25. package/src/stories/beginners/basic-set-up/index.ts +1 -1
  26. package/src/stories/clusters/{lasso-selection → polygon-selection}/index.ts +11 -11
  27. package/src/stories/clusters/{lasso-selection/lasso.ts → polygon-selection/polygon.ts} +16 -16
  28. package/src/stories/clusters/{lasso-selection → polygon-selection}/style.css +1 -1
  29. package/src/stories/clusters/worm.ts +22 -1
  30. package/src/stories/clusters.stories.ts +9 -9
  31. package/src/variables.ts +2 -0
package/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
 
2
2
  <p align="center" style="color: #444">
3
3
  <picture>
4
- <source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/1428fb58-c85e-4f9c-8f14-5be2f7c73b16">
5
- <source media="(prefers-color-scheme: light)" srcset="https://github.com/user-attachments/assets/44cdb7c6-2ccd-4ed0-a6c3-e9c4606559f0">
6
- <img align="center" width="225px" alt="cosmos.gl logo" src="https://github.com/user-attachments/assets/1428fb58-c85e-4f9c-8f14-5be2f7c73b16">
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://assets.cosmograph.app/cosmos-dark-theme.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://assets.cosmograph.app/cosmos-light-theme.svg">
6
+ <img align="center" width="225px" alt="cosmos.gl logo" src="https://assets.cosmograph.app/cosmos-light-theme.svg">
7
7
  </picture>
8
8
  </p>
9
9
  <p align="center" style="font-size: 1.2rem;">GPU-accelerated Force Graph</p>
10
10
 
11
- **Cosmos.gl** is a high-performance WebGL Force Graph algorithm and rendering engine. All the computations and drawing occur on the GPU in fragment and vertex shaders, avoiding expensive memory operations. It enables the real-time simulation of network graphs consisting of hundreds of thousands of points and links on modern hardware.
11
+ **cosmos.gl** is a high-performance WebGL Force Graph algorithm and rendering engine. All the computations and drawing occur on the GPU in fragment and vertex shaders, avoiding expensive memory operations. It enables the real-time simulation of network graphs consisting of hundreds of thousands of points and links on modern hardware.
12
12
 
13
- This engine powers 🪐 [Cosmograph](http://cosmograph.app) — a toolset for exploring complex networks and AI embeddings.
13
+ This engine powers 🪐 [Cosmograph](https://cosmograph.app) — a toolset for exploring complex networks and AI embeddings.
14
14
 
15
15
  <video src="https://user-images.githubusercontent.com/755708/173392407-9b05cbb6-d39e-4c2c-ab41-50900cfda823.mp4" autoplay controls alt="Demo of cosmos.gl GPU-accelerated Force Graph">
16
16
  </video>
@@ -77,7 +77,7 @@ graph.render()
77
77
 
78
78
  ### What's New in v2.0?
79
79
 
80
- Cosmos.gl v2.0 introduces significant improvements in performance and data handling:
80
+ cosmos.gl v2.0 introduces significant improvements in performance and data handling:
81
81
 
82
82
  - Enhanced data structures with WebGL-compatible formats.
83
83
  - Methods like `setPointPositions` and `setLinks` replace `setData` for improved efficiency.
@@ -107,7 +107,7 @@ Check the [Migration Guide](./cosmos-2-0-migration-notes.md) for details.
107
107
  ### Known Issues
108
108
 
109
109
  - ~~Starting from version 15.4, iOS has stopped supporting the key WebGL extension powering our Many-Body force implementation (`EXT_float_blend`). We're investigating this issue and exploring solutions.~~ The latest iOS works again!
110
- - Cosmos.gl doesn't work on some Android devices.
110
+ - cosmos.gl doesn't work on Android devices that don't support the `OES_texture_float` WebGL extension.
111
111
 
112
112
 
113
113
  ---
package/dist/config.d.ts CHANGED
@@ -57,6 +57,13 @@ export interface GraphConfigInterface {
57
57
  * Default value: `4`
58
58
  */
59
59
  pointSize?: number;
60
+ /**
61
+ * Universal opacity value applied to all points.
62
+ * This value multiplies with individual point alpha values (if set via setPointColors).
63
+ * Useful for dynamically controlling opacity of all points without updating individual RGBA arrays.
64
+ * Default value: `1.0`
65
+ */
66
+ pointOpacity?: number;
60
67
  /**
61
68
  * Scale factor for the point size.
62
69
  * Default value: `1`
@@ -103,6 +110,13 @@ export interface GraphConfigInterface {
103
110
  * Default value: '#666666'
104
111
  */
105
112
  linkColor?: string | [number, number, number, number];
113
+ /**
114
+ * Universal opacity value applied to all links.
115
+ * This value multiplies with individual link alpha values (if set via setLinkColors).
116
+ * Useful for dynamically controlling opacity of all links without updating individual RGBA arrays.
117
+ * Default value: `1.0`
118
+ */
119
+ linkOpacity?: number;
106
120
  /**
107
121
  * Greyed out link opacity value when the selection is active.
108
122
  * Default value: `0.1`
@@ -468,6 +482,7 @@ export declare class GraphConfig implements GraphConfigInterface {
468
482
  pointGreyoutOpacity: undefined;
469
483
  pointGreyoutColor: undefined;
470
484
  pointSize: number;
485
+ pointOpacity: number;
471
486
  pointSizeScale: number;
472
487
  hoveredPointCursor: string;
473
488
  renderHoveredPointRing: boolean;
@@ -475,6 +490,7 @@ export declare class GraphConfig implements GraphConfigInterface {
475
490
  focusedPointRingColor: string;
476
491
  focusedPointIndex: undefined;
477
492
  linkColor: string;
493
+ linkOpacity: number;
478
494
  linkGreyoutOpacity: number;
479
495
  linkWidth: number;
480
496
  linkWidthScale: number;
package/dist/index.d.ts CHANGED
@@ -87,6 +87,13 @@ export declare class Graph {
87
87
  * Example: `new Float32Array([255, 0, 0, 1, 0, 255, 0, 1])` sets the first point to red and the second point to green.
88
88
  */
89
89
  setPointColors(pointColors: Float32Array): void;
90
+ /**
91
+ * Gets the current colors of the graph points.
92
+ *
93
+ * @returns {Float32Array} A Float32Array representing the colors of points in the format [r1, g1, b1, a1, r2, g2, b2, a2, ..., rn, gn, bn, an],
94
+ * where each color is in RGBA format. Returns an empty Float32Array if no point colors are set.
95
+ */
96
+ getPointColors(): Float32Array;
90
97
  /**
91
98
  * Sets the sizes for the graph points.
92
99
  *
@@ -95,6 +102,13 @@ export declare class Graph {
95
102
  * Example: `new Float32Array([10, 20, 30])` sets the first point to size 10, the second point to size 20, and the third point to size 30.
96
103
  */
97
104
  setPointSizes(pointSizes: Float32Array): void;
105
+ /**
106
+ * Gets the current sizes of the graph points.
107
+ *
108
+ * @returns {Float32Array} A Float32Array representing the sizes of points in the format [size1, size2, ..., sizen],
109
+ * where `n` is the index of the point. Returns an empty Float32Array if no point sizes are set.
110
+ */
111
+ getPointSizes(): Float32Array;
98
112
  /**
99
113
  * Sets the links for the graph.
100
114
  *
@@ -112,6 +126,13 @@ export declare class Graph {
112
126
  * Example: `new Float32Array([255, 0, 0, 1, 0, 255, 0, 1])` sets the first link to red and the second link to green.
113
127
  */
114
128
  setLinkColors(linkColors: Float32Array): void;
129
+ /**
130
+ * Gets the current colors of the graph links.
131
+ *
132
+ * @returns {Float32Array} A Float32Array representing the colors of links in the format [r1, g1, b1, a1, r2, g2, b2, a2, ..., rn, gn, bn, an],
133
+ * where each color is in RGBA format. Returns an empty Float32Array if no link colors are set.
134
+ */
135
+ getLinkColors(): Float32Array;
115
136
  /**
116
137
  * Sets the widths for the graph links.
117
138
  *
@@ -120,6 +141,13 @@ export declare class Graph {
120
141
  * Example: `new Float32Array([1, 2, 3])` sets the first link to width 1, the second link to width 2, and the third link to width 3.
121
142
  */
122
143
  setLinkWidths(linkWidths: Float32Array): void;
144
+ /**
145
+ * Gets the current widths of the graph links.
146
+ *
147
+ * @returns {Float32Array} A Float32Array representing the widths of links in the format [width1, width2, ..., widthn],
148
+ * where `n` is the index of the link. Returns an empty Float32Array if no link widths are set.
149
+ */
150
+ getLinkWidths(): Float32Array;
123
151
  /**
124
152
  * Sets the arrows for the graph links.
125
153
  *
@@ -238,24 +266,40 @@ export declare class Graph {
238
266
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
239
267
  * @returns A Float32Array containing the indices of points inside a rectangular area.
240
268
  */
269
+ getPointsInRect(selection: [[number, number], [number, number]]): Float32Array;
270
+ /**
271
+ * Get points indices inside a rectangular area.
272
+ * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
273
+ * The `left` and `right` coordinates should be from 0 to the width of the canvas.
274
+ * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
275
+ * @returns A Float32Array containing the indices of points inside a rectangular area.
276
+ * @deprecated Use `getPointsInRect` instead. This method will be removed in a future version.
277
+ */
241
278
  getPointsInRange(selection: [[number, number], [number, number]]): Float32Array;
242
279
  /**
243
- * Get points indices inside a lasso (polygon) area.
244
- * @param lassoPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the lasso polygon.
280
+ * Get points indices inside a polygon area.
281
+ * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
245
282
  * The coordinates should be from 0 to the width/height of the canvas.
246
- * @returns A Float32Array containing the indices of points inside the lasso area.
283
+ * @returns A Float32Array containing the indices of points inside the polygon area.
247
284
  */
248
- getPointsInLasso(lassoPath: [number, number][]): Float32Array;
285
+ getPointsInPolygon(polygonPath: [number, number][]): Float32Array;
249
286
  /** Select points inside a rectangular area.
250
287
  * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
251
288
  * The `left` and `right` coordinates should be from 0 to the width of the canvas.
252
289
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas. */
290
+ selectPointsInRect(selection: [[number, number], [number, number]] | null): void;
291
+ /** Select points inside a rectangular area.
292
+ * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
293
+ * The `left` and `right` coordinates should be from 0 to the width of the canvas.
294
+ * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
295
+ * @deprecated Use `selectPointsInRect` instead. This method will be removed in a future version.
296
+ */
253
297
  selectPointsInRange(selection: [[number, number], [number, number]] | null): void;
254
- /** Select points inside a lasso (polygon) area.
255
- * @param lassoPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the lasso polygon.
298
+ /** Select points inside a polygon area.
299
+ * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
256
300
  * The coordinates should be from 0 to the width/height of the canvas.
257
301
  * Set to null to clear selection. */
258
- selectPointsInLasso(lassoPath: [number, number][] | null): void;
302
+ selectPointsInPolygon(polygonPath: [number, number][] | null): void;
259
303
  /**
260
304
  * Select a point by index. If you want the adjacent points to get selected too, provide `true` as the second argument.
261
305
  * @param index The index of the point in the array of points.
@@ -316,6 +360,13 @@ export declare class Graph {
316
360
  * @returns A Map object where keys are the indices of the points and values are their corresponding X and Y coordinates in the [number, number] format.
317
361
  */
318
362
  getTrackedPointPositionsMap(): Map<number, [number, number]>;
363
+ /**
364
+ * Get current X and Y coordinates of the tracked points as an array.
365
+ * @returns Array of point positions in the format [x1, y1, x2, y2, ..., xn, yn] for tracked points only.
366
+ * The positions are ordered by the tracking indices (same order as provided to trackPointPositionsByIndices).
367
+ * Returns an empty array if no points are being tracked.
368
+ */
369
+ getTrackedPointPositionsArray(): number[];
319
370
  /**
320
371
  * For the points that are currently visible on the screen, get a sample of point indices with their coordinates.
321
372
  * The resulting number of points will depend on the `pointSamplingDistance` configuration property,
@@ -323,6 +374,16 @@ export declare class Graph {
323
374
  * @returns A Map object where keys are the index of the points and values are their corresponding X and Y coordinates in the [number, number] format.
324
375
  */
325
376
  getSampledPointPositionsMap(): Map<number, [number, number]>;
377
+ /**
378
+ * For the points that are currently visible on the screen, get a sample of point indices and positions.
379
+ * The resulting number of points will depend on the `pointSamplingDistance` configuration property,
380
+ * and the sampled points will be evenly distributed.
381
+ * @returns An object containing arrays of point indices and positions.
382
+ */
383
+ getSampledPoints(): {
384
+ indices: number[];
385
+ positions: number[];
386
+ };
326
387
  /**
327
388
  * Gets the X-axis of rescaling function.
328
389
  *