@cosmos.gl/graph 3.0.0-beta.6 → 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.
111
+ */
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.
100
120
  */
101
- setConfig(config: Partial<GraphConfigInterface>): void;
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]]`.
@@ -530,7 +557,9 @@ export declare class Graph {
530
557
  */
531
558
  destroy(): void;
532
559
  /**
533
- * 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()`.
534
563
  */
535
564
  create(): void;
536
565
  /**
@@ -545,6 +574,16 @@ export declare class Graph {
545
574
  * @returns An array of tuple positions
546
575
  */
547
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;
548
587
  /**
549
588
  * Ensures device is initialized before executing a method.
550
589
  * If device is not ready, queues the method to run after initialization.
@@ -615,7 +654,7 @@ export declare class Graph {
615
654
  private updateCanvasCursor;
616
655
  private addAttribution;
617
656
  }
618
- export type { GraphConfigInterface } from './config';
657
+ export type { GraphConfig } from './config';
619
658
  export { PointShape } from './modules/GraphData';
620
659
  export * from './variables';
621
660
  export * from './helper';