@cosmos.gl/graph 2.4.0 → 2.5.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 (36) hide show
  1. package/dist/config.d.ts +69 -0
  2. package/dist/index.d.ts +16 -6
  3. package/dist/index.js +4328 -4129
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +113 -45
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/modules/Lines/index.d.ts +8 -0
  8. package/dist/modules/Store/index.d.ts +14 -2
  9. package/dist/modules/core-module.d.ts +1 -0
  10. package/dist/stories/beginners/link-hovering/data-generator.d.ts +19 -0
  11. package/dist/stories/beginners/link-hovering/index.d.ts +5 -0
  12. package/dist/stories/beginners.stories.d.ts +1 -0
  13. package/dist/variables.d.ts +5 -2
  14. package/package.json +1 -1
  15. package/src/config.ts +86 -2
  16. package/src/index.ts +151 -31
  17. package/src/modules/Lines/draw-curve-line.frag +12 -1
  18. package/src/modules/Lines/draw-curve-line.vert +29 -2
  19. package/src/modules/Lines/hovered-line-index.frag +27 -0
  20. package/src/modules/Lines/hovered-line-index.vert +8 -0
  21. package/src/modules/Lines/index.ts +112 -2
  22. package/src/modules/Store/index.ts +33 -2
  23. package/src/modules/core-module.ts +1 -0
  24. package/src/stories/1. welcome.mdx +2 -1
  25. package/src/stories/2. configuration.mdx +10 -1
  26. package/src/stories/3. api-reference.mdx +13 -4
  27. package/src/stories/beginners/basic-set-up/index.ts +20 -10
  28. package/src/stories/beginners/link-hovering/data-generator.ts +198 -0
  29. package/src/stories/beginners/link-hovering/index.ts +61 -0
  30. package/src/stories/beginners/link-hovering/style.css +73 -0
  31. package/src/stories/beginners/quick-start.ts +2 -1
  32. package/src/stories/beginners/remove-points/index.ts +28 -30
  33. package/src/stories/beginners.stories.ts +17 -0
  34. package/src/stories/clusters/polygon-selection/index.ts +2 -4
  35. package/src/stories/shapes/image-example/index.ts +7 -8
  36. package/src/variables.ts +5 -2
