@cosmos.gl/deck-layers 3.5.0-beta.2 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -26
- package/dist/cosmos-graph-layer.d.ts +121 -29
- package/dist/cosmos-links-layer-uniforms.d.ts +3 -1
- package/dist/cosmos-links-layer.d.ts +6 -1
- package/dist/cosmos-points-layer.d.ts +4 -1
- package/dist/index.d.ts +6 -9
- package/dist/index.js +299 -198
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/types.d.ts +0 -9
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Layer as
|
|
2
|
-
import { GraphSimulation as
|
|
3
|
-
import { Model as
|
|
4
|
-
const
|
|
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
5
|
depthWriteEnabled: !1,
|
|
6
6
|
depthCompare: "always",
|
|
7
7
|
blend: !0,
|
|
@@ -11,18 +11,18 @@ const A = {
|
|
|
11
11
|
blendAlphaOperation: "add",
|
|
12
12
|
blendAlphaSrcFactor: "one",
|
|
13
13
|
blendAlphaDstFactor: "one-minus-src-alpha"
|
|
14
|
-
},
|
|
14
|
+
}, tt = `layout(std140) uniform cosmosPointsUniforms {
|
|
15
15
|
float pointsTextureSize;
|
|
16
16
|
highp int sizeUnits;
|
|
17
17
|
} cosmosPoints;
|
|
18
|
-
`,
|
|
18
|
+
`, et = {
|
|
19
19
|
name: "cosmosPoints",
|
|
20
|
-
vs:
|
|
20
|
+
vs: tt,
|
|
21
21
|
uniformTypes: {
|
|
22
22
|
pointsTextureSize: "f32",
|
|
23
23
|
sizeUnits: "i32"
|
|
24
24
|
}
|
|
25
|
-
},
|
|
25
|
+
}, Z = [74, 92, 191, 230], it = (
|
|
26
26
|
/* glsl */
|
|
27
27
|
`#version 300 es
|
|
28
28
|
#define SHADER_NAME cosmos-points-layer-vertex-shader
|
|
@@ -85,7 +85,7 @@ void main(void) {
|
|
|
85
85
|
DECKGL_FILTER_COLOR(vColor, geometry);
|
|
86
86
|
}
|
|
87
87
|
`
|
|
88
|
-
),
|
|
88
|
+
), ot = (
|
|
89
89
|
/* glsl */
|
|
90
90
|
`#version 300 es
|
|
91
91
|
#define SHADER_NAME cosmos-points-layer-fragment-shader
|
|
@@ -111,14 +111,14 @@ void main(void) {
|
|
|
111
111
|
DECKGL_FILTER_COLOR(fragColor, geometry);
|
|
112
112
|
}
|
|
113
113
|
`
|
|
114
|
-
),
|
|
114
|
+
), nt = {
|
|
115
115
|
getPointSize: { type: "accessor", value: 4 },
|
|
116
|
-
getPointColor: { type: "accessor", value:
|
|
116
|
+
getPointColor: { type: "accessor", value: Z },
|
|
117
117
|
pointSizeUnits: "pixels",
|
|
118
|
-
parameters: { type: "object", value:
|
|
119
|
-
},
|
|
118
|
+
parameters: { type: "object", value: b, optional: !0, compare: 2 }
|
|
119
|
+
}, T = class T extends H {
|
|
120
120
|
getShaders() {
|
|
121
|
-
return super.getShaders({ vs:
|
|
121
|
+
return super.getShaders({ vs: it, fs: ot, modules: [B, K, et] });
|
|
122
122
|
}
|
|
123
123
|
initializeState() {
|
|
124
124
|
this.getAttributeManager().addInstanced({
|
|
@@ -133,30 +133,30 @@ void main(void) {
|
|
|
133
133
|
transition: !0,
|
|
134
134
|
type: "unorm8",
|
|
135
135
|
accessor: "getPointColor",
|
|
136
|
-
defaultValue: [...
|
|
136
|
+
defaultValue: [...Z]
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
-
updateState(
|
|
141
|
-
var
|
|
142
|
-
super.updateState(
|
|
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
143
|
}
|
|
144
144
|
draw() {
|
|
145
|
-
const
|
|
146
|
-
if (!
|
|
145
|
+
const t = this.props.graph.getPointPositionTexture(), { model: e } = this.state;
|
|
146
|
+
if (!t || !e || t.pointCount === 0) return;
|
|
147
147
|
const i = {
|
|
148
|
-
pointsTextureSize:
|
|
149
|
-
sizeUnits:
|
|
150
|
-
positionsTexture:
|
|
148
|
+
pointsTextureSize: t.textureSize,
|
|
149
|
+
sizeUnits: $[this.props.pointSizeUnits],
|
|
150
|
+
positionsTexture: t.texture
|
|
151
151
|
};
|
|
152
|
-
|
|
152
|
+
e.shaderInputs.setProps({ cosmosPoints: i }), e.draw(this.context.renderPass);
|
|
153
153
|
}
|
|
154
154
|
_getModel() {
|
|
155
|
-
return new
|
|
155
|
+
return new q(this.context.device, {
|
|
156
156
|
...this.getShaders(),
|
|
157
157
|
id: this.props.id,
|
|
158
158
|
bufferLayout: this.getAttributeManager().getBufferLayouts(),
|
|
159
|
-
geometry: new
|
|
159
|
+
geometry: new V({
|
|
160
160
|
topology: "triangle-strip",
|
|
161
161
|
attributes: {
|
|
162
162
|
positions: { size: 3, value: new Float32Array([-1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0]) }
|
|
@@ -166,20 +166,22 @@ void main(void) {
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
|
-
|
|
170
|
-
let
|
|
171
|
-
const
|
|
169
|
+
T.layerName = "CosmosPointsLayer", T.defaultProps = nt;
|
|
170
|
+
let D = T;
|
|
171
|
+
const st = `layout(std140) uniform cosmosLinksUniforms {
|
|
172
172
|
float pointsTextureSize;
|
|
173
173
|
highp int widthUnits;
|
|
174
|
+
float pointCount;
|
|
174
175
|
} cosmosLinks;
|
|
175
|
-
`,
|
|
176
|
+
`, at = {
|
|
176
177
|
name: "cosmosLinks",
|
|
177
|
-
vs:
|
|
178
|
+
vs: st,
|
|
178
179
|
uniformTypes: {
|
|
179
180
|
pointsTextureSize: "f32",
|
|
180
|
-
widthUnits: "i32"
|
|
181
|
+
widthUnits: "i32",
|
|
182
|
+
pointCount: "f32"
|
|
181
183
|
}
|
|
182
|
-
},
|
|
184
|
+
}, J = [94, 115, 194, 64], rt = (
|
|
183
185
|
/* glsl */
|
|
184
186
|
`#version 300 es
|
|
185
187
|
#define SHADER_NAME cosmos-links-layer-vertex-shader
|
|
@@ -205,6 +207,12 @@ vec2 getExtrusionOffset(vec2 lineClipspace, float offsetDirection, float width)
|
|
|
205
207
|
return dirScreenspace * offsetDirection * width / 2.0;
|
|
206
208
|
}
|
|
207
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
|
+
|
|
208
216
|
vec4 fetchPointPosition(float index, int textureSize) {
|
|
209
217
|
int pointIndex = int(index);
|
|
210
218
|
// Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates
|
|
@@ -212,13 +220,20 @@ vec4 fetchPointPosition(float index, int textureSize) {
|
|
|
212
220
|
}
|
|
213
221
|
|
|
214
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
|
+
|
|
215
230
|
int textureSize = int(cosmosLinks.pointsTextureSize);
|
|
216
|
-
vec4 sourcePosition = fetchPointPosition(instanceSourceIndices, textureSize);
|
|
217
|
-
vec4 targetPosition = fetchPointPosition(instanceTargetIndices, textureSize);
|
|
231
|
+
vec4 sourcePosition = namesNoPoint ? vec4(0.0) : fetchPointPosition(instanceSourceIndices, textureSize);
|
|
232
|
+
vec4 targetPosition = namesNoPoint ? vec4(0.0) : fetchPointPosition(instanceTargetIndices, textureSize);
|
|
218
233
|
|
|
219
234
|
// A removed (absent) endpoint's texel is NaN — see PointPositionTexture;
|
|
220
|
-
// collapse the quad so it clips away
|
|
221
|
-
if (isnan(sourcePosition.x) || isnan(targetPosition.x)) {
|
|
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)) {
|
|
222
237
|
gl_Position = vec4(0.0);
|
|
223
238
|
vColor = vec4(0.0);
|
|
224
239
|
uv = vec2(0.0);
|
|
@@ -254,7 +269,7 @@ void main(void) {
|
|
|
254
269
|
DECKGL_FILTER_COLOR(vColor, geometry);
|
|
255
270
|
}
|
|
256
271
|
`
|
|
257
|
-
),
|
|
272
|
+
), lt = (
|
|
258
273
|
/* glsl */
|
|
259
274
|
`#version 300 es
|
|
260
275
|
#define SHADER_NAME cosmos-links-layer-fragment-shader
|
|
@@ -273,16 +288,16 @@ void main(void) {
|
|
|
273
288
|
DECKGL_FILTER_COLOR(fragColor, geometry);
|
|
274
289
|
}
|
|
275
290
|
`
|
|
276
|
-
),
|
|
277
|
-
getLinkSource: { type: "accessor", value: (
|
|
278
|
-
getLinkTarget: { type: "accessor", value: (
|
|
279
|
-
getLinkColor: { type: "accessor", value:
|
|
291
|
+
), ct = {
|
|
292
|
+
getLinkSource: { type: "accessor", value: (u) => u.source },
|
|
293
|
+
getLinkTarget: { type: "accessor", value: (u) => u.target },
|
|
294
|
+
getLinkColor: { type: "accessor", value: J },
|
|
280
295
|
getLinkWidth: { type: "accessor", value: 1 },
|
|
281
296
|
linkWidthUnits: "pixels",
|
|
282
|
-
parameters: { type: "object", value:
|
|
283
|
-
},
|
|
297
|
+
parameters: { type: "object", value: b, optional: !0, compare: 2 }
|
|
298
|
+
}, A = class A extends H {
|
|
284
299
|
getShaders() {
|
|
285
|
-
return super.getShaders({ vs:
|
|
300
|
+
return super.getShaders({ vs: rt, fs: lt, modules: [B, K, at] });
|
|
286
301
|
}
|
|
287
302
|
initializeState() {
|
|
288
303
|
this.getAttributeManager().addInstanced({
|
|
@@ -299,7 +314,7 @@ void main(void) {
|
|
|
299
314
|
transition: !0,
|
|
300
315
|
type: "unorm8",
|
|
301
316
|
accessor: "getLinkColor",
|
|
302
|
-
defaultValue: [...
|
|
317
|
+
defaultValue: [...J]
|
|
303
318
|
},
|
|
304
319
|
instanceWidths: {
|
|
305
320
|
size: 1,
|
|
@@ -309,26 +324,27 @@ void main(void) {
|
|
|
309
324
|
}
|
|
310
325
|
});
|
|
311
326
|
}
|
|
312
|
-
updateState(
|
|
313
|
-
var
|
|
314
|
-
super.updateState(
|
|
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());
|
|
315
330
|
}
|
|
316
331
|
draw() {
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
332
|
+
const t = this.props.graph.getPointPositionTexture(), { model: e } = this.state;
|
|
333
|
+
if (!t || !e || t.pointCount === 0) return;
|
|
319
334
|
const i = {
|
|
320
|
-
pointsTextureSize:
|
|
321
|
-
widthUnits:
|
|
322
|
-
|
|
335
|
+
pointsTextureSize: t.textureSize,
|
|
336
|
+
widthUnits: $[this.props.linkWidthUnits],
|
|
337
|
+
pointCount: t.pointCount,
|
|
338
|
+
positionsTexture: t.texture
|
|
323
339
|
};
|
|
324
|
-
|
|
340
|
+
e.shaderInputs.setProps({ cosmosLinks: i }), e.draw(this.context.renderPass);
|
|
325
341
|
}
|
|
326
342
|
_getModel() {
|
|
327
|
-
return new
|
|
343
|
+
return new q(this.context.device, {
|
|
328
344
|
...this.getShaders(),
|
|
329
345
|
id: this.props.id,
|
|
330
346
|
bufferLayout: this.getAttributeManager().getBufferLayouts(),
|
|
331
|
-
geometry: new
|
|
347
|
+
geometry: new V({
|
|
332
348
|
topology: "triangle-strip",
|
|
333
349
|
attributes: {
|
|
334
350
|
positions: { size: 3, value: new Float32Array([0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 0]) }
|
|
@@ -338,17 +354,18 @@ void main(void) {
|
|
|
338
354
|
});
|
|
339
355
|
}
|
|
340
356
|
};
|
|
341
|
-
|
|
342
|
-
let
|
|
343
|
-
const
|
|
357
|
+
A.layerName = "CosmosLinksLayer", A.defaultProps = ct;
|
|
358
|
+
let E = A;
|
|
359
|
+
const dt = {
|
|
360
|
+
points: { type: "object", value: null, optional: !0 },
|
|
344
361
|
links: null,
|
|
345
362
|
getPointId: { type: "accessor", value: null },
|
|
346
363
|
getPointPosition: { type: "accessor", value: null },
|
|
347
364
|
getPointSize: { type: "accessor", value: 4 },
|
|
348
365
|
getPointColor: { type: "accessor", value: [74, 92, 191, 230] },
|
|
349
366
|
pointSizeUnits: "pixels",
|
|
350
|
-
getLinkSource: { type: "accessor", value: (
|
|
351
|
-
getLinkTarget: { type: "accessor", value: (
|
|
367
|
+
getLinkSource: { type: "accessor", value: (u) => u.source },
|
|
368
|
+
getLinkTarget: { type: "accessor", value: (u) => u.target },
|
|
352
369
|
getLinkColor: { type: "accessor", value: [94, 115, 194, 64] },
|
|
353
370
|
getLinkWidth: { type: "accessor", value: 1 },
|
|
354
371
|
linkWidthUnits: "pixels",
|
|
@@ -358,27 +375,36 @@ const oe = {
|
|
|
358
375
|
onPointDragStart: { type: "function", value: null, optional: !0 },
|
|
359
376
|
onPointDrag: { type: "function", value: null, optional: !0 },
|
|
360
377
|
onPointDragEnd: { type: "function", value: null, optional: !0 },
|
|
378
|
+
simulation: { type: "object", value: null, optional: !0 },
|
|
361
379
|
simulationConfig: { type: "object", value: {}, compare: 2 },
|
|
362
380
|
onSimulationCreated: { type: "function", value: null, optional: !0 },
|
|
363
381
|
// getSubLayerProps forwards `parameters` into every sublayer, so the
|
|
364
382
|
// composite must carry the same pipeline-state default the primitives do
|
|
365
|
-
parameters: { type: "object", value:
|
|
366
|
-
},
|
|
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 }
|
|
391
|
+
}
|
|
392
|
+
}), ut = Symbol("seeded"), j = new Float32Array(0), w = class w extends Q {
|
|
367
393
|
get isLoaded() {
|
|
368
|
-
var
|
|
369
|
-
return super.isLoaded && !!((
|
|
394
|
+
var t;
|
|
395
|
+
return super.isLoaded && !!((t = this.state) != null && t.isReady);
|
|
370
396
|
}
|
|
371
397
|
initializeState() {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (e.type !== "webgl")
|
|
398
|
+
const { device: t, timeline: e } = this.context;
|
|
399
|
+
if (t.type !== "webgl")
|
|
375
400
|
throw new Error(
|
|
376
|
-
`@cosmos.gl/deck-layers requires a WebGL 2 device — the cosmos.gl simulation is WebGL-only, got '${
|
|
401
|
+
`@cosmos.gl/deck-layers requires a WebGL 2 device — the cosmos.gl simulation is WebGL-only, got '${t.type}'`
|
|
377
402
|
);
|
|
378
|
-
const i = new B(this.props.simulationConfig, Promise.resolve(e));
|
|
379
403
|
this.state = {
|
|
380
|
-
|
|
404
|
+
providedSimulation: null,
|
|
381
405
|
isReady: !1,
|
|
406
|
+
isIngestPending: !1,
|
|
407
|
+
hasLoaded: !1,
|
|
382
408
|
pointCount: 0,
|
|
383
409
|
pointsData: { length: 0 },
|
|
384
410
|
linksData: null,
|
|
@@ -386,185 +412,260 @@ const oe = {
|
|
|
386
412
|
draggedPointIndex: null,
|
|
387
413
|
// Step the simulation exactly once per animation frame, independent of
|
|
388
414
|
// draw passes (draw runs per viewport and again while picking)
|
|
389
|
-
animationHandle:
|
|
390
|
-
}, (
|
|
391
|
-
var a;
|
|
392
|
-
if (((a = this.state) == null ? void 0 : a.simulation) !== i) return;
|
|
393
|
-
(this.getCurrentLayer() ?? this).setState({ isReady: !0 });
|
|
394
|
-
}).catch((o) => {
|
|
395
|
-
console.error("@cosmos.gl/deck-layers: simulation failed to initialize", o);
|
|
396
|
-
});
|
|
415
|
+
animationHandle: e.attachAnimation({ setTime: (i) => this._onTimelineTick(i) })
|
|
416
|
+
}, this._attachSimulation(this.props.simulation ?? null);
|
|
397
417
|
}
|
|
398
|
-
updateState(
|
|
399
|
-
super.updateState(
|
|
400
|
-
const { props:
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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;
|
|
423
|
+
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)));
|
|
405
427
|
}
|
|
406
428
|
renderLayers() {
|
|
407
|
-
const { simulation:
|
|
408
|
-
if (!
|
|
409
|
-
const { getPointSize:
|
|
410
|
-
return
|
|
411
|
-
new
|
|
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(
|
|
412
434
|
this.getSubLayerProps({
|
|
413
435
|
id: "links",
|
|
414
436
|
updateTriggers: {
|
|
415
|
-
getLinkSource:
|
|
416
|
-
getLinkTarget:
|
|
417
|
-
getLinkColor:
|
|
418
|
-
getLinkWidth:
|
|
437
|
+
getLinkSource: f.getLinkSource,
|
|
438
|
+
getLinkTarget: f.getLinkTarget,
|
|
439
|
+
getLinkColor: f.getLinkColor,
|
|
440
|
+
getLinkWidth: f.getLinkWidth
|
|
419
441
|
}
|
|
420
442
|
}),
|
|
421
443
|
{
|
|
422
|
-
data:
|
|
423
|
-
graph:
|
|
424
|
-
getLinkColor:
|
|
425
|
-
getLinkWidth:
|
|
426
|
-
linkWidthUnits:
|
|
444
|
+
data: a,
|
|
445
|
+
graph: t,
|
|
446
|
+
getLinkColor: C,
|
|
447
|
+
getLinkWidth: y,
|
|
448
|
+
linkWidthUnits: h,
|
|
427
449
|
// getSubLayerProps does not forward `transitions`
|
|
428
450
|
transitions: this.props.transitions
|
|
429
451
|
},
|
|
430
|
-
Array.isArray(
|
|
452
|
+
Array.isArray(a) && o ? {
|
|
431
453
|
// Array links read the endpoints resolved at ingest, so the
|
|
432
454
|
// rendered links are exactly the simulated ones
|
|
433
|
-
getLinkSource: (
|
|
434
|
-
getLinkTarget: (
|
|
455
|
+
getLinkSource: (k, { index: g }) => o[g * 2],
|
|
456
|
+
getLinkTarget: (k, { index: g }) => o[g * 2 + 1]
|
|
435
457
|
} : {}
|
|
436
458
|
)
|
|
437
|
-
),
|
|
438
|
-
new
|
|
459
|
+
), p.push(
|
|
460
|
+
new D(
|
|
439
461
|
this.getSubLayerProps({
|
|
440
462
|
id: "points",
|
|
441
463
|
updateTriggers: {
|
|
442
|
-
getPointSize:
|
|
443
|
-
getPointColor:
|
|
464
|
+
getPointSize: f.getPointSize,
|
|
465
|
+
getPointColor: f.getPointColor
|
|
444
466
|
}
|
|
445
467
|
}),
|
|
446
468
|
{
|
|
447
|
-
data:
|
|
448
|
-
graph:
|
|
449
|
-
getPointSize:
|
|
469
|
+
data: n,
|
|
470
|
+
graph: t,
|
|
471
|
+
getPointSize: r,
|
|
450
472
|
getPointColor: l,
|
|
451
|
-
pointSizeUnits:
|
|
473
|
+
pointSizeUnits: d,
|
|
452
474
|
// getSubLayerProps does not forward `transitions`
|
|
453
475
|
transitions: this.props.transitions
|
|
454
476
|
}
|
|
455
477
|
)
|
|
456
|
-
),
|
|
478
|
+
), p;
|
|
457
479
|
}
|
|
458
|
-
onDragStart(
|
|
459
|
-
var
|
|
460
|
-
const { simulation: i } = this.state, { enablePointDrag:
|
|
461
|
-
return !
|
|
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);
|
|
462
484
|
}
|
|
463
|
-
onDrag(
|
|
464
|
-
var
|
|
465
|
-
const { simulation: i, draggedPointIndex:
|
|
466
|
-
if (!i ||
|
|
467
|
-
const [
|
|
468
|
-
return i.setPointPosition(
|
|
485
|
+
onDrag(t, e) {
|
|
486
|
+
var r, l, d;
|
|
487
|
+
const { simulation: i, draggedPointIndex: n } = this.state;
|
|
488
|
+
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;
|
|
469
491
|
}
|
|
470
|
-
onDragEnd(
|
|
471
|
-
var
|
|
472
|
-
const { simulation: i, draggedPointIndex:
|
|
473
|
-
return !i ||
|
|
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);
|
|
474
496
|
}
|
|
475
|
-
getPickingInfo(
|
|
476
|
-
const
|
|
477
|
-
return
|
|
497
|
+
getPickingInfo(t) {
|
|
498
|
+
const e = t.info;
|
|
499
|
+
return t.sourceLayer && (e.elementType = t.sourceLayer.id.endsWith("-links") ? "link" : "point"), e;
|
|
478
500
|
}
|
|
479
501
|
/** The whole simulation space; lets deck's viewport helpers frame the graph. */
|
|
480
502
|
getBounds() {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return [[0, 0, 0], [e, e, 0]];
|
|
503
|
+
const t = this._spaceSize();
|
|
504
|
+
return [[0, 0, 0], [t, t, 0]];
|
|
484
505
|
}
|
|
485
|
-
finalizeState(
|
|
486
|
-
var
|
|
487
|
-
((
|
|
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);
|
|
488
509
|
}
|
|
489
510
|
/**
|
|
490
511
|
* Points and links have separate index spaces, so the same picking color
|
|
491
512
|
* exists in both sublayers: highlight only the sublayer that was hovered
|
|
492
513
|
* and clear the other, or hovering point N would also tint link N.
|
|
493
514
|
*/
|
|
494
|
-
_updateAutoHighlight(
|
|
495
|
-
var
|
|
515
|
+
_updateAutoHighlight(t) {
|
|
516
|
+
var e;
|
|
496
517
|
for (const i of this.getSubLayers())
|
|
497
|
-
i.id === ((
|
|
518
|
+
i.id === ((e = t.sourceLayer) == null ? void 0 : e.id) ? i.updateAutoHighlight(t) : i.updateAutoHighlight({ ...t, picked: !1 });
|
|
498
519
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
e
|
|
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));
|
|
524
|
+
this.setState({
|
|
525
|
+
simulation: i,
|
|
526
|
+
providedSimulation: t,
|
|
527
|
+
isReady: !1,
|
|
528
|
+
hasLoaded: !1,
|
|
529
|
+
loadedPositions: void 0,
|
|
530
|
+
loadedPairs: null,
|
|
531
|
+
idToIndex: null,
|
|
532
|
+
draggedPointIndex: null
|
|
533
|
+
}), t || (a = (n = this.props).onSimulationCreated) == null || a.call(n, i), i.ready.then(() => {
|
|
534
|
+
var r;
|
|
535
|
+
if (((r = this.state) == null ? void 0 : r.simulation) !== i) return;
|
|
536
|
+
const o = this.getCurrentLayer() ?? this;
|
|
537
|
+
if (i.device !== o.context.device) {
|
|
538
|
+
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"
|
|
540
|
+
);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
o.state.isIngestPending ? (o.state.isIngestPending = !1, o._updateSimulationData(!0, !0, !0)) : o.props.points || o._syncFromSimulation(!0), o.setState({ isReady: !0 });
|
|
544
|
+
}).catch((o) => {
|
|
545
|
+
console.error("@cosmos.gl/deck-layers: simulation failed to initialize", o);
|
|
546
|
+
});
|
|
503
547
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const t = this.
|
|
507
|
-
|
|
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;
|
|
508
552
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
553
|
+
/** The simulation's space size — authoritative for a provided simulation too. */
|
|
554
|
+
_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;
|
|
557
|
+
}
|
|
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());
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
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.
|
|
568
|
+
*/
|
|
569
|
+
_syncFromSimulation(t = !1) {
|
|
570
|
+
const { simulation: e } = this.state;
|
|
512
571
|
if (!e) return;
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
+
});
|
|
580
|
+
}
|
|
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]];
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
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.
|
|
592
|
+
*/
|
|
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);
|
|
607
|
+
}
|
|
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);
|
|
613
|
+
}
|
|
523
614
|
} else {
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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;
|
|
621
|
+
else {
|
|
622
|
+
p = new Float32Array(h * 2);
|
|
623
|
+
for (let m = 0; m < p.length; m += 1) p[m] = y();
|
|
624
|
+
}
|
|
625
|
+
k = c;
|
|
530
626
|
}
|
|
531
|
-
P = r.attributes ? { length: l, attributes: r.attributes } : { length: l };
|
|
532
627
|
}
|
|
533
|
-
let
|
|
534
|
-
if (
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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));
|
|
540
641
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
w === void 0 || R === void 0 || (m.push(h), b.push(w, R));
|
|
550
|
-
}
|
|
551
|
-
const D = r.length - m.length;
|
|
552
|
-
if (D > 0) {
|
|
553
|
-
const g = f ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
|
|
554
|
-
console.warn(
|
|
555
|
-
`@cosmos.gl/deck-layers: dropped ${D} of ${r.length} links whose source or target is not a point — check ${g}`
|
|
556
|
-
);
|
|
642
|
+
const F = s.length - S.length;
|
|
643
|
+
if (F > 0) {
|
|
644
|
+
const P = g ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
|
|
645
|
+
console.warn(
|
|
646
|
+
`@cosmos.gl/deck-layers: dropped ${F} of ${s.length} links whose source or target is not a point — check ${P}`
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
x = Float32Array.from(R), z = x, _ = S;
|
|
557
650
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
651
|
+
} 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({
|
|
654
|
+
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
|
+
});
|
|
561
664
|
}
|
|
562
665
|
};
|
|
563
|
-
|
|
564
|
-
let
|
|
666
|
+
w.layerName = "CosmosGraphLayer", w.defaultProps = dt;
|
|
667
|
+
let G = w;
|
|
565
668
|
export {
|
|
566
|
-
|
|
567
|
-
I as CosmosLinksLayer,
|
|
568
|
-
_ as CosmosPointsLayer
|
|
669
|
+
G as CosmosGraphLayer
|
|
569
670
|
};
|
|
570
671
|
//# sourceMappingURL=index.js.map
|