@cosmos.gl/deck-layers 3.5.0 → 3.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.
@@ -1,20 +1,22 @@
1
- import { CompositeLayer, Accessor, BinaryAttribute, Color, DefaultProps, GetPickingInfoParams, Layer, LayerContext, LayerProps, PickingInfo, Unit, UpdateParameters } from '@deck.gl/core';
2
- import { GraphSimulation, GraphSimulationConfig } from '@cosmos.gl/graph';
1
+ import { Layer, Accessor, BinaryAttribute, Color, DefaultProps, GetPickingInfoParams, LayerContext, LayerProps, PickingInfo, UpdateParameters } from '@deck.gl/core';
2
+ import { Graph, GraphConfig } from '@cosmos.gl/graph';
3
3
  /**
4
4
  * Binary styling channels for binary points, keyed by the accessor each one
5
- * replaces: deck uploads the typed array as the instanced attribute instead of
6
- * calling the accessor per point. Colors are RGBA bytes (0..255), 4 per point;
7
- * sizes are one diameter per point, in `pointSizeUnits`.
5
+ * replaces. Colors are RGBA per point, 4 values each: a `Uint8Array` in
6
+ * 0..255 (deck's convention) is converted, a `Float32Array` is cosmos's own
7
+ * 0..1 and is handed over as it is. Sizes are one value per point, handed
8
+ * over as they are. Values are read tightly packed; `offset` and `stride` are
9
+ * not honoured.
8
10
  */
9
11
  export type CosmosPointAttributes = {
10
12
  getPointColor?: BinaryAttribute;
11
13
  getPointSize?: BinaryAttribute;
12
14
  };
13
15
  /**
14
- * Points input: an array to run accessors over (picking returns the original
15
- * objects), or the cosmos-native binary form — a point count plus optional
16
- * `[x0, y0, x1, y1, …]` initial positions and binary styling channels. Points
17
- * without given positions are seeded randomly inside the simulation space.
16
+ * Points input: an array to run accessors over, or the cosmos-native binary
17
+ * form — a point count plus optional `[x0, y0, x1, y1, …]` initial positions
18
+ * and binary styling channels. Points without given positions are seeded
19
+ * randomly inside the simulation space.
18
20
  */