package/dist/config.d.ts CHANGED
@@ -74,6 +74,11 @@ export interface GraphConfigInterface {
74
74
  * Default value: `auto`
75
75
  */
76
76
  hoveredPointCursor?: string;
77
+ /**
78
+ * Cursor style to use when hovering over a link
79
+ * Default value: `auto`
80
+ */
81
+ hoveredLinkCursor?: string;
77
82
  /**
78
83
  * Turns ring rendering around a point on hover on / off
79
84
  * Default value: `false`
@@ -127,6 +132,19 @@ export interface GraphConfigInterface {
127
132
  * Default value: `1`
128
133
  */
129
134
  linkWidth?: number;
135
+ /**
136
+ * The color to use for links when they are hovered.
137
+ * This can be either a hex color string (e.g., '#ff3333') or an array of RGBA values
138
+ * in the format `[red, green, blue, alpha]` where each value is a number between 0 and 255.
139
+ * Default value: `undefined`
140
+ */
141
+ hoveredLinkColor?: string | [number, number, number, number];
142
+ /**
143
+ * Number of pixels to add to the link width when hovered.
144
+ * The hovered width is calculated as: originalWidth + hoveredLinkWidthIncrease
145
+ * Default value: `5`
146
+ */
147
+ hoveredLinkWidthIncrease?: number;
130
148
  /**
131
149
  * Scale factor for the link width.
132
150
  * Default value: `1`
@@ -289,9 +307,15 @@ export interface GraphConfigInterface {
289
307
  onSimulationPause?: () => void;
290
308
  /**
291
309
  * Callback function that will be called when the simulation is restarted.
310
+ * @deprecated Use `onSimulationUnpause` instead. This callback will be removed in a future version.
292
311
  * Default value: `undefined`
293
312
  */
294
313
  onSimulationRestart?: () => void;
314
+ /**
315
+ * Callback function that will be called when the simulation is unpaused.
316
+ * Default value: `undefined`
317
+ */
318
+ onSimulationUnpause?: () => void;
295
319
  /**
296
320
  * Callback function that will be called on every canvas click.
297
321
  * If clicked on a point, its index will be passed as the first argument,
@@ -300,6 +324,28 @@ export interface GraphConfigInterface {
300
324
  * Default value: `undefined`
301
325
  */
302
326
  onClick?: (index: number | undefined, pointPosition: [number, number] | undefined, event: MouseEvent) => void;
327
+ /**
328
+ * Callback function that will be called when a point is clicked.
329
+ * The point index will be passed as the first argument,
330
+ * position as the second argument and the corresponding mouse event as the third argument:
331
+ * `(index: number, pointPosition: [number, number], event: MouseEvent) => void`.
332
+ * Default value: `undefined`
333
+ */
334
+ onPointClick?: (index: number, pointPosition: [number, number], event: MouseEvent) => void;
335
+ /**
336
+ * Callback function that will be called when a link is clicked.
337
+ * The link index will be passed as the first argument and the corresponding mouse event as the second argument:
338
+ * `(linkIndex: number, event: MouseEvent) => void`.
339
+ * Default value: `undefined`
340
+ */
341
+ onLinkClick?: (linkIndex: number, event: MouseEvent) => void;
342
+ /**
343
+ * Callback function that will be called when the background (empty space) is clicked.
344
+ * The mouse event will be passed as the first argument:
345
+ * `(event: MouseEvent) => void`.
346
+ * Default value: `undefined`
347
+ */
348
+ onBackgroundClick?: (event: MouseEvent) => void;
303
349
  /**
304
350
  * Callback function that will be called when mouse movement happens.
305
351
  * If the mouse moves over a point, its index will be passed as the first argument,
@@ -326,6 +372,20 @@ export interface GraphConfigInterface {
326
372
  * Default value: `undefined`
327
373
  */
328
374
  onPointMouseOut?: (event: MouseEvent | D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | undefined) => void;
375
+ /**
376
+ * Callback function that will be called when the mouse moves over a link.
377
+ * The link index will be passed as the first argument:
378
+ * `(linkIndex: number) => void`.
379
+ * Default value: `undefined`
380
+ */
381
+ onLinkMouseOver?: (linkIndex: number) => void;
382
+ /**
383
+ * Callback function that will be called when the mouse moves out of a link.
384
+ * The event will be passed as the first argument:
385
+ * `(event: MouseEvent | D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | undefined) => void`.
386
+ * Default value: `undefined`
387
+ */
388
+ onLinkMouseOut?: (event: MouseEvent | D3ZoomEvent<HTMLCanvasElement, undefined> | D3DragEvent<HTMLCanvasElement, undefined, Hovered> | undefined) => void;
329
389
  /**
330
390
  * Callback function that will be called when zooming or panning starts.
331
391
  * First argument is a D3 Zoom Event and second indicates whether
@@ -491,6 +551,7 @@ export declare class GraphConfig implements GraphConfigInterface {
491
551
  pointOpacity: number;
492
552
  pointSizeScale: number;
493
553
  hoveredPointCursor: string;
554
+ hoveredLinkCursor: string;
494
555
  renderHoveredPointRing: boolean;
495
556
  hoveredPointRingColor: string;
496
557
  focusedPointRingColor: string;
@@ -500,6 +561,8 @@ export declare class GraphConfig implements GraphConfigInterface {
500
561
  linkGreyoutOpacity: number;
501
562
  linkWidth: number;
502
563
  linkWidthScale: number;
564
+ hoveredLinkColor: undefined;
565
+ hoveredLinkWidthIncrease: number;
503
566
  renderLinks: boolean;
504
567
  curvedLinks: boolean;
505
568
  curvedLinkSegments: number;
@@ -529,10 +592,16 @@ export declare class GraphConfig implements GraphConfigInterface {
529
592
  onSimulationEnd: GraphConfigInterface['onSimulationEnd'];
530
593
  onSimulationPause: GraphConfigInterface['onSimulationPause'];
531
594
  onSimulationRestart: GraphConfigInterface['onSimulationRestart'];
595
+ onSimulationUnpause: GraphConfigInterface['onSimulationUnpause'];
532
596
  onClick: GraphConfigInterface['onClick'];
597
+ onPointClick: GraphConfigInterface['onPointClick'];
598
+ onLinkClick: GraphConfigInterface['onLinkClick'];
599
+ onBackgroundClick: GraphConfigInterface['onBackgroundClick'];
533
600
  onMouseMove: GraphConfigInterface['onMouseMove'];
534
601
  onPointMouseOver: GraphConfigInterface['onPointMouseOver'];
535
602
  onPointMouseOut: GraphConfigInterface['onPointMouseOut'];
603
+ onLinkMouseOver: GraphConfigInterface['onLinkMouseOver'];
604
+ onLinkMouseOut: GraphConfigInterface['onLinkMouseOut'];
536
605
  onZoomStart: GraphConfigInterface['onZoomStart'];
537
606
  onZoom: GraphConfigInterface['onZoom'];
538
607
  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
  /**
@@ -443,11 +443,19 @@ export declare class Graph {
443
443
  */
444
444
  start(alpha?: number): void;
445
445
  /**
446
- * Pause the simulation.
446
+ * Pause the simulation. When paused, the simulation stops running
447
+ * and can be resumed using the unpause method.
447
448
  */
448
449
  pause(): void;
449
450
  /**
450
- * Restart the simulation.
451
+ * Unpause the simulation. This method resumes a paused
452
+ * simulation and continues its execution.
453
+ */
454
+ unpause(): void;
455
+ /**
456
+ * Restart/Resume the simulation. This method unpauses a paused
457
+ * simulation and resumes its execution.
458
+ * @deprecated Use `unpause()` instead. This method will be removed in a future version.
451
459
  */
452
460
  restart(): void;
453
461
  /**
@@ -486,7 +494,9 @@ export declare class Graph {
486
494
  private resizeCanvas;
487
495
  private setZoomTransformByPointPositions;
488
496
  private updateZoomDragBehaviors;
497
+ private findHoveredItem;
489
498
  private findHoveredPoint;
499
+ private findHoveredLine;
490
500
  private updateCanvasCursor;
491
501
  private addAttribution;
492
502
  }