@cosmos.gl/graph 3.0.0-beta.5 → 3.0.0-beta.7

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/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Device } from '@luma.gl/core';
2
- import { GraphConfig, GraphConfigInterface } from './config';
2
+ import { GraphConfigInterface, GraphConfig } from './config';
3
3
  import { GraphData } from './modules/GraphData';
4
4
  export declare class Graph {
5
- config: GraphConfig;
5
+ /** Current graph configuration. Always fully populated with default values for any unset properties. */
6
+ config: GraphConfigInterface;
6
7
  graph: GraphData;
7
8
  /** Promise that resolves when the graph is fully initialized and ready to use */
8
9
  readonly ready: Promise<void>;
@@ -80,7 +81,12 @@ export declare class Graph {
80
81
  private isForceCenterUpdateNeeded;
81
82
  private isPointImageSizesUpdateNeeded;
82
83
  private _isDestroyed;
83
- constructor(div: HTMLDivElement, config?: GraphConfigInterface, devicePromise?: Promise<Device>);
84
+ /**
85
+ * Create a new Graph instance.
86
+ * @param div - Container element for the graph canvas.
87
+ * @param config - Optional configuration. Unset properties use default values.
88
+ */
89
+ constructor(div: HTMLDivElement, config?: GraphConfig, devicePromise?: Promise<Device>);
84
90
  /**
85
91
  * Returns the current simulation progress
86
92
  */
@@ -95,10 +101,24 @@ export declare class Graph {
95
101
  */
96
102
  get maxPointSize(): number;
97
103
  /**
98
- * Set or update Cosmos configuration. The changes will be applied in real time.
99
- * @param config Cosmos configuration object.
104
+ * Apply a new configuration. Changes take effect immediately.
105
+ *
106
+ * **Important:** Every call fully resets the configuration to defaults first,
107
+ * then applies the provided values on top. Properties not included in `config`
108
+ * will revert to their default values — they are not preserved from the previous call.
109
+ *
110
+ * @param config - Configuration object. Only include the properties you want to set.
100
111
  */
101
- setConfig(config: Partial<GraphConfigInterface>): void;
112
+ setConfig(config: GraphConfig): void;
113
+ /**
114
+ * Partially updates the graph configuration. Only the provided properties
115
+ * will be changed; all other properties retain their current values.
116
+ *
117
+ * Properties set to `undefined` will be reset to their default values.
118
+ *
119
+ * @param config - A partial configuration object with the properties to update.
120
+ */
121
+ setConfigPartial(config: GraphConfig): void;
102
122
  /**
103
123
  * Sets the positions for the graph points.
104
124
  *
@@ -115,7 +135,7 @@ export declare class Graph {
115
135
  *
116
136
  * @param {Float32Array} pointColors - A Float32Array representing the colors of points in the format [r1, g1, b1, a1, r2, g2, b2, a2, ..., rn, gn, bn, an],
117
137
  * where each color is represented in RGBA format.
118
- * Example: `new Float32Array([255, 0, 0, 1, 0, 255, 0, 1])` sets the first point to red and the second point to green.
138
+ * Example: `new Float32Array([1, 0, 0, 1, 0, 1, 0, 1])` sets the first point to red and the second point to green.
119
139
  */
120
140
  setPointColors(pointColors: Float32Array): void;
121
141
  /**
@@ -190,7 +210,7 @@ export declare class Graph {
190
210
  *
191
211
  * @param {Float32Array} linkColors - A Float32Array representing the colors of links in the format [r1, g1, b1, a1, r2, g2, b2, a2, ..., rn, gn, bn, an],
192
212
  * where each color is in RGBA format.
193
- * Example: `new Float32Array([255, 0, 0, 1, 0, 255, 0, 1])` sets the first link to red and the second link to green.
213
+ * Example: `new Float32Array([1, 0, 0, 1, 0, 1, 0, 1])` sets the first link to red and the second link to green.
194
214
  */
195
215
  setLinkColors(linkColors: Float32Array): void;
196
216
  /**
@@ -299,20 +319,23 @@ export declare class Graph {
299
319
  * @param duration Duration of the animation transition in milliseconds (`700` by default).
300
320
  * @param scale Scale value to zoom in or out (`3` by default).
301
321
  * @param canZoomOut Set to `false` to prevent zooming out from the point (`true` by default).
322
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
302
323
  */
303
- zoomToPointByIndex(index: number, duration?: number, scale?: number, canZoomOut?: boolean): void;
324
+ zoomToPointByIndex(index: number, duration?: number, scale?: number, canZoomOut?: boolean, enableSimulation?: boolean): void;
304
325
  /**
305
326
  * Zoom the view in or out to the specified zoom level.
306
327
  * @param value Zoom level
307
328
  * @param duration Duration of the zoom in/out transition.
329
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
308
330
  */
309
- zoom(value: number, duration?: number): void;
331
+ zoom(value: number, duration?: number, enableSimulation?: boolean): void;
310
332
  /**
311
333
  * Zoom the view in or out to the specified zoom level.
312
334
  * @param value Zoom level
313
335
  * @param duration Duration of the zoom in/out transition.
336
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
314
337
  */
315
- setZoomLevel(value: number, duration?: number): void;
338
+ setZoomLevel(value: number, duration?: number, enableSimulation?: boolean): void;
316
339
  /**
317
340
  * Get zoom level.
318
341
  * @returns Zoom level value of the view.
@@ -325,29 +348,32 @@ export declare class Graph {
325
348
  getPointPositions(): number[];
326
349
  /**
327
350
  * Get current X and Y coordinates of the clusters.
328
- * @returns Array of point cluster.
351
+ * @returns Array of cluster positions in `[x0, y0, x1, y1, ...]` order. Do not mutate the returned array.
329
352
  */
330
- getClusterPositions(): number[];
353
+ getClusterPositions(): Readonly<number[]>;
331
354
  /**
332
355
  * Center and zoom in/out the view to fit all points in the scene.
333
356
  * @param duration Duration of the center and zoom in/out animation in milliseconds (`250` by default).
334
357
  * @param padding Padding around the viewport in percentage (`0.1` by default).
358
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
335
359
  */
336
- fitView(duration?: number, padding?: number): void;
360
+ fitView(duration?: number, padding?: number, enableSimulation?: boolean): void;
337
361
  /**
338
362
  * Center and zoom in/out the view to fit points by their indices in the scene.
339
363
  * @param indices Point indices to fit in the view.
340
364
  * @param duration Duration of the center and zoom in/out animation in milliseconds (`250` by default).
341
365
  * @param padding Padding around the viewport in percentage (`0.1` by default).
366
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
342
367
  */
343
- fitViewByPointIndices(indices: number[], duration?: number, padding?: number): void;
368
+ fitViewByPointIndices(indices: number[], duration?: number, padding?: number, enableSimulation?: boolean): void;
344
369
  /**
345
370
  * Center and zoom in/out the view to fit points by their positions in the scene.
346
371
  * @param positions Flat array of point coordinates as `[x0, y0, x1, y1, ...]`.
347
372
  * @param duration Duration of the center and zoom in/out animation in milliseconds (`250` by default).
348
373
  * @param padding Padding around the viewport in percentage (`0.1` by default).
374
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
349
375
  */
350
- fitViewByPointPositions(positions: number[], duration?: number, padding?: number): void;
376
+ fitViewByPointPositions(positions: number[], duration?: number, padding?: number, enableSimulation?: boolean): void;
351
377
  /**
352
378
  * Sets the zoom transform so that the given point positions fit in the viewport, with optional animation.
353
379
  *
@@ -355,8 +381,9 @@ export declare class Graph {
355
381
  * @param duration Animation duration in milliseconds. Default `250`.
356
382
  * @param scale Optional scale factor; if omitted, scale is chosen to fit the positions.
357
383
  * @param padding Padding around the viewport as a fraction (e.g. `0.1` = 10%). Default `0.1`.
384
+ * @param enableSimulation Whether to run the simulation during the zoom transition (`true` by default).
358
385
  */
359
- setZoomTransformByPointPositions(positions: Float32Array, duration?: number, scale?: number, padding?: number): void;
386
+ setZoomTransformByPointPositions(positions: Float32Array, duration?: number, scale?: number, padding?: number, enableSimulation?: boolean): void;
360
387
  /**
361
388
  * Get points indices inside a rectangular area.
362
389
  * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
@@ -365,15 +392,6 @@ export declare class Graph {
365
392
  * @returns A Float32Array containing the indices of points inside a rectangular area.
366
393
  */
367
394
  getPointsInRect(selection: [[number, number], [number, number]]): Float32Array;
368
- /**
369
- * Get points indices inside a rectangular area.
370
- * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
371
- * The `left` and `right` coordinates should be from 0 to the width of the canvas.
372
- * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
373
- * @returns A Float32Array containing the indices of points inside a rectangular area.
374
- * @deprecated Use `getPointsInRect` instead. This method will be removed in a future version.
375
- */
376
- getPointsInRange(selection: [[number, number], [number, number]]): Float32Array;
377
395
  /**
378
396
  * Get points indices inside a polygon area.
379
397
  * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
@@ -386,13 +404,6 @@ export declare class Graph {
386
404
  * The `left` and `right` coordinates should be from 0 to the width of the canvas.
387
405
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas. */
388
406
  selectPointsInRect(selection: [[number, number], [number, number]] | null): void;
389
- /** Select points inside a rectangular area.
390
- * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
391
- * The `left` and `right` coordinates should be from 0 to the width of the canvas.
392
- * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
393
- * @deprecated Use `selectPointsInRect` instead. This method will be removed in a future version.
394
- */
395
- selectPointsInRange(selection: [[number, number], [number, number]] | null): void;
396
407
  /** Select points inside a polygon area.
397
408
  * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
398
409
  * The coordinates should be from 0 to the width/height of the canvas.
@@ -484,6 +495,24 @@ export declare class Graph {
484
495
  indices: number[];
485
496
  positions: number[];
486
497
  };
498
+ /**
499
+ * For the links that are currently visible on the screen, get a sample of link indices with their midpoint coordinates and angle.
500
+ * The resulting number of links will depend on the `linkSamplingDistance` configuration property,
501
+ * and the sampled links will be evenly distributed (one link per grid cell, based on link midpoint in screen space).
502
+ * Each value is [x, y, angle]: position in data space; angle in radians for screen-space rotation (0 = right, positive = clockwise, e.g. for CSS rotation).
503
+ */
504
+ getSampledLinkPositionsMap(): Map<number, [number, number, number]>;
505
+ /**
506
+ * For the links that are currently visible on the screen, get a sample of link indices, midpoint positions, and angles.
507
+ * The resulting number of links will depend on the `linkSamplingDistance` configuration property,
508
+ * and the sampled links will be evenly distributed.
509
+ * Positions are in data space; angles are in radians for screen-space rotation (0 = right, positive = clockwise, e.g. for CSS rotation).
510
+ */
511
+ getSampledLinks(): {
512
+ indices: number[];
513
+ positions: number[];
514
+ angles: number[];
515
+ };
487
516
  /**
488
517
  * Gets the X-axis of rescaling function.
489
518
  *
@@ -518,12 +547,6 @@ export declare class Graph {
518
547
  * simulation and continues its execution.
519
548
  */
520
549
  unpause(): void;
521
- /**
522
- * Restart/Resume the simulation. This method unpauses a paused
523
- * simulation and resumes its execution.
524
- * @deprecated Use `unpause()` instead. This method will be removed in a future version.
525
- */
526
- restart(): void;
527
550
  /**
528
551
  * Run one step of the simulation manually.
529
552
  * Works even when the simulation is paused.
@@ -534,7 +557,9 @@ export declare class Graph {
534
557
  */
535
558
  destroy(): void;
536
559
  /**
537
- * Updates and recreates the graph visualization based on pending changes.
560
+ * Applies pending data changes (positions, colors, sizes, shapes, links, forces, clusters)
561
+ * to the graph visualization. Call this after setting data via methods like `setPointPositions`,
562
+ * `setPointColors`, `setLinks`, etc. if you need to apply changes without calling `render()`.
538
563
  */
539
564
  create(): void;
540
565
  /**
@@ -549,6 +574,16 @@ export declare class Graph {
549
574
  * @returns An array of tuple positions
550
575
  */
551
576
  pair(pointPositions: number[]): [number, number][];
577
+ /**
578
+ * Restores init-only fields (`enableSimulation`, `initialZoomLevel`, `randomSeed`, `attribution`)
579
+ * to their pre-update values, preventing runtime changes via setConfig/setConfigPartial.
580
+ */
581
+ private preserveInitOnlyFields;
582
+ /**
583
+ * Compares the previous config snapshot with the current `this.config` and
584
+ * applies any necessary side effects (updating renderers, store, behaviors, etc.).
585
+ */
586
+ private updateStateFromConfig;
552
587
  /**
553
588
  * Ensures device is initialized before executing a method.
554
589
  * If device is not ready, queues the method to run after initialization.
@@ -619,6 +654,7 @@ export declare class Graph {
619
654
  private updateCanvasCursor;
620
655
  private addAttribution;
621
656
  }
622
- export type { GraphConfigInterface } from './config';
657
+ export type { GraphConfig } from './config';
623
658
  export { PointShape } from './modules/GraphData';
659
+ export * from './variables';
624
660
  export * from './helper';