@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.
package/dist/index.js CHANGED
@@ -1,671 +1,533 @@
1
- import { Layer as H, project32 as B, picking as K, UNIT as $, CompositeLayer as Q } from "@deck.gl/core";
2
- import { GraphSimulation as X, defaultConfigValues as Y } from "@cosmos.gl/graph";
3
- import { Model as q, Geometry as V } from "@luma.gl/engine";
4
- const b = {
5
- depthWriteEnabled: !1,
6
- depthCompare: "always",
7
- blend: !0,
8
- blendColorOperation: "add",
9
- blendColorSrcFactor: "src-alpha",
10
- blendColorDstFactor: "one-minus-src-alpha",
11
- blendAlphaOperation: "add",
12
- blendAlphaSrcFactor: "one",
13
- blendAlphaDstFactor: "one-minus-src-alpha"
14
- }, tt = `layout(std140) uniform cosmosPointsUniforms {
15
- float pointsTextureSize;
16
- highp int sizeUnits;
17
- } cosmosPoints;
18
- `, et = {
19
- name: "cosmosPoints",
20
- vs: tt,
21
- uniformTypes: {
22
- pointsTextureSize: "f32",
23
- sizeUnits: "i32"
24
- }
25
- }, Z = [74, 92, 191, 230], it = (
26
- /* glsl */
27
- `#version 300 es
28
- #define SHADER_NAME cosmos-points-layer-vertex-shader
29
-
30
- in vec3 positions;
31
-
32
- in float instanceSizes;
33
- in vec4 instanceColors;
34
- in vec3 instancePickingColors;
35
-
36
- uniform sampler2D positionsTexture;
37
-
38
- out vec4 vColor;
39
- out vec2 unitPosition;
40
- out float outerRadiusPixels;
41
-
42
- // Collapse the quad so it clips away: nothing rasterizes, nothing picks
43
- void collapse() {
44
- gl_Position = vec4(0.0);
45
- unitPosition = vec2(0.0);
46
- outerRadiusPixels = 0.0;
47
- vColor = vec4(0.0);
48
- }
49
-
50
- void main(void) {
51
- int pointIndex = gl_InstanceID;
52
- int textureSize = int(cosmosPoints.pointsTextureSize);
53
- // Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates
54
- vec4 pointPosition = texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);
55
-
56
- // A removed (absent) point's texel is NaN — see PointPositionTexture
57
- if (isnan(pointPosition.x)) {
58
- collapse();
59
- return;
60
- }
61
-
62
- geometry.worldPosition = vec3(pointPosition.xy, 0.0);
63
- geometry.pickingColor = instancePickingColors;
64
-
65
- // instanceSizes is a diameter; the quad expands by radius
66
- outerRadiusPixels = project_size_to_pixel(instanceSizes * 0.5, cosmosPoints.sizeUnits);
67
- // A non-positive size hides the point — and the edge-padding divide below
68
- // is undefined at zero
69
- if (outerRadiusPixels <= 0.0) {
70
- collapse();
71
- return;
72
- }
73
- // Expand the quad so edge smoothing has room outside the circle
74
- float edgePadding = (outerRadiusPixels + SMOOTH_EDGE_RADIUS) / outerRadiusPixels;
75
-
76
- unitPosition = edgePadding * positions.xy;
77
- geometry.uv = unitPosition;
78
-
79
- vec3 offset = vec3(edgePadding * positions.xy * project_pixel_size(outerRadiusPixels), 0.0);
80
- DECKGL_FILTER_SIZE(offset, geometry);
81
- gl_Position = project_position_to_clipspace(geometry.worldPosition, vec3(0.0), offset, geometry.position);
82
- DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
83
-
84
- vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);
85
- DECKGL_FILTER_COLOR(vColor, geometry);
86
- }
87
- `
88
- ), ot = (
89
- /* glsl */
90
- `#version 300 es
91
- #define SHADER_NAME cosmos-points-layer-fragment-shader
92
-
93
- precision highp float;
94
-
95
- in vec4 vColor;
96
- in vec2 unitPosition;
97
- in float outerRadiusPixels;
98
-
99
- out vec4 fragColor;
100
-
101
- void main(void) {
102
- geometry.uv = unitPosition;
103
-
104
- float distToCenter = length(unitPosition) * outerRadiusPixels;
105
- float inCircle = smoothedge(distToCenter, outerRadiusPixels);
106
- if (inCircle == 0.0) {
107
- discard;
108
- }
109
-
110
- fragColor = vec4(vColor.rgb, vColor.a * inCircle);
111
- DECKGL_FILTER_COLOR(fragColor, geometry);
112
- }
113
- `
114
- ), nt = {
115
- getPointSize: { type: "accessor", value: 4 },
116
- getPointColor: { type: "accessor", value: Z },
117
- pointSizeUnits: "pixels",
118
- parameters: { type: "object", value: b, optional: !0, compare: 2 }
119
- }, T = class T extends H {
120
- getShaders() {
121
- return super.getShaders({ vs: it, fs: ot, modules: [B, K, et] });
122
- }
123
- initializeState() {
124
- this.getAttributeManager().addInstanced({
125
- instanceSizes: {
126
- size: 1,
127
- transition: !0,
128
- accessor: "getPointSize",
129
- defaultValue: 4
130
- },
131
- instanceColors: {
132
- size: 4,
133
- transition: !0,
134
- type: "unorm8",
135
- accessor: "getPointColor",
136
- defaultValue: [...Z]
137
- }
138
- });
139
- }
140
- updateState(t) {
141
- var e;
142
- super.updateState(t), t.changeFlags.extensionsChanged && ((e = this.state.model) == null || e.destroy(), this.state.model = this._getModel(), this.getAttributeManager().invalidateAll());
143
- }
144
- draw() {
145
- const t = this.props.graph.getPointPositionTexture(), { model: e } = this.state;
146
- if (!t || !e || t.pointCount === 0) return;
147
- const i = {
148
- pointsTextureSize: t.textureSize,
149
- sizeUnits: $[this.props.pointSizeUnits],
150
- positionsTexture: t.texture
151
- };
152
- e.shaderInputs.setProps({ cosmosPoints: i }), e.draw(this.context.renderPass);
153
- }
154
- _getModel() {
155
- return new q(this.context.device, {
156
- ...this.getShaders(),
157
- id: this.props.id,
158
- bufferLayout: this.getAttributeManager().getBufferLayouts(),
159
- geometry: new V({
160
- topology: "triangle-strip",
161
- attributes: {
162
- positions: { size: 3, value: new Float32Array([-1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0]) }
163
- }
164
- }),
165
- isInstanced: !0
166
- });
167
- }
168
- };
169
- T.layerName = "CosmosPointsLayer", T.defaultProps = nt;
170
- let D = T;
171
- const st = `layout(std140) uniform cosmosLinksUniforms {
172
- float pointsTextureSize;
173
- highp int widthUnits;
174
- float pointCount;
175
- } cosmosLinks;
176
- `, at = {
177
- name: "cosmosLinks",
178
- vs: st,
179
- uniformTypes: {
180
- pointsTextureSize: "f32",
181
- widthUnits: "i32",
182
- pointCount: "f32"
183
- }
184
- }, J = [94, 115, 194, 64], rt = (
185
- /* glsl */
186
- `#version 300 es
187
- #define SHADER_NAME cosmos-links-layer-vertex-shader
188
-
189
- in vec3 positions;
190
-
191
- in float instanceSourceIndices;
192
- in float instanceTargetIndices;
193
- in vec4 instanceColors;
194
- in float instanceWidths;
195
- in vec3 instancePickingColors;
196
-
197
- uniform sampler2D positionsTexture;
198
-
199
- out vec4 vColor;
200
- out vec2 uv;
201
-
202
- // Offset the vertex by half the link width, perpendicular to the link, in
203
- // screen space. offsetDirection is -1 (left) or 1 (right).
204
- vec2 getExtrusionOffset(vec2 lineClipspace, float offsetDirection, float width) {
205
- vec2 dirScreenspace = normalize(lineClipspace * project.viewportSize);
206
- dirScreenspace = vec2(-dirScreenspace.y, dirScreenspace.x);
207
- return dirScreenspace * offsetDirection * width / 2.0;
208
- }
209
-
210
- // The engine's isPointIndex: an integer in [0, pointCount). A fraction would
211
- // truncate to a neighbour, NaN would make int() undefined.
212
- bool namesPoint(float index, float pointCount) {
213
- return index >= 0.0 && index < pointCount && index == floor(index);
214
- }
215
-
216
- vec4 fetchPointPosition(float index, int textureSize) {
217
- int pointIndex = int(index);
218
- // Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates
219
- return texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);
220
- }
221
-
222
- void main(void) {
223
- // An endpoint that names no point (an index outside the point count) is
224
- // skipped, never dropped, so the instance index stays the link index — the
225
- // rule the engine applies to the same pair in its link grouping. Its texel
226
- // would be outside the live data.
227
- float pointCount = cosmosLinks.pointCount;
228
- bool namesNoPoint = !namesPoint(instanceSourceIndices, pointCount) || !namesPoint(instanceTargetIndices, pointCount);
229
-
230
- int textureSize = int(cosmosLinks.pointsTextureSize);
231
- vec4 sourcePosition = namesNoPoint ? vec4(0.0) : fetchPointPosition(instanceSourceIndices, textureSize);
232
- vec4 targetPosition = namesNoPoint ? vec4(0.0) : fetchPointPosition(instanceTargetIndices, textureSize);
233
-
234
- // A removed (absent) endpoint's texel is NaN — see PointPositionTexture;
235
- // collapse the quad, as for an endpoint that names no point, so it clips away
236
- if (namesNoPoint || isnan(sourcePosition.x) || isnan(targetPosition.x)) {
237
- gl_Position = vec4(0.0);
238
- vColor = vec4(0.0);
239
- uv = vec2(0.0);
240
- return;
241
- }
242
-
243
- vec3 sourceWorld = vec3(sourcePosition.xy, 0.0);
244
- vec3 targetWorld = vec3(targetPosition.xy, 0.0);
245
- geometry.worldPosition = sourceWorld;
246
- geometry.worldPositionAlt = targetWorld;
247
-
248
- vec4 sourceCommonspace;
249
- vec4 targetCommonspace;
250
- vec4 source = project_position_to_clipspace(sourceWorld, vec3(0.0), vec3(0.0), sourceCommonspace);
251
- vec4 target = project_position_to_clipspace(targetWorld, vec3(0.0), vec3(0.0), targetCommonspace);
252
-
253
- // positions.x selects the endpoint, positions.y the extrusion side
254
- float segmentIndex = positions.x;
255
- vec4 p = mix(source, target, segmentIndex);
256
- geometry.position = mix(sourceCommonspace, targetCommonspace, segmentIndex);
257
- uv = positions.xy;
258
- geometry.uv = uv;
259
- geometry.pickingColor = instancePickingColors;
260
-
261
- float widthPixels = project_size_to_pixel(instanceWidths, cosmosLinks.widthUnits);
262
-
263
- vec3 offset = vec3(getExtrusionOffset(target.xy - source.xy, positions.y, widthPixels), 0.0);
264
- DECKGL_FILTER_SIZE(offset, geometry);
265
- DECKGL_FILTER_GL_POSITION(p, geometry);
266
- gl_Position = p + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0);
267
-
268
- vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);
269
- DECKGL_FILTER_COLOR(vColor, geometry);
270
- }
271
- `
272
- ), lt = (
273
- /* glsl */
274
- `#version 300 es
275
- #define SHADER_NAME cosmos-links-layer-fragment-shader
276
-
277
- precision highp float;
278
-
279
- in vec4 vColor;
280
- in vec2 uv;
281
-
282
- out vec4 fragColor;
283
-
284
- void main(void) {
285
- geometry.uv = uv;
286
-
287
- fragColor = vColor;
288
- DECKGL_FILTER_COLOR(fragColor, geometry);
289
- }
290
- `
291
- ), ct = {
292
- getLinkSource: { type: "accessor", value: (u) => u.source },
293
- getLinkTarget: { type: "accessor", value: (u) => u.target },
294
- getLinkColor: { type: "accessor", value: J },
295
- getLinkWidth: { type: "accessor", value: 1 },
296
- linkWidthUnits: "pixels",
297
- parameters: { type: "object", value: b, optional: !0, compare: 2 }
298
- }, A = class A extends H {
299
- getShaders() {
300
- return super.getShaders({ vs: rt, fs: lt, modules: [B, K, at] });
301
- }
302
- initializeState() {
303
- this.getAttributeManager().addInstanced({
304
- instanceSourceIndices: {
305
- size: 1,
306
- accessor: "getLinkSource"
307
- },
308
- instanceTargetIndices: {
309
- size: 1,
310
- accessor: "getLinkTarget"
311
- },
312
- instanceColors: {
313
- size: 4,
314
- transition: !0,
315
- type: "unorm8",
316
- accessor: "getLinkColor",
317
- defaultValue: [...J]
318
- },
319
- instanceWidths: {
320
- size: 1,
321
- transition: !0,
322
- accessor: "getLinkWidth",
323
- defaultValue: 1
324
- }
325
- });
326
- }
327
- updateState(t) {
328
- var e;
329
- super.updateState(t), t.changeFlags.extensionsChanged && ((e = this.state.model) == null || e.destroy(), this.state.model = this._getModel(), this.getAttributeManager().invalidateAll());
330
- }
331
- draw() {
332
- const t = this.props.graph.getPointPositionTexture(), { model: e } = this.state;
333
- if (!t || !e || t.pointCount === 0) return;
334
- const i = {
335
- pointsTextureSize: t.textureSize,
336
- widthUnits: $[this.props.linkWidthUnits],
337
- pointCount: t.pointCount,
338
- positionsTexture: t.texture
339
- };
340
- e.shaderInputs.setProps({ cosmosLinks: i }), e.draw(this.context.renderPass);
341
- }
342
- _getModel() {
343
- return new q(this.context.device, {
344
- ...this.getShaders(),
345
- id: this.props.id,
346
- bufferLayout: this.getAttributeManager().getBufferLayouts(),
347
- geometry: new V({
348
- topology: "triangle-strip",
349
- attributes: {
350
- positions: { size: 3, value: new Float32Array([0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 0]) }
351
- }
352
- }),
353
- isInstanced: !0
354
- });
355
- }
356
- };
357
- A.layerName = "CosmosLinksLayer", A.defaultProps = ct;
358
- let E = A;
359
- const dt = {
1
+ import { COORDINATE_SYSTEM as it, Layer as nt } from "@deck.gl/core";
2
+ import { Graph as ot, defaultConfigValues as st } from "@cosmos.gl/graph";
3
+ const rt = [
4
+ "enableRenderLoop",
5
+ "backgroundColor",
6
+ "pixelRatio",
7
+ "showFPSMonitor",
8
+ "attribution",
9
+ "hoveredPointCursor",
10
+ "hoveredLinkCursor",
11
+ "initialZoomLevel",
12
+ "enableZoom",
13
+ "enableSimulationDuringZoom",
14
+ "enableDrag",
15
+ "fitViewOnInit",
16
+ "fitViewDelay",
17
+ "fitViewPadding",
18
+ "fitViewDuration",
19
+ "fitViewByPointsInRect",
20
+ "fitViewByPointIndices",
21
+ "simulationRepulsionFromMouse",
22
+ "enableRightClickRepulsion",
23
+ "onClick",
24
+ "onPointClick",
25
+ "onLinkClick",
26
+ "onBackgroundClick",
27
+ "onContextMenu",
28
+ "onPointContextMenu",
29
+ "onLinkContextMenu",
30
+ "onBackgroundContextMenu",
31
+ "onMouseMove",
32
+ "onPointMouseOver",
33
+ "onPointMouseOut",
34
+ "onLinkMouseOver",
35
+ "onLinkMouseOut",
36
+ "onZoomStart",
37
+ "onZoom",
38
+ "onZoomEnd",
39
+ "onDragStart",
40
+ "onDrag",
41
+ "onDragEnd"
42
+ ], N = (a) => (e) => e == null || typeof e == "function" || (a === "number" ? typeof e == "number" : Array.isArray(e) || ArrayBuffer.isView(e)), at = {
360
43
  points: { type: "object", value: null, optional: !0 },
361
44
  links: null,
362
45
  getPointId: { type: "accessor", value: null },
363
46
  getPointPosition: { type: "accessor", value: null },
364
- getPointSize: { type: "accessor", value: 4 },
365
- getPointColor: { type: "accessor", value: [74, 92, 191, 230] },
366
- pointSizeUnits: "pixels",
367
- getLinkSource: { type: "accessor", value: (u) => u.source },
368
- getLinkTarget: { type: "accessor", value: (u) => u.target },
369
- getLinkColor: { type: "accessor", value: [94, 115, 194, 64] },
370
- getLinkWidth: { type: "accessor", value: 1 },
371
- linkWidthUnits: "pixels",
47
+ getPointSize: { type: "accessor", value: null, validate: N("number") },
48
+ getPointColor: { type: "accessor", value: null, validate: N("color") },
49
+ getLinkSource: { type: "accessor", value: (a) => a.source },
50
+ getLinkTarget: { type: "accessor", value: (a) => a.target },
51
+ getLinkColor: { type: "accessor", value: null, validate: N("color") },
52
+ getLinkWidth: { type: "accessor", value: null, validate: N("number") },
372
53
  enablePointDrag: !1,
373
54
  dragReheatAlpha: 0.1,
374
55
  unpinOnDragEnd: !0,
375
56
  onPointDragStart: { type: "function", value: null, optional: !0 },
376
57
  onPointDrag: { type: "function", value: null, optional: !0 },
377
58
  onPointDragEnd: { type: "function", value: null, optional: !0 },
378
- simulation: { type: "object", value: null, optional: !0 },
379
- simulationConfig: { type: "object", value: {}, compare: 2 },
380
- onSimulationCreated: { type: "function", value: null, optional: !0 },
381
- // getSubLayerProps forwards `parameters` into every sublayer, so the
382
- // composite must carry the same pipeline-state default the primitives do
383
- parameters: { type: "object", value: b, optional: !0, compare: 2 }
384
- }, I = (u, t, e) => typeof u == "function" ? u(t, e) : u, U = /* @__PURE__ */ new WeakMap(), M = (u, t) => ({
385
- length: u.length / 2,
386
- attributes: {
387
- getLinkSource: { value: u, size: 1, stride: 8 },
388
- getLinkTarget: { value: u, size: 1, offset: 4, stride: 8 },
389
- ...(t == null ? void 0 : t.getLinkColor) && { getLinkColor: t.getLinkColor },
390
- ...(t == null ? void 0 : t.getLinkWidth) && { getLinkWidth: t.getLinkWidth }
59
+ config: { type: "object", value: {}, compare: 2 },
60
+ graph: { type: "object", value: null, optional: !0 },
61
+ onGraphCreated: { type: "function", value: null, optional: !0 },
62
+ onGraphDataLoaded: { type: "function", value: null, optional: !0 },
63
+ // cosmos draws its space coordinates as world coordinates; `modelMatrix` places the space
64
+ coordinateSystem: it.CARTESIAN
65
+ }, R = (a, e, t) => typeof a == "function" ? a(e, t) : a, W = (a, e) => a !== e && !(typeof a == "function" && typeof e == "function"), lt = (a, e) => {
66
+ if (a === e) return !0;
67
+ if (!a || !e) return !1;
68
+ const t = Object.keys(a);
69
+ return t.length !== Object.keys(e).length ? !1 : t.every((i) => {
70
+ const n = a[i], s = e[i];
71
+ return Array.isArray(n) && Array.isArray(s) ? n.length === s.length && n.every((o, r) => o === s[r]) : n === s;
72
+ });
73
+ }, Z = (a, e, t, i) => {
74
+ if (i) {
75
+ const { value: o } = i;
76
+ return o instanceof Float32Array ? o : Float32Array.from(o, (r) => r / 255);
77
+ }
78
+ const n = new Float32Array(a * 4), s = t ?? { length: a };
79
+ for (let o = 0; o < a; o += 1) {
80
+ const r = R(e, t == null ? void 0 : t[o], { index: o, data: s, target: [] });
81
+ n[o * 4] = r[0] / 255, n[o * 4 + 1] = r[1] / 255, n[o * 4 + 2] = r[2] / 255, n[o * 4 + 3] = (r[3] ?? 255) / 255;
82
+ }
83
+ return n;
84
+ }, q = (a, e, t, i) => {
85
+ if (i) {
86
+ const { value: o } = i;
87
+ return o instanceof Float32Array ? o : Float32Array.from(o);
88
+ }
89
+ const n = new Float32Array(a), s = t ?? { length: a };
90
+ for (let o = 0; o < a; o += 1)
91
+ n[o] = R(e, t == null ? void 0 : t[o], { index: o, data: s, target: [] });
92
+ return n;
93
+ }, $ = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), D = [0.25, 0.75], dt = 4096, K = (a, e) => {
94
+ const t = Math.fround(a);
95
+ return t === 1 / 0 ? e : t === -1 / 0 ? 0 : t;
96
+ };
97
+ class j {
98
+ constructor() {
99
+ this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0;
100
+ }
101
+ add(e, t) {
102
+ !Number.isFinite(e) || !Number.isFinite(t) || (e < this.minX && (this.minX = e), e > this.maxX && (this.maxX = e), t < this.minY && (this.minY = t), t > this.maxY && (this.maxY = t));
391
103
  }
392
- }), ut = Symbol("seeded"), j = new Float32Array(0), w = class w extends Q {
104
+ /** Layer.getBounds' shape, z = 0; `null` when no point was added. */
105
+ bounds() {
106
+ return this.minX > this.maxX ? null : [[this.minX, this.minY, 0], [this.maxX, this.maxY, 0]];
107
+ }
108
+ }
109
+ const ut = Symbol("seeded"), J = new Float32Array(0), b = new Float32Array(0), v = (a, e) => a != null || e != null, Q = (a) => a && !Array.isArray(a) ? a.attributes : void 0, tt = (a) => a && !Array.isArray(a) && !(a instanceof Float32Array) ? a.attributes : void 0, O = class O extends nt {
393
110
  get isLoaded() {
394
- var t;
395
- return super.isLoaded && !!((t = this.state) != null && t.isReady);
111
+ var e;
112
+ return super.isLoaded && !!((e = this.state) != null && e.isReady);
396
113
  }
397
114
  initializeState() {
398
- const { device: t, timeline: e } = this.context;
399
- if (t.type !== "webgl")
115
+ const { device: e, timeline: t } = this.context;
116
+ if (e.type !== "webgl")
400
117
  throw new Error(
401
- `@cosmos.gl/deck-layers requires a WebGL 2 device — the cosmos.gl simulation is WebGL-only, got '${t.type}'`
118
+ `@cosmos.gl/deck-layers requires a WebGL 2 device — cosmos.gl is WebGL-only, got '${e.type}'`
402
119
  );
403
120
  this.state = {
404
- providedSimulation: null,
121
+ providedGraph: null,
405
122
  isReady: !1,
406
123
  isIngestPending: !1,
407
124
  hasLoaded: !1,
408
125
  pointCount: 0,
409
- pointsData: { length: 0 },
410
- linksData: null,
411
- linkIndices: null,
126
+ linkCount: 0,
127
+ keptLinks: null,
412
128
  draggedPointIndex: null,
129
+ holdsHover: !1,
413
130
  // Step the simulation exactly once per animation frame, independent of
414
- // draw passes (draw runs per viewport and again while picking)
415
- animationHandle: e.attachAnimation({ setTime: (i) => this._onTimelineTick(i) })
416
- }, this._attachSimulation(this.props.simulation ?? null);
417
- }
418
- updateState(t) {
419
- super.updateState(t);
420
- const { props: e, oldProps: i, changeFlags: n } = t, a = e.simulation ?? null, o = a !== this.state.providedSimulation;
421
- o && (this._releaseSimulation(), this._attachSimulation(a));
422
- const r = this.state.simulation;
131
+ // draw passes (draw runs per viewport)
132
+ animationHandle: t.attachAnimation({ setTime: (i) => this._onTimelineTick(i) })
133
+ }, this._attachGraph(this.props.graph ?? null);
134
+ }
135
+ updateState(e) {
136
+ super.updateState(e);
137
+ const { props: t, oldProps: i, changeFlags: n } = e, s = t.graph ?? null, o = s !== this.state.providedGraph;
138
+ o && (this._releaseGraph(), this._attachGraph(s));
139
+ const r = this.state.graph;
423
140
  if (!r) return;
424
- !a && n.propsChanged && e.simulationConfig !== i.simulationConfig && r.setConfig(e.simulationConfig);
425
- const l = typeof n.updateTriggersChanged == "object" ? n.updateTriggersChanged : void 0, d = o || e.points !== i.points || !!(l != null && l.getPointPosition), C = !!(l != null && l.getPointId), y = o || e.links !== i.links || !!(l != null && l.getLinkSource || l != null && l.getLinkTarget) || C;
426
- !d && !y || (e.points ? this.state.isReady ? this._updateSimulationData(d, y, C) : this.state.isIngestPending = !0 : (e.links && console.warn("@cosmos.gl/deck-layers: `links` is ignored without `points` — load them into the simulation instead"), this.state.isIngestPending = !1, this.state.hasLoaded = !1, this.state.isReady && this._syncFromSimulation(!0)));
427
- }
428
- renderLayers() {
429
- const { simulation: t, isReady: e, pointCount: i, pointsData: n, linksData: a, linkIndices: o } = this.state;
430
- if (!t || !e || i === 0) return null;
431
- const { getPointSize: r, getPointColor: l, pointSizeUnits: d, getLinkColor: C, getLinkWidth: y, linkWidthUnits: h } = this.props, f = this.props.updateTriggers ?? {}, p = [];
432
- return a && p.push(
433
- new E(
434
- this.getSubLayerProps({
435
- id: "links",
436
- updateTriggers: {
437
- getLinkSource: f.getLinkSource,
438
- getLinkTarget: f.getLinkTarget,
439
- getLinkColor: f.getLinkColor,
440
- getLinkWidth: f.getLinkWidth
441
- }
442
- }),
443
- {
444
- data: a,
445
- graph: t,
446
- getLinkColor: C,
447
- getLinkWidth: y,
448
- linkWidthUnits: h,
449
- // getSubLayerProps does not forward `transitions`
450
- transitions: this.props.transitions
451
- },
452
- Array.isArray(a) && o ? {
453
- // Array links read the endpoints resolved at ingest, so the
454
- // rendered links are exactly the simulated ones
455
- getLinkSource: (k, { index: g }) => o[g * 2],
456
- getLinkTarget: (k, { index: g }) => o[g * 2 + 1]
457
- } : {}
458
- )
459
- ), p.push(
460
- new D(
461
- this.getSubLayerProps({
462
- id: "points",
463
- updateTriggers: {
464
- getPointSize: f.getPointSize,
465
- getPointColor: f.getPointColor
141
+ !s && !o && !lt(t.config, i.config) && r.setConfig(this._graphConfig());
142
+ const l = typeof n.updateTriggersChanged == "object" ? n.updateTriggersChanged : void 0, g = (_) => !!(l != null && l.all || l != null && l[_]), d = o || t.points !== i.points || g("getPointPosition"), f = g("getPointId"), u = o || t.links !== i.links || g("getLinkSource") || g("getLinkTarget") || f, c = d || g("getPointColor") || g("getPointSize") || W(t.getPointColor, i.getPointColor) || W(t.getPointSize, i.getPointSize), x = u || g("getLinkColor") || g("getLinkWidth") || W(t.getLinkColor, i.getLinkColor) || W(t.getLinkWidth, i.getLinkWidth);
143
+ if (!d && !u && !c && !x) return;
144
+ const k = !!i.points && !o, y = Q(i.points), C = Q(t.points), m = tt(i.links), p = tt(t.links), S = (_, M) => k && _ && !M, T = {
145
+ pointColorUnset: S(v(i.getPointColor, y == null ? void 0 : y.getPointColor), v(t.getPointColor, C == null ? void 0 : C.getPointColor)),
146
+ pointSizeUnset: S(v(i.getPointSize, y == null ? void 0 : y.getPointSize), v(t.getPointSize, C == null ? void 0 : C.getPointSize)),
147
+ linkColorUnset: S(v(i.getLinkColor, m == null ? void 0 : m.getLinkColor), v(t.getLinkColor, p == null ? void 0 : p.getLinkColor)),
148
+ linkWidthUnset: S(v(i.getLinkWidth, m == null ? void 0 : m.getLinkWidth), v(t.getLinkWidth, p == null ? void 0 : p.getLinkWidth))
149
+ };
150
+ t.points ? this.state.isReady ? this._load({ pointsChanged: d, linksChanged: u, idsChanged: f, pointStyleChanged: c, linkStyleChanged: x, ...T }) : this.state.isIngestPending = !0 : (t.links && !this.state.linksWarned && (this.state.linksWarned = !0, console.warn("@cosmos.gl/deck-layers: `links` is ignored without `points` — load them into the graph instead")), this.state.isIngestPending = !1, this.state.hasLoaded = !1);
151
+ }
152
+ draw(e) {
153
+ var o, r, l, g;
154
+ const { graph: t, isReady: i } = this.state;
155
+ if (!t || !i) return;
156
+ const { viewport: n } = this.context, s = this._viewTransform(t, n);
157
+ if (s) {
158
+ if (t.setViewTransform(s, [n.width, n.height]), (r = (o = e.shaderModuleProps) == null ? void 0 : o.picking) != null && r.isActive) {
159
+ t.drawToRenderPass(this.context.renderPass, {
160
+ picking: {
161
+ alpha: ((g = (l = e.parameters) == null ? void 0 : l.blendColor) == null ? void 0 : g[3]) ?? 1,
162
+ linkIndexOffset: t.graph.pointsNumber ?? 0
466
163
  }
467
- }),
468
- {
469
- data: n,
470
- graph: t,
471
- getPointSize: r,
472
- getPointColor: l,
473
- pointSizeUnits: d,
474
- // getSubLayerProps does not forward `transitions`
475
- transitions: this.props.transitions
476
- }
477
- )
478
- ), p;
479
- }
480
- onDragStart(t, e) {
481
- var r, l, d;
482
- const { simulation: i } = this.state, { enablePointDrag: n, dragReheatAlpha: a } = this.props, o = t;
483
- return !n || !i || o.elementType !== "point" || t.index < 0 ? !1 : (this.state.draggedPointIndex = t.index, i.setPinnedPoint(t.index, !0), a !== null && i.start(a), (r = e.stopImmediatePropagation) == null || r.call(e), (d = (l = this.props).onPointDragStart) == null || d.call(l, o), !0);
164
+ });
165
+ return;
166
+ }
167
+ t.drawToRenderPass(this.context.renderPass);
168
+ }
484
169
  }
485
- onDrag(t, e) {
486
- var r, l, d;
487
- const { simulation: i, draggedPointIndex: n } = this.state;
170
+ getPickingInfo({ info: e }) {
171
+ var r;
172
+ const t = e, i = this.state.graph;
173
+ if (!i || e.index < 0) return t;
174
+ const n = i.graph.pointsNumber ?? 0, { points: s, links: o } = this.props;
175
+ return e.index >= n ? (t.elementType = "link", t.index = e.index - n, t.object = Array.isArray(o) ? (r = this.state.keptLinks) == null ? void 0 : r[t.index] : void 0) : (t.elementType = "point", t.object = Array.isArray(s) ? s[e.index] : void 0), t;
176
+ }
177
+ onDragStart(e, t) {
178
+ var r, l, g;
179
+ const { graph: i } = this.state, { enablePointDrag: n, dragReheatAlpha: s } = this.props, o = e;
180
+ return !n || !i || o.elementType !== "point" || e.index < 0 ? !1 : (this.state.draggedPointIndex = e.index, i.setPinnedPoint(e.index, !0), s !== null && i.start(s), (r = t.stopImmediatePropagation) == null || r.call(t), (g = (l = this.props).onPointDragStart) == null || g.call(l, o), !0);
181
+ }
182
+ onDrag(e, t) {
183
+ var o, r, l;
184
+ const { graph: i, draggedPointIndex: n } = this.state;
488
185
  if (!i || n === null) return !1;
489
- const [a, o] = this._dragCoordinate(t);
490
- return i.setPointPosition(n, a, o), (r = e.stopImmediatePropagation) == null || r.call(e), (this.getCurrentLayer() ?? this).setNeedsRedraw(), (d = (l = this.props).onPointDrag) == null || d.call(l, t), !0;
491
- }
492
- onDragEnd(t, e) {
493
- var a, o, r;
494
- const { simulation: i, draggedPointIndex: n } = this.state;
495
- return !i || n === null ? !1 : (this.props.unpinOnDragEnd && i.setPinnedPoint(n, !1), this.state.draggedPointIndex = null, (a = e.stopImmediatePropagation) == null || a.call(e), (r = (o = this.props).onPointDragEnd) == null || r.call(o, t), !0);
186
+ const s = this._dragPosition(i, e);
187
+ return s && i.setPointPosition(n, s[0], s[1]), (o = t.stopImmediatePropagation) == null || o.call(t), (this.getCurrentLayer() ?? this).setNeedsRedraw(), (l = (r = this.props).onPointDrag) == null || l.call(r, e), !0;
496
188
  }
497
- getPickingInfo(t) {
498
- const e = t.info;
499
- return t.sourceLayer && (e.elementType = t.sourceLayer.id.endsWith("-links") ? "link" : "point"), e;
189
+ onDragEnd(e, t) {
190
+ var s, o, r;
191
+ const { graph: i, draggedPointIndex: n } = this.state;
192
+ return !i || n === null ? !1 : (this.props.unpinOnDragEnd && i.setPinnedPoint(n, !1), this.state.draggedPointIndex = null, (s = t.stopImmediatePropagation) == null || s.call(t), (r = (o = this.props).onPointDragEnd) == null || r.call(o, e), !0);
500
193
  }
501
- /** The whole simulation space; lets deck's viewport helpers frame the graph. */
194
+ /**
195
+ * The box around the graph's points, `[[minX, minY, 0], [maxX, maxY, 0]]`, for an
196
+ * application to frame the layer with. In space coordinates, before `modelMatrix`: map it
197
+ * through `modelMatrix` (and, on a map, unproject it) before fitting a viewport to it.
198
+ * deck.gl's core does not call it; its mask effect reads it from every mask layer and its
199
+ * collision-filter effect from every layer carrying that extension, each on every frame.
200
+ *
201
+ * `spaceSize` bounds no position — a layout grows past its square as far as its forces
202
+ * take it — so the box is measured from the live positions, read back from the GPU. The
203
+ * read does not stall the frame: it is asynchronous, started by a call that finds the
204
+ * positions changed since the box was measured, one at a time, and the box it returns is
205
+ * the last one measured. While a read is on its way the layer holds the graph's step, as
206
+ * the engine's own render loop holds its frame for a copy: the read that completes a copy
207
+ * waits for every command queued before it, and a step queued behind the copy would be
208
+ * that wait. (A graph the application steps itself is not held.) While points move the
209
+ * box trails the drawn frame, by a frame or so, and a call made before the first read
210
+ * lands — or before the first read of a newly loaded dataset — gets the input box below.
211
+ * When a read lands the layer asks for a redraw, so a consumer reading the box every
212
+ * frame has the new one on the next. A layer nobody asks reads nothing. Absent points
213
+ * (NaN) are left out.
214
+ *
215
+ * Until the graph holds positions (its device is still initializing) or the first read
216
+ * has landed, the box is that of the positions the layer is about to load or has loaded:
217
+ * `initialPositions`, or `getPointPosition` over the point objects, plus the middle half
218
+ * of the space where unseeded points are placed — where the points start, so a view can
219
+ * be framed before the first frame.
220
+ *
221
+ * When there is nothing to measure — no points yet, every point absent, or positions the
222
+ * graph rescales on load (`rescalePositions: true`), which it centres on the space — the
223
+ * box is the space's square, `[[0, 0, 0], [spaceSize, spaceSize, 0]]`: where the graph
224
+ * starts, and what this method returned before layouts could leave the square. It is
225
+ * never `null`; the declared type keeps deck's `Layer.getBounds` contract, so a subclass
226
+ * may still override it with deck's own signature.
227
+ */
502
228
  getBounds() {
503
- const t = this._spaceSize();
504
- return [[0, 0, 0], [t, t, 0]];
229
+ const { state: e } = this, t = e == null ? void 0 : e.graph, i = t == null ? void 0 : t.getPointPositionTexture();
230
+ if (t && i && i.pointCount > 0 && (i.version !== e.measuredBoundsVersion && !e.isMeasuringBounds && this._measureBounds(t, i.version), e.measuredBounds !== void 0))
231
+ return e.measuredBounds ?? this._spaceSquare();
232
+ const n = new j();
233
+ return this._addInputPositions(n), n.bounds() ?? this._spaceSquare();
505
234
  }
506
- finalizeState(t) {
507
- var e;
508
- ((e = this.state) == null ? void 0 : e.animationHandle) !== void 0 && this.context.timeline.detachAnimation(this.state.animationHandle), this.state && this._releaseSimulation(), super.finalizeState(t);
235
+ finalizeState(e) {
236
+ var t;
237
+ ((t = this.state) == null ? void 0 : t.animationHandle) !== void 0 && this.context.timeline.detachAnimation(this.state.animationHandle), this.state && this._releaseGraph(), super.finalizeState(e);
238
+ }
239
+ /** No deck attributes: cosmos.gl holds every channel and draws them itself. */
240
+ _getAttributeManager() {
241
+ return null;
509
242
  }
510
243
  /**
511
- * Points and links have separate index spaces, so the same picking color
512
- * exists in both sublayers: highlight only the sublayer that was hovered
513
- * and clear the other, or hovering point N would also tint link N.
244
+ * deck's auto-highlight, through cosmos.gl's own hover emphasis: the hovered point
245
+ * gets the hover ring, the hovered link the hovered-link width and color. It is the
246
+ * graph's host hover, so the graph's config — focus included — stays the
247
+ * application's. deck's picking module has no model of ours to tint, so
248
+ * `highlightColor` does not apply.
514
249
  */
515
- _updateAutoHighlight(t) {
516
- var e;
517
- for (const i of this.getSubLayers())
518
- i.id === ((e = t.sourceLayer) == null ? void 0 : e.id) ? i.updateAutoHighlight(t) : i.updateAutoHighlight({ ...t, picked: !1 });
250
+ _updateAutoHighlight(e) {
251
+ const { graph: t, isReady: i } = this.state;
252
+ if (!t || !i) return;
253
+ const n = e.picked && e.index >= 0 ? e.elementType : void 0, s = n === "point" ? e.index : void 0, o = n === "link" ? e.index : void 0;
254
+ t.setHostHoveredPoint(s), t.setHostHoveredLink(o), this.state.holdsHover = s !== void 0 || o !== void 0, this.setNeedsRedraw();
519
255
  }
520
- /** Adopts the provided simulation, or creates one on deck's device when `provided` is `null`. */
521
- _attachSimulation(t) {
522
- var n, a;
523
- const { device: e } = this.context, i = t ?? new X(this.props.simulationConfig, Promise.resolve(e));
256
+ /**
257
+ * The pointer in space coordinates, through the view of the viewport the pointer
258
+ * is in — the same derivation `draw` hands cosmos, inverted — under a map as well
259
+ * as an orthographic view. Not through the view cosmos holds: that is whichever
260
+ * viewport drew the graph last, a thumbnail's as easily as the one being dragged
261
+ * in. Pixels are relative to that viewport. Where the view cannot be derived the
262
+ * point stays where it is.
263
+ */
264
+ _dragPosition(e, t) {
265
+ const i = t.viewport ?? this.context.viewport, n = this._viewTransform(e, i);
266
+ return n ? [(t.x - i.x - n.originX) / n.k, (n.originY - (t.y - i.y)) / n.k] : null;
267
+ }
268
+ /** Adopts the provided graph, or creates a headless one on deck's device when `provided` is `null`. */
269
+ _attachGraph(e) {
270
+ var n, s;
271
+ const { device: t } = this.context, i = e ?? new ot(null, this._graphConfig(), Promise.resolve(t));
524
272
  this.setState({
525
- simulation: i,
526
- providedSimulation: t,
273
+ graph: i,
274
+ providedGraph: e,
527
275
  isReady: !1,
528
276
  hasLoaded: !1,
529
277
  loadedPositions: void 0,
530
278
  loadedPairs: null,
531
279
  idToIndex: null,
532
- draggedPointIndex: null
533
- }), t || (a = (n = this.props).onSimulationCreated) == null || a.call(n, i), i.ready.then(() => {
280
+ keptLinks: null
281
+ }), e || (s = (n = this.props).onGraphCreated) == null || s.call(n, i), i.ready.then(() => {
534
282
  var r;
535
- if (((r = this.state) == null ? void 0 : r.simulation) !== i) return;
283
+ if (((r = this.state) == null ? void 0 : r.graph) !== i) return;
536
284
  const o = this.getCurrentLayer() ?? this;
537
- if (i.device !== o.context.device) {
285
+ if (i.simulation.device !== o.context.device) {
538
286
  console.error(
539
- "@cosmos.gl/deck-layers: the provided simulation runs on a different device than deck — construct it with the device from deck's onDeviceInitialized"
287
+ "@cosmos.gl/deck-layers: the provided graph runs on a different device than deck — construct it with the device from deck's onDeviceInitialized"
540
288
  );
541
289
  return;
542
290
  }
543
- o.state.isIngestPending ? (o.state.isIngestPending = !1, o._updateSimulationData(!0, !0, !0)) : o.props.points || o._syncFromSimulation(!0), o.setState({ isReady: !0 });
291
+ o.state.isIngestPending && (o.state.isIngestPending = !1, o._load({
292
+ pointsChanged: !0,
293
+ linksChanged: !0,
294
+ idsChanged: !0,
295
+ pointStyleChanged: !0,
296
+ linkStyleChanged: !0,
297
+ pointColorUnset: !1,
298
+ pointSizeUnset: !1,
299
+ linkColorUnset: !1,
300
+ linkWidthUnset: !1
301
+ })), o.setState({ isReady: !0 });
544
302
  }).catch((o) => {
545
- console.error("@cosmos.gl/deck-layers: simulation failed to initialize", o);
303
+ console.error("@cosmos.gl/deck-layers: the graph failed to initialize", o);
304
+ });
305
+ }
306
+ /**
307
+ * Destroys a layer-created graph; a provided one is left to the application, without
308
+ * the hover this layer put on it. deck sends no leave to a layer it removes.
309
+ */
310
+ _releaseGraph() {
311
+ const { graph: e, providedGraph: t, holdsHover: i } = this.state;
312
+ e && t ? i && (e.setHostHoveredPoint(void 0), e.setHostHoveredLink(void 0)) : e && e.destroy(), this.state.graph = void 0, this.state.holdsHover = !1, this.state.measuredBounds = void 0, this.state.measuredBoundsVersion = void 0, this.state.isMeasuringBounds = !1;
313
+ }
314
+ /**
315
+ * Starts one asynchronous read of the live positions and keeps its box for `getBounds`,
316
+ * stamped with the texture version the read was asked at. A read that lands after the
317
+ * layer let go of the graph is dropped; an empty result (nothing to read, or the point
318
+ * count changed under the copy) leaves the box as it was, and the next call asks again.
319
+ */
320
+ _measureBounds(e, t) {
321
+ const { state: i } = this, n = i.loadSerial;
322
+ i.isMeasuringBounds = !0, z.set(e, (z.get(e) ?? 0) + 1);
323
+ const s = () => {
324
+ z.set(e, Math.max(0, (z.get(e) ?? 1) - 1));
325
+ };
326
+ e.getPointPositionsAsync().then((o) => {
327
+ if (s(), i.graph !== e) return;
328
+ if (i.isMeasuringBounds = !1, i.loadSerial !== n) {
329
+ (this.getCurrentLayer() ?? this).setNeedsRedraw();
330
+ return;
331
+ }
332
+ if (o.length === 0) return;
333
+ const r = new j();
334
+ for (let l = 0; l < o.length; l += 2) r.add(o[l], o[l + 1]);
335
+ i.measuredBounds = r.bounds(), i.measuredBoundsVersion = t, (this.getCurrentLayer() ?? this).setNeedsRedraw();
336
+ }, () => {
337
+ s(), i.graph === e && (i.isMeasuringBounds = !1, (this.getCurrentLayer() ?? this).setNeedsRedraw());
546
338
  });
547
339
  }
548
- /** Destroys a layer-created simulation; a provided one is left to the application. */
549
- _releaseSimulation() {
550
- const { simulation: t, providedSimulation: e } = this.state;
551
- t && !e && t.destroy(), this.state.simulation = void 0;
340
+ /** The space's square, the stand-in extent when there is nothing to measure (see `getBounds`). */
341
+ _spaceSquare() {
342
+ const e = this._spaceSize();
343
+ return [[0, 0, 0], [e, e, 0]];
552
344
  }
553
- /** The simulation's space size — authoritative for a provided simulation too. */
345
+ /**
346
+ * Adds the positions the layer would load to `box` (see `getBounds`): the given ones,
347
+ * placed as the engine will place them, and the square unseeded points are drawn in.
348
+ * Nothing when they are rescaled on load.
349
+ */
350
+ _addInputPositions(e) {
351
+ var r, l, g;
352
+ const { points: t, getPointPosition: i } = this.props;
353
+ if (!t || ((g = ((l = (r = this.state) == null ? void 0 : r.graph) == null ? void 0 : l.config) ?? this.props.config) == null ? void 0 : g.rescalePositions) === !0) return;
354
+ const n = this._spaceSize(), s = (d, f) => {
355
+ Number.isNaN(d) || Number.isNaN(f) || e.add(K(d, n), K(f, n));
356
+ };
357
+ let o = !1;
358
+ if (Array.isArray(t)) {
359
+ const d = t;
360
+ for (let f = 0; f < d.length; f += 1) {
361
+ const u = { index: f, data: d, target: [] }, c = i ? R(i, d[f], u) : null;
362
+ c ? s(c[0], c[1]) : o = !0;
363
+ }
364
+ } else {
365
+ const { length: d, initialPositions: f } = t;
366
+ if (f)
367
+ for (let u = 0; u < d; u += 1) s(f[u * 2], f[u * 2 + 1]);
368
+ else o = d > 0;
369
+ }
370
+ o && (e.add(n * D[0], n * D[0]), e.add(n * D[1], n * D[1]));
371
+ }
372
+ /**
373
+ * The length the engine's placement rules are fractions of: the infinite-input edge, the
374
+ * unseeded square, and the stand-in extent. The graph's own, validated, length once
375
+ * there is a graph — from its construction, so the default when its config's `spaceSize`
376
+ * is not a usable size, and authoritative for a provided graph — the config's before.
377
+ * It sizes nothing.
378
+ */
554
379
  _spaceSize() {
555
- var t, e, i;
556
- return ((e = (t = this.state) == null ? void 0 : t.simulation) == null ? void 0 : e.config.spaceSize) ?? ((i = this.props.simulationConfig) == null ? void 0 : i.spaceSize) ?? Y.spaceSize;
380
+ var i, n, s;
381
+ const e = (n = (i = this.state) == null ? void 0 : i.graph) == null ? void 0 : n.simulation.store.referenceLength;
382
+ if (e !== void 0) return e;
383
+ const t = (s = this.props.config) == null ? void 0 : s.spaceSize;
384
+ return t === void 0 || !Number.isFinite(t) || t <= 0 ? st.spaceSize : Math.max(t, 2);
385
+ }
386
+ /**
387
+ * The config for a layer-created graph: the prop without the keys deck owns,
388
+ * and the pixel ratio deck's canvas draws at, so cosmos sizes pixels alike.
389
+ */
390
+ _graphConfig() {
391
+ const e = { ...this.props.config };
392
+ for (const t of rt) delete e[t];
393
+ return e.pixelRatio = this._pixelRatio(), e;
557
394
  }
558
- _onTimelineTick(t) {
559
- const { simulation: e, isReady: i } = this.state ?? {};
560
- if (!e || !i) return;
561
- const n = this.getCurrentLayer() ?? this;
562
- n.props.points || n._syncFromSimulation(), e.isSimulationRunning && (U.get(e) !== t && (U.set(e, t), e.step()), n.setNeedsRedraw());
395
+ /** deck's device pixels per CSS pixel, as its canvas context reports them. */
396
+ _pixelRatio() {
397
+ var i;
398
+ const e = this.context.device.canvasContext, t = (i = e == null ? void 0 : e.cssToDeviceRatio) == null ? void 0 : i.call(e);
399
+ return t && Number.isFinite(t) ? t : typeof window < "u" && window.devicePixelRatio || 1;
563
400
  }
564
401
  /**
565
- * Without `points`: builds the render data from what the simulation holds —
566
- * its point count and links — and rebuilds it when either changes. Runs every
567
- * tick, so it only compares until something differs.
402
+ * cosmos's view for a deck viewport: a uniform scale `k` (pixels per space
403
+ * unit) and a translation, per `setViewTransform`'s space → screen formula,
404
+ * inverted. Three anchors through deck's projection — the space origin, its
405
+ * x axis, its y axis — give the scale and tell whether the view is one cosmos
406
+ * can draw: unrotated, unpitched, y up. The translation then follows from where
407
+ * the space origin lands and the world origin cosmos centres its screen on, read
408
+ * from the engine (`spaceSize / 2` on both axes, after the engine's own space-size
409
+ * adjustment). The space origin's pixel is returned too, for mapping the other way.
568
410
  */
569
- _syncFromSimulation(t = !1) {
570
- const { simulation: e } = this.state;
571
- if (!e) return;
572
- const i = e.data.pointsNumber ?? 0, n = e.data.links ?? null;
573
- !t && i === this.state.pointCount && n === this.state.followedLinks || this.setState({
574
- pointCount: i,
575
- pointsData: { length: i },
576
- linksData: n && n.length > 0 ? M(n) : null,
577
- linkIndices: null,
578
- followedLinks: n
579
- });
411
+ _viewTransform(e, t) {
412
+ const { worldOrigin: i } = e.simulation.store, n = dt, s = this.props.modelMatrix, o = (p, S) => {
413
+ const T = s ? s[0] * p + s[4] * S + s[12] : p, _ = s ? s[1] * p + s[5] * S + s[13] : S, M = t.unprojectPosition([T, _, 0]), E = t.project(M);
414
+ return [E[0], E[1]];
415
+ }, [r, l] = o(0, 0), [g, d] = o(n, 0), [f, u] = o(0, n), c = (g - r) / n, x = 1e-3 * Math.max(1, Math.abs(g - r)), k = Math.abs(d - l) > x || Math.abs(f - r) > x, y = u > l;
416
+ if (k || y || !(c > 0))
417
+ return this.state.viewWarned || (this.state.viewWarned = !0, console.warn(
418
+ "@cosmos.gl/deck-layers: cosmos.gl draws under a flat, north-up, y-up view only — use OrthographicView({ flipY: false }) or a map at pitch 0 and bearing 0. The graph is not drawn."
419
+ )), null;
420
+ this.state.viewWarned = !1;
421
+ const [C, m] = i;
422
+ return {
423
+ k: c,
424
+ x: r - c * (t.width / 2 - C),
425
+ y: l - c * (m + t.height / 2),
426
+ originX: r,
427
+ originY: l
428
+ };
580
429
  }
581
- _dragCoordinate(t) {
582
- if (t.coordinate) return [t.coordinate[0], t.coordinate[1]];
583
- const e = this.context.viewport.unproject([t.x, t.y]);
584
- return [e[0], e[1]];
430
+ _onTimelineTick(e) {
431
+ const { graph: t, isReady: i } = this.state ?? {};
432
+ !t || !i || !t.isSimulationRunning || ($.get(t) !== e && !z.get(t) && ($.set(t, e), t.step()), (this.getCurrentLayer() ?? this).setNeedsRedraw());
585
433
  }
586
434
  /**
587
- * Load mode: puts the layer's `points` and `links` into the simulation and
588
- * builds the render data from them. Each channel is sent only when its own
589
- * input changed — a new `points` or `links` object with the same positions
590
- * or pairs restyles in place and leaves the layout alone. A changed id map
591
- * re-resolves array links without touching the positions.
435
+ * Load mode: puts the layer's `points`, `links` and styles into the graph.
436
+ * Each channel is sent only when its own input changed — a restyle leaves the
437
+ * layout alone, a changed id map re-resolves array links without touching the
438
+ * positions.
592
439
  */
593
- _updateSimulationData(t, e, i) {
594
- const n = this.state.simulation;
595
- if (!n) return;
596
- const { points: a, links: o, getPointId: r, getPointPosition: l } = this.props;
597
- if (!a) return;
598
- const d = !this.state.hasLoaded, C = this._spaceSize(), y = () => C * (0.25 + Math.random() * 0.5);
599
- let h, f, p = null, k = this.state.loadedPositions, g = this.state.idToIndex ?? null;
600
- if (Array.isArray(a)) {
601
- const s = a;
602
- if (h = s.length, f = s, d || t) {
603
- p = new Float32Array(h * 2), g = r ? /* @__PURE__ */ new Map() : null;
604
- for (let c = 0; c < h; c += 1) {
605
- const m = s[c], L = { index: c, data: s, target: [] }, S = l ? I(l, m, L) : null;
606
- p[c * 2] = S ? S[0] : y(), p[c * 2 + 1] = S ? S[1] : y(), g && r && g.set(I(r, m, L), c);
440
+ _load(e) {
441
+ var F, G;
442
+ const t = this.state.graph;
443
+ if (!t) return;
444
+ const { points: i, links: n, getPointId: s, getPointPosition: o } = this.props;
445
+ if (!i) return;
446
+ const r = !this.state.hasLoaded, l = this._spaceSize(), g = () => l * t.simulation.store.getRandomFloat(D[0], D[1]);
447
+ let d, f = null, u, c = null, x = this.state.loadedPositions, k = this.state.idToIndex ?? null;
448
+ if (Array.isArray(i)) {
449
+ const h = i;
450
+ if (d = h.length, f = h, r || e.pointsChanged) {
451
+ c = new Float32Array(d * 2), k = s ? /* @__PURE__ */ new Map() : null;
452
+ for (let P = 0; P < d; P += 1) {
453
+ const L = h[P], B = { index: P, data: h, target: [] }, w = o ? R(o, L, B) : null;
454
+ c[P * 2] = w ? w[0] : g(), c[P * 2 + 1] = w ? w[1] : g(), k && s && k.set(R(s, L, B), P);
607
455
  }
608
- k = s;
609
- } else if (i && (g = r ? /* @__PURE__ */ new Map() : null, g && r))
610
- for (let c = 0; c < h; c += 1) {
611
- const m = { index: c, data: s, target: [] };
612
- g.set(I(r, s[c], m), c);
456
+ x = h;
457
+ } else if (e.idsChanged && (k = s ? /* @__PURE__ */ new Map() : null, k && s))
458
+ for (let P = 0; P < d; P += 1) {
459
+ const L = { index: P, data: h, target: [] };
460
+ k.set(R(s, h[P], L), P);
613
461
  }
614
462
  } else {
615
- const s = a;
616
- h = s.length, f = s.attributes ? { length: h, attributes: s.attributes } : { length: h }, g = null;
617
- const c = s.initialPositions ?? ut;
618
- if (d || c !== this.state.loadedPositions || h !== this.state.pointCount) {
619
- if (s.initialPositions)
620
- p = s.initialPositions;
463
+ const h = i;
464
+ d = h.length, u = h.attributes, k = null;
465
+ const P = h.initialPositions ?? ut;
466
+ if (r || P !== this.state.loadedPositions || d !== this.state.pointCount) {
467
+ if (h.initialPositions)
468
+ c = h.initialPositions;
621
469
  else {
622
- p = new Float32Array(h * 2);
623
- for (let m = 0; m < p.length; m += 1) p[m] = y();
470
+ c = new Float32Array(d * 2);
471
+ for (let L = 0; L < c.length; L += 1) c[L] = g();
624
472
  }
625
- k = c;
473
+ x = P;
626
474
  }
627
475
  }
628
- let x = null, _ = this.state.linksData, z = this.state.linkIndices;
629
- if (o instanceof Float32Array || o && !Array.isArray(o) && "pairs" in o) {
630
- const s = o instanceof Float32Array ? o : o.pairs;
631
- _ = M(s, o instanceof Float32Array ? void 0 : o.attributes), z = null, (d || s !== this.state.loadedPairs) && (x = s);
632
- } else if (Array.isArray(o)) {
633
- if (d || e || p) {
634
- const s = o, { getLinkSource: c, getLinkTarget: m } = this.props, L = (P) => {
635
- const v = g ? g.get(P) : P;
636
- return typeof v == "number" && Number.isInteger(v) && v >= 0 && v < h ? v : void 0;
637
- }, S = [], R = [];
638
- for (let P = 0; P < s.length; P += 1) {
639
- const v = s[P], N = { index: P, data: s, target: [] }, O = L(I(c, v, N)), W = L(I(m, v, N));
640
- O === void 0 || W === void 0 || (S.push(v), R.push(O, W));
476
+ let y = null, C = this.state.linkCount, m = this.state.keptLinks, p;
477
+ if (n instanceof Float32Array || n && !Array.isArray(n) && "pairs" in n) {
478
+ const h = n instanceof Float32Array ? n : n.pairs;
479
+ p = n instanceof Float32Array ? void 0 : n.attributes, m = null, C = h.length / 2, (r || h !== this.state.loadedPairs) && (y = h);
480
+ } else if (Array.isArray(n)) {
481
+ if (r || e.linksChanged || c) {
482
+ const h = n, { getLinkSource: P, getLinkTarget: L } = this.props, B = (A) => {
483
+ const I = k ? k.get(A) : A;
484
+ return typeof I == "number" && Number.isInteger(I) && I >= 0 && I < d ? I : void 0;
485
+ }, w = [], H = [];
486
+ for (let A = 0; A < h.length; A += 1) {
487
+ const I = h[A], V = { index: A, data: h, target: [] }, X = B(R(P, I, V)), U = B(R(L, I, V));
488
+ X === void 0 || U === void 0 || (w.push(I), H.push(X, U));
641
489
  }
642
- const F = s.length - S.length;
643
- if (F > 0) {
644
- const P = g ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
490
+ const Y = h.length - w.length;
491
+ if (Y > 0) {
492
+ const A = k ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
645
493
  console.warn(
646
- `@cosmos.gl/deck-layers: dropped ${F} of ${s.length} links whose source or target is not a point — check ${P}`
494
+ `@cosmos.gl/deck-layers: dropped ${Y} of ${h.length} links whose source or target is not a point — check ${A}`
647
495
  );
648
496
  }
649
- x = Float32Array.from(R), z = x, _ = S;
497
+ y = Float32Array.from(H), m = w, C = w.length;
650
498
  }
651
499
  } else
652
- _ = null, z = null, (d || this.state.loadedPairs !== j) && (x = j);
653
- p && n.setPointPositions(p), x && n.setLinks(x), (p || x) && n.applyData(), this.setState({
500
+ m = null, C = 0, (r || this.state.loadedPairs !== J) && (y = J);
501
+ c && (t.setPointPositions(c, t.config.rescalePositions === void 0 ? !0 : void 0), this.state.measuredBounds = void 0, this.state.measuredBoundsVersion = void 0, this.state.loadSerial = (this.state.loadSerial ?? 0) + 1), y && t.setLinks(y);
502
+ const { getPointColor: S, getPointSize: T, getLinkColor: _, getLinkWidth: M } = this.props;
503
+ (c || e.pointStyleChanged) && (v(S, u == null ? void 0 : u.getPointColor) ? t.setPointColors(Z(d, S, f, u == null ? void 0 : u.getPointColor)) : e.pointColorUnset && t.setPointColors(b), v(T, u == null ? void 0 : u.getPointSize) ? t.setPointSizes(q(d, T, f, u == null ? void 0 : u.getPointSize)) : e.pointSizeUnset && t.setPointSizes(b)), (y || e.linkStyleChanged) && (v(_, p == null ? void 0 : p.getLinkColor) ? t.setLinkColors(Z(C, _, m, p == null ? void 0 : p.getLinkColor)) : e.linkColorUnset && t.setLinkColors(b), v(M, p == null ? void 0 : p.getLinkWidth) ? t.setLinkWidths(q(C, M, m, p == null ? void 0 : p.getLinkWidth)) : e.linkWidthUnset && t.setLinkWidths(b)), t.render();
504
+ const E = k !== this.state.idToIndex;
505
+ if (this.setState({
654
506
  hasLoaded: !0,
655
- pointCount: h,
656
- pointsData: f,
657
- linksData: _,
658
- linkIndices: z,
659
- followedLinks: void 0,
660
- loadedPositions: k,
661
- loadedPairs: x ?? this.state.loadedPairs,
662
- idToIndex: g
663
- });
507
+ pointCount: d,
508
+ linkCount: C,
509
+ keptLinks: m,
510
+ loadedPositions: x,
511
+ loadedPairs: y ?? this.state.loadedPairs,
512
+ idToIndex: k
513
+ }), c || y || E)
514
+ try {
515
+ (G = (F = this.props).onGraphDataLoaded) == null || G.call(F, {
516
+ graph: t,
517
+ pointsLoaded: !!c,
518
+ linksLoaded: !!y,
519
+ pointIndexById: k,
520
+ links: Array.isArray(n) ? m : null
521
+ });
522
+ } catch (h) {
523
+ this.raiseError(h, "onGraphDataLoaded");
524
+ }
664
525
  }
665
526
  };
666
- w.layerName = "CosmosGraphLayer", w.defaultProps = dt;
667
- let G = w;
527
+ O.layerName = "CosmosGraphLayer", O.defaultProps = at;
528
+ let et = O;
668
529
  export {
669
- G as CosmosGraphLayer
530
+ et as CosmosGraphLayer,
531
+ rt as DECK_OWNED_CONFIG_KEYS
670
532
  };
671
533
  //# sourceMappingURL=index.js.map