@cosmos.gl/graph 2.4.0 → 2.6.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 (49) hide show
  1. package/.github/SECURITY.md +7 -1
  2. package/dist/config.d.ts +73 -1
  3. package/dist/index.d.ts +34 -6
  4. package/dist/index.js +4087 -3837
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.min.js +124 -44
  7. package/dist/index.min.js.map +1 -1
  8. package/dist/modules/GraphData/index.d.ts +1 -0
  9. package/dist/modules/Lines/index.d.ts +8 -0
  10. package/dist/modules/Points/index.d.ts +3 -0
  11. package/dist/modules/Store/index.d.ts +14 -2
  12. package/dist/modules/core-module.d.ts +1 -0
  13. package/dist/stories/beginners/link-hovering/data-generator.d.ts +19 -0
  14. package/dist/stories/beginners/link-hovering/index.d.ts +5 -0
  15. package/dist/stories/beginners/pinned-points/data-gen.d.ts +5 -0
  16. package/dist/stories/beginners/pinned-points/index.d.ts +5 -0
  17. package/dist/stories/beginners.stories.d.ts +2 -0
  18. package/dist/variables.d.ts +5 -2
  19. package/package.json +1 -1
  20. package/src/config.ts +95 -3
  21. package/src/index.ts +179 -32
  22. package/src/modules/GraphData/index.ts +2 -1
  23. package/src/modules/Lines/draw-curve-line.frag +12 -1
  24. package/src/modules/Lines/draw-curve-line.vert +29 -2
  25. package/src/modules/Lines/hovered-line-index.frag +27 -0
  26. package/src/modules/Lines/hovered-line-index.vert +8 -0
  27. package/src/modules/Lines/index.ts +112 -2
  28. package/src/modules/Points/index.ts +34 -0
  29. package/src/modules/Points/update-position.frag +12 -0
  30. package/src/modules/Store/index.ts +33 -2
  31. package/src/modules/core-module.ts +1 -0
  32. package/src/stories/1. welcome.mdx +11 -4
  33. package/src/stories/2. configuration.mdx +13 -3
  34. package/src/stories/3. api-reference.mdx +13 -4
  35. package/src/stories/beginners/basic-set-up/index.ts +21 -11
  36. package/src/stories/beginners/link-hovering/data-generator.ts +198 -0
  37. package/src/stories/beginners/link-hovering/index.ts +61 -0
  38. package/src/stories/beginners/link-hovering/style.css +73 -0
  39. package/src/stories/beginners/pinned-points/data-gen.ts +153 -0
  40. package/src/stories/beginners/pinned-points/index.ts +61 -0
  41. package/src/stories/beginners/quick-start.ts +3 -2
  42. package/src/stories/beginners/remove-points/config.ts +1 -1
  43. package/src/stories/beginners/remove-points/index.ts +28 -30
  44. package/src/stories/beginners.stories.ts +31 -0
  45. package/src/stories/clusters/polygon-selection/index.ts +2 -4
  46. package/src/stories/create-cosmos.ts +1 -1
  47. package/src/stories/geospatial/moscow-metro-stations/index.ts +1 -1
  48. package/src/stories/shapes/image-example/index.ts +7 -8
  49. package/src/variables.ts +5 -2
@@ -10,4 +10,10 @@ If you have discovered a security vulnerability in this project, please report i
10
10
 
