@cosmos.gl/graph 2.2.1 → 2.3.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.
- package/.github/dco.yml +4 -0
- package/README.md +7 -7
- package/dist/config.d.ts +16 -0
- package/dist/helper.d.ts +13 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +5777 -5149
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +63 -53
- package/dist/index.min.js.map +1 -1
- package/dist/modules/Points/index.d.ts +5 -0
- package/dist/variables.d.ts +2 -0
- package/package.json +3 -1
- package/src/config.ts +21 -0
- package/src/helper.ts +22 -0
- package/src/index.ts +81 -5
- package/src/modules/Lines/draw-curve-line.frag +2 -1
- package/src/modules/Lines/draw-curve-line.vert +9 -3
- package/src/modules/Lines/index.ts +1 -0
- package/src/modules/Points/draw-highlighted.vert +2 -1
- package/src/modules/Points/draw-points.vert +2 -1
- package/src/modules/Points/index.ts +43 -0
- package/src/stories/2. configuration.mdx +2 -0
- package/src/stories/3. api-reference.mdx +55 -18
- package/src/stories/clusters/worm.ts +22 -1
- package/src/variables.ts +2 -0
package/.github/dco.yml
ADDED
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://
|
|
5
|
-
<source media="(prefers-color-scheme: light)" srcset="https://
|
|
6
|
-
<img align="center" width="225px" alt="cosmos.gl logo" src="https://
|
|
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
|
-
**
|
|
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](
|
|
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
|
-
|
|
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
|
-
-
|
|
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/helper.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as regl } from 'regl';
|
|
2
|
+
import { default as DOMPurify } from 'dompurify';
|
|
2
3
|
export declare const isFunction: <T>(a: T) => boolean;
|
|
3
4
|
export declare const isArray: <T>(a: unknown | T[]) => a is T[];
|
|
4
5
|
export declare const isObject: <T>(a: T) => boolean;
|
|
@@ -9,3 +10,15 @@ export declare function rgbToBrightness(r: number, g: number, b: number): number
|
|
|
9
10
|
export declare function readPixels(reglInstance: regl.Regl, fbo: regl.Framebuffer2D): Float32Array;
|
|
10
11
|
export declare function clamp(num: number, min: number, max: number): number;
|
|
11
12
|
export declare function isNumber(value: number | undefined | null | typeof NaN): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Sanitizes HTML content to prevent XSS attacks using DOMPurify
|
|
15
|
+
*
|
|
16
|
+
* This function is used internally to sanitize HTML content before setting innerHTML,
|
|
17
|
+
* such as in attribution text. It uses a safe default configuration that allows
|
|
18
|
+
* only common safe HTML elements and attributes.
|
|
19
|
+
*
|
|
20
|
+
* @param html The HTML string to sanitize
|
|
21
|
+
* @param options Optional DOMPurify configuration options to override defaults
|
|
22
|
+
* @returns Sanitized HTML string safe for innerHTML usage
|
|
23
|
+
*/
|
|
24
|
+
export declare function sanitizeHtml(html: string, options?: DOMPurify.Config): string;
|
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
|
*
|
|
@@ -332,6 +360,13 @@ export declare class Graph {
|
|
|
332
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.
|
|
333
361
|
*/
|
|
334
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[];
|
|
335
370
|
/**
|
|
336
371
|
* For the points that are currently visible on the screen, get a sample of point indices with their coordinates.
|
|
337
372
|
* The resulting number of points will depend on the `pointSamplingDistance` configuration property,
|
|
@@ -339,6 +374,16 @@ export declare class Graph {
|
|
|
339
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.
|
|
340
375
|
*/
|
|
341
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
|
+
};
|
|
342
387
|
/**
|
|
343
388
|
* Gets the X-axis of rescaling function.
|
|
344
389
|
*
|