19
21
  export type CosmosGraphPoints<PointDataT> = readonly PointDataT[] | {
20
22
  length: number;
@@ -23,8 +25,8 @@ export type CosmosGraphPoints<PointDataT> = readonly PointDataT[] | {
23
25
  };
24
26
  /**
25
27
  * Binary styling channels for binary links, keyed by the accessor each one
26
- * replaces. Colors are RGBA bytes (0..255), 4 per link; widths are one per
27
- * link, in `linkWidthUnits`.
28
+ * replaces, with the same conventions as `CosmosPointAttributes`: colors a
29
+ * `Uint8Array` in 0..255 or a `Float32Array` in 0..1, widths one per link.
28
30
  */
29
31
  export type CosmosLinkAttributes = {
30
32
  getLinkColor?: BinaryAttribute;
@@ -34,15 +36,68 @@ export type CosmosLinkAttributes = {
34
36
  * Links input: an array to run accessors over, the cosmos-native
35
37
  * `[source0, target0, source1, target1, …]` array of point indices, or that
36
38
  * array as `pairs` with binary styling channels beside it. An array link whose
37
- * source or target does not resolve to a point is dropped from both the
38
- * simulation and the rendering, with one warning per data change; a pair that
39
- * names no point is skipped by both and keeps its index.
39
+ * source or target does not resolve to a point is dropped, with one warning
40
+ * per data change; a pair that names no point is skipped by the engine and
41
+ * keeps its index.
40
42
  */
41
43
  export type CosmosGraphLinks<LinkDataT> = readonly LinkDataT[] | Float32Array | {
42
44
  pairs: Float32Array;
43
45
  attributes?: CosmosLinkAttributes;
44
46
  };
45
- /** Picking info from a CosmosGraphLayer: which kind of element was hit. */
47
+ /**
48
+ * The cosmos.gl config keys deck owns in this embedding — the canvas, the view
49
+ * and its zoom, the frame loop, the pointer and its callbacks. The layer strips
50
+ * them from `config`: deck's view state, controller, event callbacks and
51
+ * `useDevicePixels` are the way to those things.
52
+ */
53
+ export declare const DECK_OWNED_CONFIG_KEYS: readonly ["enableRenderLoop", "backgroundColor", "pixelRatio", "showFPSMonitor", "attribution", "hoveredPointCursor", "hoveredLinkCursor", "initialZoomLevel", "enableZoom", "enableSimulationDuringZoom", "enableDrag", "fitViewOnInit", "fitViewDelay", "fitViewPadding", "fitViewDuration", "fitViewByPointsInRect", "fitViewByPointIndices", "simulationRepulsionFromMouse", "enableRightClickRepulsion", "onClick", "onPointClick", "onLinkClick", "onBackgroundClick", "onContextMenu", "onPointContextMenu", "onLinkContextMenu", "onBackgroundContextMenu", "onMouseMove", "onPointMouseOver", "onPointMouseOut", "onLinkMouseOver", "onLinkMouseOut", "onZoomStart", "onZoom", "onZoomEnd", "onDragStart", "onDrag", "onDragEnd"];
54
+ /**
55
+ * cosmos.gl's configuration as the layer takes it: every key of `GraphConfig`
56
+ * except the ones deck owns (`DECK_OWNED_CONFIG_KEYS`). Rendering keys work as
57
+ * in cosmos.gl, because cosmos.gl does the rendering. The transition keys have
58
+ * no effect: a headless `Graph` applies data changes at once.
59
+ */
60
+ export type CosmosGraphLayerConfig = Omit<GraphConfig, (typeof DECK_OWNED_CONFIG_KEYS)[number]>;
61
+ /**
62
+ * What `onGraphDataLoaded` reports: the graph, what the load replaced, and how
63
+ * your data maps to the graph's point and link indices. Per-point and per-link
64
+ * arrays you hand the graph (`setLinkStrength`, `setPointShapes`,
65
+ * `setPointClusters`, …) follow those indices. `links` and `pointIndexById`
66
+ * are the layer's own state: read or copy them, never mutate them.
67
+ */
68
+ export type CosmosGraphDataLoadedInfo<LinkDataT = unknown> = {
69
+ /** The graph the data was loaded into: layer-created or provided. */
70
+ graph: Graph;
71
+ /**
72
+ * The point positions were replaced, and with them possibly the point count.
73
+ * Per-point arrays sent before this load may no longer line up.
74
+ */
75
+ pointsLoaded: boolean;
76
+ /**
77
+ * The links were replaced. Per-link arrays sent before this load may no longer
78
+ * line up: the engine reuses the last one it was sent whenever its length
79
+ * matches the new link count, in the old order.
80
+ */
81
+ linksLoaded: boolean;
82
+ /**
83
+ * Point `i` is always entry `i` of `points` (or pair `i` of `initialPositions`).
84
+ * With array points and `getPointId`, this maps each id to its index; a repeated
85
+ * id maps to its last point. Otherwise `null`.
86
+ */
87
+ pointIndexById: ReadonlyMap<string | number, number> | null;
88
+ /**
89
+ * Array links: the links the graph holds, in its order — link `i` is
90
+ * `info.links[i]`. Links whose endpoints name no point are not among them, so
91
+ * an index into your `links` array can differ. Binary links, or no `links`
92
+ * prop: `null`, and link `i` is pair `i` of your pair array.
93
+ */
94
+ links: readonly LinkDataT[] | null;
95
+ };
96
+ /**
97
+ * Picking info from a CosmosGraphLayer: which kind of element was hit, with `index`
98
+ * counting within that kind (point `i` or link `i`), and `object` the original record
99
+ * for array data.
100
+ */
46
101
  export type CosmosGraphPickingInfo = PickingInfo & {
47
102
  elementType?: 'point' | 'link';
48
103
  };
@@ -50,9 +105,9 @@ export type CosmosGraphLayerProps<PointDataT = unknown, LinkDataT = unknown> = C
50
105
  type CosmosGraphLayerOwnProps<PointDataT, LinkDataT> = {
51
106
  /**
52
107
  * One entry per point — an array of your objects, or `{ length, initialPositions?, attributes? }`.
53
- * The layer loads them, with `links`, into the simulation. Omit it to draw the data the
54
- * simulation already holds instead: the layer then writes nothing into the simulation and
55
- * follows its point count and links — the mode for an application-loaded `simulation`.
108
+ * The layer loads them, with `links` and the styling accessors, into the graph. Omit it to
109
+ * draw the data the graph already holds instead: the layer then writes nothing into the
110
+ * graph, styling accessors included — the mode for an application-loaded `graph`.
56
111
  */
57
112
  points?: CosmosGraphPoints<PointDataT> | null;
58
113
  /** One entry per link — an array of your objects, or a flat point-index pair array. Ignored without `points`. */
@@ -62,23 +117,24 @@ type CosmosGraphLayerOwnProps<PointDataT, LinkDataT> = {
62
117
  * accessors may return ids instead of point indices.
63
118
  */
64
119
  getPointId?: Accessor<PointDataT, string | number> | null;
65
- /** Initial `[x, y]` position accessor for array points; points it leaves undefined are seeded randomly. */
66
- getPointPosition?: Accessor<PointDataT, readonly [number, number] | null | undefined> | null;
67
120
  /**
68
- * Point diameter accessor, in `pointSizeUnits`; `0` hides the point.
69
- * @default 4
121
+ * Initial `[x, y]` position accessor for array points, in cosmos space
122
+ * coordinates; points it leaves undefined are seeded randomly.
70
123
  */
71
- getPointSize?: Accessor<PointDataT, number>;
124
+ getPointPosition?: Accessor<PointDataT, readonly [number, number] | null | undefined> | null;
72
125
  /**
73
- * Point RGBA color accessor, channels in 0..255.
74
- * @default [74, 92, 191, 230]
126
+ * Point size accessor, in cosmos.gl's units: pixels at zoom 1, scaled with the view
127
+ * when `config.scalePointsOnZoom` is on, times `config.pointSizeScale`. `0` hides the point.
128
+ * Unset, every point draws `config.pointDefaultSize`.
129
+ * @default null
75
130
  */
76
- getPointColor?: Accessor<PointDataT, Color>;
131
+ getPointSize?: Accessor<PointDataT, number> | null;
77
132
  /**
78
- * The units of the point diameter.
79
- * @default 'pixels'
133
+ * Point RGBA color accessor, channels in 0..255 (deck's convention; converted for cosmos).
134
+ * Unset, every point draws `config.pointDefaultColor`.
135
+ * @default null
80
136
  */
81
- pointSizeUnits?: Unit;
137
+ getPointColor?: Accessor<PointDataT, Color> | null;
82
138
  /**
83
139
  * Source accessor for array links: a point index, or a point id when
84
140
  * `getPointId` is set.
@@ -92,30 +148,27 @@ type CosmosGraphLayerOwnProps<PointDataT, LinkDataT> = {
92
148
  */
93
149
  getLinkTarget?: Accessor<LinkDataT, string | number>;
94
150
  /**
95
- * Link RGBA color accessor, channels in 0..255.
96
- * @default [94, 115, 194, 64]
97
- */
98
- getLinkColor?: Accessor<LinkDataT, Color>;
99
- /**
100
- * Link width accessor, in `linkWidthUnits`.
101
- * @default 1
151
+ * Link RGBA color accessor, channels in 0..255. Unset, every link draws
152
+ * `config.linkDefaultColor`.
153
+ * @default null
102
154
  */
103
- getLinkWidth?: Accessor<LinkDataT, number>;
155
+ getLinkColor?: Accessor<LinkDataT, Color> | null;
104
156
  /**
105
- * The units of the link width.
106
- * @default 'pixels'
157
+ * Link width accessor, in cosmos.gl's units (see `config.scaleLinksOnZoom`, `config.linkWidthScale`).
158
+ * Unset, every link draws `config.linkDefaultWidth`.
159
+ * @default null
107
160
  */
108
- linkWidthUnits?: Unit;
161
+ getLinkWidth?: Accessor<LinkDataT, number> | null;
109
162
  /**
110
- * Lets pointer drags grab a point: pinned on drag start, moved with the
111
- * pointer, released per `unpinOnDragEnd`. View panning is suppressed while
112
- * a point is grabbed.
163
+ * Lets pointer drags grab a point: pinned on drag start, moved with the pointer,
164
+ * released per `unpinOnDragEnd`. View panning is suppressed while a point is
165
+ * grabbed. Needs `pickable`.
113
166
  * @default false
114
167
  */
115
168
  enablePointDrag?: boolean;
116
169
  /**
117
- * Simulation alpha to restart with when a drag starts, so the graph
118
- * responds to the moving point; `null` leaves the simulation untouched.
170
+ * Simulation alpha to restart with when a drag starts, so the graph responds
171
+ * to the moving point; `null` leaves the simulation untouched.
119
172
  * @default 0.1
120
173
  */
121
174
  dragReheatAlpha?: number | null;
@@ -131,130 +184,251 @@ type CosmosGraphLayerOwnProps<PointDataT, LinkDataT> = {
131
184
  /** Called when a point drag ends. */
132
185
  onPointDragEnd?: ((info: CosmosGraphPickingInfo) => void) | null;
133
186
  /**
134
- * An application-owned `GraphSimulation` to render instead of creating one.
135
- * It must run on deck's device — construct it with the device from deck's
187
+ * cosmos.gl's configuration — forces, space size, rendering options such as
188
+ * `curvedLinks`, `pointDefaultShape`, `linkDefaultArrows`, the simulation
189
+ * callbacks — passed to the layer-created `Graph`. A key left out goes back
190
+ * to the engine default. Ignored when `graph` is provided.
191
+ */
192
+ config?: CosmosGraphLayerConfig;
193
+ /**
194
+ * An application-owned headless `Graph` to draw instead of creating one:
195
+ * `new Graph(null, config, devicePromise)` with the device from deck's
136
196
  * `onDeviceInitialized`. The layer steps it while it runs (`pause()` it to
137
197
  * take over stepping, then `deck.redraw()` after each manual `step()`) and
138
- * renders it; it never configures or destroys it — `simulationConfig` and
139
- * `onSimulationCreated` apply only to a layer-created simulation, and
140
- * teardown is the application's, before `deck.finalize()`.
198
+ * draws it; it never configures or destroys it — `config` and
199
+ * `onGraphCreated` apply only to a layer-created graph, and teardown is the
200
+ * application's, before `deck.finalize()`.
141
201
  *
142
- * `points` decides who loads the data. Given, the layer loads `points` and
143
- * `links` into the simulation once the device check has passed, over whatever
144
- * it held. Omitted, the layer draws the simulation's own data and follows its
145
- * changes. Several layers may draw one simulation — it steps once per frame
146
- * however many draw it — as long as at most one of them loads data.
202
+ * `points` decides who loads the data. Given, the layer loads `points`,
203
+ * `links` and the styling accessors into the graph once the device check has
204
+ * passed, over whatever it held. Omitted, the layer draws the graph's own
205
+ * data and writes nothing. Several layers may draw one graph — it steps once
206
+ * per frame however many draw it — as long as at most one of them loads data.
147
207
  */
148
- simulation?: GraphSimulation | null;
208
+ graph?: Graph | null;
149
209
  /**
150
- * Simulation configuration, passed through to the layer-created
151
- * `GraphSimulation` (forces, spaceSize, callbacks). Ignored when
152
- * `simulation` is provided.
210
+ * Called once with the layer-created `Graph` — the whole cosmos.gl API for
211
+ * what the props do not cover: pause, pin, reheat, shapes, clusters, trackers,
212
+ * sparse position writes. Not called for a provided `graph`.
153
213
  */
154
- simulationConfig?: GraphSimulationConfig;
214
+ onGraphCreated?: ((graph: Graph) => void) | null;
155
215
  /**
156
- * Called once with the layer-created `GraphSimulation` — the escape hatch for
157
- * advanced control (pause, pinning, sparse position writes). Not called for
158
- * a provided `simulation`.
216
+ * Called after each load of `points` or `links` into the graph, once the
217
+ * graph holds the new data — and, with both load flags `false`, when only the
218
+ * id map changed. Use it to send what lines up with the graph's indices —
219
+ * link strengths, shapes, arrows, clusters, pins — again after a reload:
220
+ * `info.pointIndexById` and `info.links` map your data to those indices.
221
+ * Not called when the layer draws a graph's own data (no `points`).
222
+ *
223
+ * The first call comes when the graph is ready (and again after a `graph`
224
+ * swap), later ones during deck's layer update. Calls on `info.graph` are
225
+ * fine in either; defer anything that changes layer props. A throw goes to
226
+ * deck's `onError`, and the load stands.
159
227
  */
160
- onSimulationCreated?: ((simulation: GraphSimulation) => void) | null;
228
+ onGraphDataLoaded?: ((info: CosmosGraphDataLoadedInfo<LinkDataT>) => void) | null;
161
229
  };
162
230
  /** The slice of a deck gesture event the drag handlers need. */
163
231
  type DragGestureEvent = {
164
232
  stopImmediatePropagation?: () => void;
165
233
  };
166
- /** The endpoint channels of the links sublayer, read straight from the cosmos pair array. */
167
- type LinkEndpointAttributes = {
168
- getLinkSource: BinaryAttribute;
169
- getLinkTarget: BinaryAttribute;
170
- };
171
- type BinaryLinksData = {
172
- length: number;
173
- attributes: LinkEndpointAttributes & CosmosLinkAttributes;
174
- };
175
234
  /**
176
- * The cosmos.gl graph layer: give it points and links, and it handles the
177
- * rest. The layer creates a `GraphSimulation` on deck's device (or renders the
178
- * application's, via `simulation`), loads the data — or, without `points`,
179
- * follows the data the simulation holds — advances the simulation once per
180
- * animation frame from deck's shared timeline while it runs (deck goes idle
181
- * when it settles — no `_animate` required), renders through its internal
182
- * links and points sublayers (positions stay GPU-resident), and destroys a
183
- * simulation it created when the layer is removed. Picking reports
184
- * `elementType: 'point' | 'link'` alongside the index and, for array data, the
185
- * original object.
235
+ * The cosmos.gl graph layer: give it points and links, and cosmos.gl lays them
236
+ * out and draws them under deck's camera. The layer creates a headless `Graph`
237
+ * on deck's device (or draws the application's, via `graph`), loads the data —
238
+ * or, without `points`, leaves the graph's own data alone — advances the
239
+ * simulation once per animation frame from deck's shared timeline while it runs
240
+ * (deck goes idle when it settles), hands deck's view to cosmos.gl before each
241
+ * draw and records cosmos.gl's own point and link draws into deck's render
242
+ * pass. Everything cosmos.gl renders is available through `config` and the
243
+ * `Graph` handle: shapes, arrows, dashes, curves, greyout, rings.
244
+ *
245
+ * The view: cosmos.gl's is a uniform scale plus a translation with y up, so
246
+ * the layer draws under an `OrthographicView({ flipY: false })` or a map view
247
+ * at pitch 0 and bearing 0, with `modelMatrix` placing the space in the world.
248
+ * A rotated, pitched or y-down view is reported once and not drawn.
249
+ *
250
+ * Picking is deck's: in deck's pick pass cosmos.gl draws its picking colors
251
+ * (an index per point and per link, hard-edged), so `pickable` gives hover and
252
+ * click with `info.elementType`, `info.index` and, for array data, `info.object`.
253
+ * `autoHighlight` lights the hovered point or link with cosmos.gl's own hover
254
+ * ring and hovered-link width (`config.hoveredPointRingColor`,
255
+ * `config.hoveredLinkWidthIncrease`, `config.hoveredLinkColor`) and leaves focus
256
+ * to the application; `highlightColor` is not used.
257
+ * `enablePointDrag` grabs a point and moves it, on a map as well.
186
258
  */
187
- export declare class CosmosGraphLayer<PointDataT = unknown, LinkDataT = unknown> extends CompositeLayer<Required<CosmosGraphLayerOwnProps<PointDataT, LinkDataT>>> {
259
+ export declare class CosmosGraphLayer<PointDataT = unknown, LinkDataT = unknown> extends Layer<Required<CosmosGraphLayerOwnProps<PointDataT, LinkDataT>>> {
188
260
  static layerName: string;
189
261
  static defaultProps: DefaultProps<CosmosGraphLayerProps<unknown, unknown>>;
190
262
  state: {
191
- simulation?: GraphSimulation;
192
- /** The `simulation` prop this state was built from; `null` when the layer created its own. */
193
- providedSimulation: GraphSimulation | null;
263
+ graph?: Graph;
264
+ /** The `graph` prop this state was built from; `null` when the layer created its own. */
265
+ providedGraph: Graph | null;
194
266
  isReady: boolean;
195
- /** `points` changed before the simulation was ready: load them once it is. */
267
+ /** `points` changed before the graph was ready: load them once it is. */
196
268
  isIngestPending: boolean;
197
269
  pointCount: number;
198
- pointsData: readonly PointDataT[] | {
199
- length: number;
200
- attributes?: CosmosPointAttributes;
201
- };
202
- linksData: readonly LinkDataT[] | BinaryLinksData | null;
203
- /** Array links only: the resolved `[source, target]` point-index pairs, one per entry of `linksData`. */
204
- linkIndices: Float32Array | null;
270
+ linkCount: number;
205
271
  /**
206
- * Load mode: what the simulation holds, so a channel reloads only when its own
207
- * input changes and a restyle leaves the layout alone. `loadedPositions` is the
272
+ * Load mode: what the graph holds, so a channel reloads only when its own input
273
+ * changes and a restyle leaves the layout alone. `loadedPositions` is the
208
274
  * `initialPositions` array, `SEEDED`, or the points array; `loadedPairs` the pair
209
- * array sent last; `idToIndex` the id map of the loaded points.
275
+ * array sent last; `idToIndex` the id map of the loaded points; `keptLinks` the
276
+ * array links the graph holds, in its order.
210
277
  */
211
278
  hasLoaded: boolean;
212
279
  loadedPositions?: unknown;
213
280
  loadedPairs?: Float32Array | null;
214
281
  idToIndex?: Map<string | number, number> | null;
215
- /** Without `points`: the simulation's links array the render data was built from. */
216
- followedLinks?: Float32Array | null;
282
+ keptLinks: readonly LinkDataT[] | null;
283
+ /**
284
+ * `getBounds`' measured box: the last one read back (`null` when nothing finite was
285
+ * there), the position texture version it was asked at, and whether a read is on its
286
+ * way. Unset until the first read lands, and again when a new dataset is loaded. The
287
+ * serial counts the datasets loaded: a read of the previous one that lands after the
288
+ * next is dropped.
289
+ */
290
+ measuredBounds?: [number[], number[]] | null;
291
+ measuredBoundsVersion?: number;
292
+ isMeasuringBounds?: boolean;
293
+ loadSerial?: number;
294
+ /** The view was found unsupported and said so; said once. */
295
+ viewWarned?: boolean;
296
+ linksWarned?: boolean;
217
297
  draggedPointIndex: number | null;
298
+ /**
299
+ * This layer's last auto-highlight write was a hover. Several layers may draw one
300
+ * graph, and the hover lives on the graph: only the layer holding it clears it.
301
+ */
302
+ holdsHover: boolean;
218
303
  animationHandle?: number;
219
304
  };
220
305
  get isLoaded(): boolean;
221
306
  initializeState(): void;
222
307
  updateState(params: UpdateParameters<this>): void;
223
- renderLayers(): Layer[] | null;
308
+ draw(opts: {
309
+ shaderModuleProps?: {
310
+ picking?: {
311
+ isActive?: number | boolean;
312
+ };
313
+ };
314
+ parameters?: {
315
+ blendColor?: number[];
316
+ };
317
+ }): void;
318
+ getPickingInfo({ info }: GetPickingInfoParams): CosmosGraphPickingInfo;
224
319
  onDragStart(info: PickingInfo, event: DragGestureEvent): boolean;
225
320
  onDrag(info: PickingInfo, event: DragGestureEvent): boolean;
226
321
  onDragEnd(info: PickingInfo, event: DragGestureEvent): boolean;
227
- getPickingInfo(params: GetPickingInfoParams): CosmosGraphPickingInfo;
228
- /** The whole simulation space; lets deck's viewport helpers frame the graph. */
322
+ /**
323
+ * The box around the graph's points, `[[minX, minY, 0], [maxX, maxY, 0]]`, for an
324
+ * application to frame the layer with. In space coordinates, before `modelMatrix`: map it
325
+ * through `modelMatrix` (and, on a map, unproject it) before fitting a viewport to it.
326
+ * deck.gl's core does not call it; its mask effect reads it from every mask layer and its
327
+ * collision-filter effect from every layer carrying that extension, each on every frame.
328
+ *
329
+ * `spaceSize` bounds no position — a layout grows past its square as far as its forces
330
+ * take it — so the box is measured from the live positions, read back from the GPU. The
331
+ * read does not stall the frame: it is asynchronous, started by a call that finds the
332
+ * positions changed since the box was measured, one at a time, and the box it returns is
333
+ * the last one measured. While a read is on its way the layer holds the graph's step, as
334
+ * the engine's own render loop holds its frame for a copy: the read that completes a copy
335
+ * waits for every command queued before it, and a step queued behind the copy would be
336
+ * that wait. (A graph the application steps itself is not held.) While points move the
337
+ * box trails the drawn frame, by a frame or so, and a call made before the first read
338
+ * lands — or before the first read of a newly loaded dataset — gets the input box below.
339
+ * When a read lands the layer asks for a redraw, so a consumer reading the box every
340
+ * frame has the new one on the next. A layer nobody asks reads nothing. Absent points
341
+ * (NaN) are left out.
342
+ *
343
+ * Until the graph holds positions (its device is still initializing) or the first read
344
+ * has landed, the box is that of the positions the layer is about to load or has loaded:
345
+ * `initialPositions`, or `getPointPosition` over the point objects, plus the middle half
346
+ * of the space where unseeded points are placed — where the points start, so a view can
347
+ * be framed before the first frame.
348
+ *
349
+ * When there is nothing to measure — no points yet, every point absent, or positions the
350
+ * graph rescales on load (`rescalePositions: true`), which it centres on the space — the
351
+ * box is the space's square, `[[0, 0, 0], [spaceSize, spaceSize, 0]]`: where the graph
352
+ * starts, and what this method returned before layouts could leave the square. It is
353
+ * never `null`; the declared type keeps deck's `Layer.getBounds` contract, so a subclass
354
+ * may still override it with deck's own signature.
355
+ */
229
356
  getBounds(): [number[], number[]] | null;
230
357
  finalizeState(context: LayerContext): void;
358
+ /** No deck attributes: cosmos.gl holds every channel and draws them itself. */
359
+ protected _getAttributeManager(): null;
231
360
  /**
232
- * Points and links have separate index spaces, so the same picking color
233
- * exists in both sublayers: highlight only the sublayer that was hovered
234
- * and clear the other, or hovering point N would also tint link N.
361
+ * deck's auto-highlight, through cosmos.gl's own hover emphasis: the hovered point
362
+ * gets the hover ring, the hovered link the hovered-link width and color. It is the
363
+ * graph's host hover, so the graph's config — focus included — stays the
364
+ * application's. deck's picking module has no model of ours to tint, so
365
+ * `highlightColor` does not apply.
235
366
  */
236
367
  protected _updateAutoHighlight(info: PickingInfo): void;
237
- /** Adopts the provided simulation, or creates one on deck's device when `provided` is `null`. */
238
- private _attachSimulation;
239
- /** Destroys a layer-created simulation; a provided one is left to the application. */
240
- private _releaseSimulation;
241
- /** The simulation's space size — authoritative for a provided simulation too. */
368
+ /**
369
+ * The pointer in space coordinates, through the view of the viewport the pointer
370
+ * is in — the same derivation `draw` hands cosmos, inverted — under a map as well
371
+ * as an orthographic view. Not through the view cosmos holds: that is whichever
372
+ * viewport drew the graph last, a thumbnail's as easily as the one being dragged
373
+ * in. Pixels are relative to that viewport. Where the view cannot be derived the
374
+ * point stays where it is.
375
+ */
376
+ private _dragPosition;
377
+ /** Adopts the provided graph, or creates a headless one on deck's device when `provided` is `null`. */
378
+ private _attachGraph;
379
+ /**
380
+ * Destroys a layer-created graph; a provided one is left to the application, without
381
+ * the hover this layer put on it. deck sends no leave to a layer it removes.
382
+ */
383
+ private _releaseGraph;
384
+ /**
385
+ * Starts one asynchronous read of the live positions and keeps its box for `getBounds`,
386
+ * stamped with the texture version the read was asked at. A read that lands after the
387
+ * layer let go of the graph is dropped; an empty result (nothing to read, or the point
388
+ * count changed under the copy) leaves the box as it was, and the next call asks again.
389
+ */
390
+ private _measureBounds;
391
+ /** The space's square, the stand-in extent when there is nothing to measure (see `getBounds`). */
392
+ private _spaceSquare;
393
+ /**
394
+ * Adds the positions the layer would load to `box` (see `getBounds`): the given ones,
395
+ * placed as the engine will place them, and the square unseeded points are drawn in.
396
+ * Nothing when they are rescaled on load.
397
+ */
398
+ private _addInputPositions;
399
+ /**
400
+ * The length the engine's placement rules are fractions of: the infinite-input edge, the
401
+ * unseeded square, and the stand-in extent. The graph's own, validated, length once
402
+ * there is a graph — from its construction, so the default when its config's `spaceSize`
403
+ * is not a usable size, and authoritative for a provided graph — the config's before.
404
+ * It sizes nothing.
405
+ */
242
406
  private _spaceSize;
243
- private _onTimelineTick;
244
407
  /**
245
- * Without `points`: builds the render data from what the simulation holds —
246
- * its point count and links — and rebuilds it when either changes. Runs every
247
- * tick, so it only compares until something differs.
408
+ * The config for a layer-created graph: the prop without the keys deck owns,
409
+ * and the pixel ratio deck's canvas draws at, so cosmos sizes pixels alike.
248
410
  */
249
- private _syncFromSimulation;
250
- private _dragCoordinate;
411
+ private _graphConfig;
412
+ /** deck's device pixels per CSS pixel, as its canvas context reports them. */
413
+ private _pixelRatio;
414
+ /**
415
+ * cosmos's view for a deck viewport: a uniform scale `k` (pixels per space
416
+ * unit) and a translation, per `setViewTransform`'s space → screen formula,
417
+ * inverted. Three anchors through deck's projection — the space origin, its
418
+ * x axis, its y axis — give the scale and tell whether the view is one cosmos
419
+ * can draw: unrotated, unpitched, y up. The translation then follows from where
420
+ * the space origin lands and the world origin cosmos centres its screen on, read
421
+ * from the engine (`spaceSize / 2` on both axes, after the engine's own space-size
422
+ * adjustment). The space origin's pixel is returned too, for mapping the other way.
423
+ */
424
+ private _viewTransform;
425
+ private _onTimelineTick;
251
426
  /**
252
- * Load mode: puts the layer's `points` and `links` into the simulation and
253
- * builds the render data from them. Each channel is sent only when its own
254
- * input changed — a new `points` or `links` object with the same positions
255
- * or pairs restyles in place and leaves the layout alone. A changed id map
256
- * re-resolves array links without touching the positions.
427
+ * Load mode: puts the layer's `points`, `links` and styles into the graph.
428
+ * Each channel is sent only when its own input changed — a restyle leaves the
429
+ * layout alone, a changed id map re-resolves array links without touching the
430
+ * positions.
257
431
  */
258
- private _updateSimulationData;
432
+ private _load;
259
433
  }
260
434
  export {};
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * A deck.gl layer that renders a cosmos.gl simulation with **zero position
3
- * readback**: each draw samples the live GPU position texture with
4
- * `texelFetch`, so point coordinates never leave the GPU. The simulation runs
5
- * on deck.gl's own device — created and owned by the layer, or supplied by the
6
- * application through the `simulation` prop.
2
+ * A deck.gl layer that runs and draws a cosmos.gl graph. The simulation runs
3
+ * on deck.gl's own luma.gl device, and cosmos.gl's own renderer draws it into
4
+ * deck's render pass under deck's camera — positions never leave the GPU, and
5
+ * every cosmos.gl rendering option is available through `config`. Picking is
6
+ * deck's: cosmos.gl draws its picking colors in deck's pick pass.
7
7
  */
8
- export { CosmosGraphLayer, type CosmosGraphLayerProps, type CosmosGraphPoints, type CosmosPointAttributes, type CosmosGraphLinks, type CosmosLinkAttributes, type CosmosGraphPickingInfo, } from './cosmos-graph-layer';
8
+ export { CosmosGraphLayer, DECK_OWNED_CONFIG_KEYS, type CosmosGraphLayerProps, type CosmosGraphLayerConfig, type CosmosGraphPoints, type CosmosPointAttributes, type CosmosGraphLinks, type CosmosLinkAttributes, type CosmosGraphDataLoadedInfo, type CosmosGraphPickingInfo, } from './cosmos-graph-layer';