11
11
  Please disclose it at [security advisory](https://github.com/cosmograph-org/cosmos/security/advisories/new).
12
12
 
13
- This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
13
+ This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
14
+
15
+ ## Escalation
16
+
17
+ If you do not receive an acknowledgement of your report within 6 business days, or if you cannot find a private security contact for the project, you may escalate to the OpenJS Foundation CNA at `security@lists.openjsf.org`.
18
+
19
+ If the project acknowledges your report but does not provide any further response or engagement within 14 days, escalation is also appropriate.
package/dist/config.d.ts CHANGED
@@ -27,13 +27,15 @@ export interface GraphConfigInterface {
27
27
  * in the format `[red, green, blue, alpha]` where each value is a number between 0 and 255.
28
28
  * Default value: '#b3b3b3'
29
29
  */
30
+ pointDefaultColor?: string | [number, number, number, number];
31
+ /** @deprecated Use `pointDefaultColor` instead */
30
32
  pointColor?: string | [number, number, number, number];
31
33
  /**
32
34
  * The color to use for points when they are greyed out (when selection is active).
33
35
  * This can be either a hex color string (e.g., '#b3b3b3') or an array of RGBA values
34
36
  * in the format `[red, green, blue, alpha]` where each value is a number between 0 and 255.
35
37
  *
36
- * If not provided, the color will be the same as the `pointColor`,
38
+ * If not provided, the color will be the same as the point's original color,
37
39
  * but darkened or lightened depending on the background color.
38
40
  *
39
41
  * If `pointGreyoutOpacity` is also defined, it will override the alpha/opacity component
@@ -74,6 +76,11 @@ export interface GraphConfigInterface {
74
76
  * Default value: `auto`
75
77
  */
76
78
  hoveredPointCursor?: string;
79
+ /**
80
+ * Cursor style to use when hovering over a link
81
+ * Default value: `auto`
82
+ */
83
+ hoveredLinkCursor?: string;
77
84
  /**
78
85
  * Turns ring rendering around a point on hover on / off
79
86
  * Default value: `false`
@@ -127,6 +134,19 @@ export interface GraphConfigInterface {
127
134
  * Default value: `1`
128
135
  */
129
136
  linkWidth?: number;
137
+ /**
138
+ * The color to use for links when they are hovered.
139
+ * This can be either a hex color string (e.g., '#ff3333') or an array of RGBA values
140
+ * in the format `[red, green, blue, alpha]` where each value is a number between 0 and 255.
141
+ * Default value: `undefined`
142
+ */
143
+ hoveredLinkColor?: string | [number, number, number, number];
144
+ /**
145
+ * Number of pixels to add to the link width when hovered.
146
+ * The hovered width is calculated as: originalWidth + hoveredLinkWidthIncrease
147
+ * Default value: `5`
148
+ */
149
+ hoveredLinkWidthIncrease?: number;
130
150
  /**
131
151
  * Scale factor for the link width.
132
152
  * Default value: `1`
@@ -289,9 +309,15 @@ export interface GraphConfigInterface {
289
309
  onSimulationPause?: () => void;
290
310
  /**
291
311
  * Callback function that will be called when the simulation is restarted.
312
+ * @deprecated Use `onSimulationUnpause` instead. This callback will be removed in a future version.
292
313
  * Default value: `undefined`
293
314
  */
294
315
  onSimulationRestart?: () => void;
316
+ /**
317
+ * Callback function that will be called when the simulation is unpaused.
318
+ * Default value: `undefined`
319
+ */
320
+ onSimulationUnpause?: () => void;
295
321
  /**
296
322
  * Callback function that will be called on every canvas click.
297
323
  * If clicked on a point, its index will be passed as the first argument,
@@ -300,6 +326,28 @@ export interface GraphConfigInterface {
300
326
  * Default value: `undefined`
301
327
  */
302
328
  onClick?: (index: number | undefined, pointPosition: [number, number] | undefined, event: MouseEvent) => void;
329
+ /**
330
+ * Callback function that will be called when a point is clicked.
331
+ * The point index will be passed as the first argument,
332
+ * position as the second argument and the corresponding mouse event as the third argument:
333
+ * `(index: number, pointPosition: [number, number], event: MouseEvent) => void`.
334
+ * Default value: `undefined`
335
+ */
336
+ onPointClick?: (index: number, pointPosition: [number, number], event: MouseEvent) => void;
337
+ /**
338
+ * Callback function that will be called when a link is clicked.
339
+ * The link index will be passed as the first argument and the corresponding mouse event as the second argument:
340
+ * `(linkIndex: number, event: MouseEvent) => void`.
341
+ * Default value: `undefined`
342
+ */
343
+ onLinkClick?: (linkIndex: number, event: MouseEvent) => void;
344
+ /**
345
+ * Callback function that will be called when the background (empty space) is clicked.
346
+ * The mouse event will be passed as the first argument:
347
+ * `(event: MouseEvent) => void`.
348
+ * Default value: `undefined`
349
+ */
350
+ onBackgroundClick?: (event: MouseEvent) => void;
303
351
  /**
304
352
  * Callback function that will be called when mouse movement happens.
305
353
  * If the mouse moves over a point, its index will be passed as the first argument,
@@ -326,6 +374,20 @@ export interface GraphConfigInterface {
326
374
  * Default value: `undefined`
327
375
  */
328
376
  onPointMouseOut?: (event: MouseEvent | D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | undefined) => void;
377
+ /**
378
+ * Callback function that will be called when the mouse moves over a link.
379
+ * The link index will be passed as the first argument:
380
+ * `(linkIndex: number) => void`.
381
+ * Default value: `undefined`
382
+ */
383
+ onLinkMouseOver?: (linkIndex: number) => void;
384
+ /**
385
+ * Callback function that will be called when the mouse moves out of a link.
386
+ * The event will be passed as the first argument:
387
+ * `(event: MouseEvent | D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | undefined) => void`.
388
+ * Default value: `undefined`
389
+ */
390
+ onLinkMouseOut?: (event: MouseEvent | D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | undefined) => void;
329
391
  /**
330
392
  * Callback function that will be called when zooming or panning starts.
331
393
  * First argument is a D3 Zoom Event and second indicates whether
@@ -485,12 +547,14 @@ export declare class GraphConfig implements GraphConfigInterface {
485
547
  backgroundColor: string;
486
548
  spaceSize: number;
487
549
  pointColor: string;
550
+ pointDefaultColor: undefined;
488
551
  pointGreyoutOpacity: undefined;
489
552
  pointGreyoutColor: undefined;
490
553
  pointSize: number;
491
554
  pointOpacity: number;
492
555
  pointSizeScale: number;
493
556
  hoveredPointCursor: string;
557
+ hoveredLinkCursor: string;
494
558
  renderHoveredPointRing: boolean;
495
559
  hoveredPointRingColor: string;
496
560
  focusedPointRingColor: string;
@@ -500,6 +564,8 @@ export declare class GraphConfig implements GraphConfigInterface {
500
564
  linkGreyoutOpacity: number;
501
565
  linkWidth: number;
502
566
  linkWidthScale: number;
567
+ hoveredLinkColor: undefined;
568
+ hoveredLinkWidthIncrease: number;
503
569
  renderLinks: boolean;
504
570
  curvedLinks: boolean;
505
571
  curvedLinkSegments: number;
@@ -529,10 +595,16 @@ export declare class GraphConfig implements GraphConfigInterface {
529
595
  onSimulationEnd: GraphConfigInterface['onSimulationEnd'];
530
596
  onSimulationPause: GraphConfigInterface['onSimulationPause'];
531
597
  onSimulationRestart: GraphConfigInterface['onSimulationRestart'];
598
+ onSimulationUnpause: GraphConfigInterface['onSimulationUnpause'];
532
599
  onClick: GraphConfigInterface['onClick'];
600
+ onPointClick: GraphConfigInterface['onPointClick'];
601
+ onLinkClick: GraphConfigInterface['onLinkClick'];
602
+ onBackgroundClick: GraphConfigInterface['onBackgroundClick'];
533
603
  onMouseMove: GraphConfigInterface['onMouseMove'];
534
604
  onPointMouseOver: GraphConfigInterface['onPointMouseOver'];
535
605
  onPointMouseOut: GraphConfigInterface['onPointMouseOut'];
606
+ onLinkMouseOver: GraphConfigInterface['onLinkMouseOver'];
607
+ onLinkMouseOut: GraphConfigInterface['onLinkMouseOut'];
536
608
  onZoomStart: GraphConfigInterface['onZoomStart'];
537
609
  onZoom: GraphConfigInterface['onZoom'];
538
610
  onZoomEnd: GraphConfigInterface['onZoomEnd'];
package/dist/index.d.ts CHANGED
@@ -24,12 +24,12 @@ export declare class Graph {
24
24
  private fpsMonitor;
25
25
  private currentEvent;
26
26
  /**
27
- * The value of `_findHoveredPointExecutionCount` is incremented by 1 on each animation frame.
28
- * When the counter reaches 2 (or more), it is reset to 0 and the `findHoveredPoint` method is executed.
27
+ * The value of `_findHoveredItemExecutionCount` is incremented by 1 on each animation frame.
28
+ * When the counter reaches MAX_HOVER_DETECTION_DELAY (default 4), it is reset to 0 and the `findHoveredPoint` or `findHoveredLine` method is executed.
29
29
  */
30
- private _findHoveredPointExecutionCount;
30
+ private _findHoveredItemExecutionCount;
31
31
  /**
32
- * If the mouse is not on the Canvas, the `findHoveredPoint` method will not be executed.
32
+ * If the mouse is not on the Canvas, the `findHoveredPoint` or `findHoveredLine` method will not be executed.
33
33
  */
34
34
  private _isMouseOnCanvas;
35
35
  /**
@@ -237,6 +237,24 @@ export declare class Graph {
237
237
  * Example: `new Float32Array([1, 0.4, 0.3])` sets the force coefficient for point 0 to 1, point 1 to 0.4, and point 2 to 0.3.
238
238
  */
239
239
  setPointClusterStrength(clusterStrength: Float32Array): void;
240
+ /**
241
+ * Sets which points are pinned (fixed) in position.
242
+ *
243
+ * Pinned points:
244
+ * - Do not move due to physics forces (gravity, repulsion, link forces, etc.)
245
+ * - Still participate in force calculations (other nodes are attracted to/repelled by them)
246
+ * - Can still be dragged by the user if `enableDrag` is true
247
+ *
248
+ * @param {number[] | null} pinnedIndices - Array of point indices to pin. Set to `[]` or `null` to unpin all points.
249
+ * @example
250
+ * // Pin points 0 and 5
251
+ * graph.setPinnedPoints([0, 5])
252
+ *
253
+ * // Unpin all points
254
+ * graph.setPinnedPoints([])
255
+ * graph.setPinnedPoints(null)
256
+ */
257
+ setPinnedPoints(pinnedIndices: number[] | null): void;
240
258
  /**
241
259
  * Renders the graph.
242
260
  *
@@ -443,11 +461,19 @@ export declare class Graph {
443
461
  */
444
462
  start(alpha?: number): void;
445
463
  /**
446
- * Pause the simulation.
464
+ * Pause the simulation. When paused, the simulation stops running
465
+ * and can be resumed using the unpause method.
447
466
  */
448
467
  pause(): void;
449
468
  /**
450
- * Restart the simulation.
469
+ * Unpause the simulation. This method resumes a paused
470
+ * simulation and continues its execution.
471
+ */
472
+ unpause(): void;
473
+ /**
474
+ * Restart/Resume the simulation. This method unpauses a paused
475
+ * simulation and resumes its execution.
476
+ * @deprecated Use `unpause()` instead. This method will be removed in a future version.
451
477
  */
452
478
  restart(): void;
453
479
  /**
@@ -486,7 +512,9 @@ export declare class Graph {
486
512
  private resizeCanvas;
487
513
  private setZoomTransformByPointPositions;
488
514
  private updateZoomDragBehaviors;
515
+ private findHoveredItem;
489
516
  private findHoveredPoint;
517
+ private findHoveredLine;
490
518
  private updateCanvasCursor;
491
519
  private addAttribution;
492
520
  }