@cosmos.gl/deck-layers 3.5.0-beta.2 → 3.5.1
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 +148 -61
- package/dist/cosmos-graph-layer.d.ts +276 -77
- package/dist/index.d.ts +6 -9
- package/dist/index.js +351 -513
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/blend-parameters.d.ts +0 -23
- package/dist/cosmos-links-layer-uniforms.d.ts +0 -18
- package/dist/cosmos-links-layer.d.ts +0 -63
- package/dist/cosmos-points-layer-uniforms.d.ts +0 -18
- package/dist/cosmos-points-layer.d.ts +0 -49
- package/dist/types.d.ts +0 -9
package/dist/index.js
CHANGED
|
@@ -1,570 +1,408 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
), J = (
|
|
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
|
-
), Q = {
|
|
115
|
-
getPointSize: { type: "accessor", value: 4 },
|
|
116
|
-
getPointColor: { type: "accessor", value: H },
|
|
117
|
-
pointSizeUnits: "pixels",
|
|
118
|
-
parameters: { type: "object", value: A, optional: !0, compare: 2 }
|
|
119
|
-
}, L = class L extends U {
|
|
120
|
-
getShaders() {
|
|
121
|
-
return super.getShaders({ vs: Z, fs: J, modules: [W, N, V] });
|
|
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: [...H]
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
updateState(e) {
|
|
141
|
-
var t;
|
|
142
|
-
super.updateState(e), e.changeFlags.extensionsChanged && ((t = this.state.model) == null || t.destroy(), this.state.model = this._getModel(), this.getAttributeManager().invalidateAll());
|
|
143
|
-
}
|
|
144
|
-
draw() {
|
|
145
|
-
const e = this.props.graph.getPointPositionTexture(), { model: t } = this.state;
|
|
146
|
-
if (!e || !t || e.pointCount === 0) return;
|
|
147
|
-
const i = {
|
|
148
|
-
pointsTextureSize: e.textureSize,
|
|
149
|
-
sizeUnits: M[this.props.pointSizeUnits],
|
|
150
|
-
positionsTexture: e.texture
|
|
151
|
-
};
|
|
152
|
-
t.shaderInputs.setProps({ cosmosPoints: i }), t.draw(this.context.renderPass);
|
|
153
|
-
}
|
|
154
|
-
_getModel() {
|
|
155
|
-
return new j(this.context.device, {
|
|
156
|
-
...this.getShaders(),
|
|
157
|
-
id: this.props.id,
|
|
158
|
-
bufferLayout: this.getAttributeManager().getBufferLayouts(),
|
|
159
|
-
geometry: new G({
|
|
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
|
-
L.layerName = "CosmosPointsLayer", L.defaultProps = Q;
|
|
170
|
-
let _ = L;
|
|
171
|
-
const X = `layout(std140) uniform cosmosLinksUniforms {
|
|
172
|
-
float pointsTextureSize;
|
|
173
|
-
highp int widthUnits;
|
|
174
|
-
} cosmosLinks;
|
|
175
|
-
`, Y = {
|
|
176
|
-
name: "cosmosLinks",
|
|
177
|
-
vs: X,
|
|
178
|
-
uniformTypes: {
|
|
179
|
-
pointsTextureSize: "f32",
|
|
180
|
-
widthUnits: "i32"
|
|
181
|
-
}
|
|
182
|
-
}, K = [94, 115, 194, 64], ee = (
|
|
183
|
-
/* glsl */
|
|
184
|
-
`#version 300 es
|
|
185
|
-
#define SHADER_NAME cosmos-links-layer-vertex-shader
|
|
186
|
-
|
|
187
|
-
in vec3 positions;
|
|
188
|
-
|
|
189
|
-
in float instanceSourceIndices;
|
|
190
|
-
in float instanceTargetIndices;
|
|
191
|
-
in vec4 instanceColors;
|
|
192
|
-
in float instanceWidths;
|
|
193
|
-
in vec3 instancePickingColors;
|
|
194
|
-
|
|
195
|
-
uniform sampler2D positionsTexture;
|
|
196
|
-
|
|
197
|
-
out vec4 vColor;
|
|
198
|
-
out vec2 uv;
|
|
199
|
-
|
|
200
|
-
// Offset the vertex by half the link width, perpendicular to the link, in
|
|
201
|
-
// screen space. offsetDirection is -1 (left) or 1 (right).
|
|
202
|
-
vec2 getExtrusionOffset(vec2 lineClipspace, float offsetDirection, float width) {
|
|
203
|
-
vec2 dirScreenspace = normalize(lineClipspace * project.viewportSize);
|
|
204
|
-
dirScreenspace = vec2(-dirScreenspace.y, dirScreenspace.x);
|
|
205
|
-
return dirScreenspace * offsetDirection * width / 2.0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
vec4 fetchPointPosition(float index, int textureSize) {
|
|
209
|
-
int pointIndex = int(index);
|
|
210
|
-
// Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates
|
|
211
|
-
return texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
void main(void) {
|
|
215
|
-
int textureSize = int(cosmosLinks.pointsTextureSize);
|
|
216
|
-
vec4 sourcePosition = fetchPointPosition(instanceSourceIndices, textureSize);
|
|
217
|
-
vec4 targetPosition = fetchPointPosition(instanceTargetIndices, textureSize);
|
|
218
|
-
|
|
219
|
-
// 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)) {
|
|
222
|
-
gl_Position = vec4(0.0);
|
|
223
|
-
vColor = vec4(0.0);
|
|
224
|
-
uv = vec2(0.0);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
vec3 sourceWorld = vec3(sourcePosition.xy, 0.0);
|
|
229
|
-
vec3 targetWorld = vec3(targetPosition.xy, 0.0);
|
|
230
|
-
geometry.worldPosition = sourceWorld;
|
|
231
|
-
geometry.worldPositionAlt = targetWorld;
|
|
232
|
-
|
|
233
|
-
vec4 sourceCommonspace;
|
|
234
|
-
vec4 targetCommonspace;
|
|
235
|
-
vec4 source = project_position_to_clipspace(sourceWorld, vec3(0.0), vec3(0.0), sourceCommonspace);
|
|
236
|
-
vec4 target = project_position_to_clipspace(targetWorld, vec3(0.0), vec3(0.0), targetCommonspace);
|
|
237
|
-
|
|
238
|
-
// positions.x selects the endpoint, positions.y the extrusion side
|
|
239
|
-
float segmentIndex = positions.x;
|
|
240
|
-
vec4 p = mix(source, target, segmentIndex);
|
|
241
|
-
geometry.position = mix(sourceCommonspace, targetCommonspace, segmentIndex);
|
|
242
|
-
uv = positions.xy;
|
|
243
|
-
geometry.uv = uv;
|
|
244
|
-
geometry.pickingColor = instancePickingColors;
|
|
245
|
-
|
|
246
|
-
float widthPixels = project_size_to_pixel(instanceWidths, cosmosLinks.widthUnits);
|
|
247
|
-
|
|
248
|
-
vec3 offset = vec3(getExtrusionOffset(target.xy - source.xy, positions.y, widthPixels), 0.0);
|
|
249
|
-
DECKGL_FILTER_SIZE(offset, geometry);
|
|
250
|
-
DECKGL_FILTER_GL_POSITION(p, geometry);
|
|
251
|
-
gl_Position = p + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0);
|
|
252
|
-
|
|
253
|
-
vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);
|
|
254
|
-
DECKGL_FILTER_COLOR(vColor, geometry);
|
|
255
|
-
}
|
|
256
|
-
`
|
|
257
|
-
), te = (
|
|
258
|
-
/* glsl */
|
|
259
|
-
`#version 300 es
|
|
260
|
-
#define SHADER_NAME cosmos-links-layer-fragment-shader
|
|
261
|
-
|
|
262
|
-
precision highp float;
|
|
263
|
-
|
|
264
|
-
in vec4 vColor;
|
|
265
|
-
in vec2 uv;
|
|
266
|
-
|
|
267
|
-
out vec4 fragColor;
|
|
268
|
-
|
|
269
|
-
void main(void) {
|
|
270
|
-
geometry.uv = uv;
|
|
271
|
-
|
|
272
|
-
fragColor = vColor;
|
|
273
|
-
DECKGL_FILTER_COLOR(fragColor, geometry);
|
|
274
|
-
}
|
|
275
|
-
`
|
|
276
|
-
), ie = {
|
|
277
|
-
getLinkSource: { type: "accessor", value: (d) => d.source },
|
|
278
|
-
getLinkTarget: { type: "accessor", value: (d) => d.target },
|
|
279
|
-
getLinkColor: { type: "accessor", value: K },
|
|
280
|
-
getLinkWidth: { type: "accessor", value: 1 },
|
|
281
|
-
linkWidthUnits: "pixels",
|
|
282
|
-
parameters: { type: "object", value: A, optional: !0, compare: 2 }
|
|
283
|
-
}, z = class z extends U {
|
|
284
|
-
getShaders() {
|
|
285
|
-
return super.getShaders({ vs: ee, fs: te, modules: [W, N, Y] });
|
|
286
|
-
}
|
|
287
|
-
initializeState() {
|
|
288
|
-
this.getAttributeManager().addInstanced({
|
|
289
|
-
instanceSourceIndices: {
|
|
290
|
-
size: 1,
|
|
291
|
-
accessor: "getLinkSource"
|
|
292
|
-
},
|
|
293
|
-
instanceTargetIndices: {
|
|
294
|
-
size: 1,
|
|
295
|
-
accessor: "getLinkTarget"
|
|
296
|
-
},
|
|
297
|
-
instanceColors: {
|
|
298
|
-
size: 4,
|
|
299
|
-
transition: !0,
|
|
300
|
-
type: "unorm8",
|
|
301
|
-
accessor: "getLinkColor",
|
|
302
|
-
defaultValue: [...K]
|
|
303
|
-
},
|
|
304
|
-
instanceWidths: {
|
|
305
|
-
size: 1,
|
|
306
|
-
transition: !0,
|
|
307
|
-
accessor: "getLinkWidth",
|
|
308
|
-
defaultValue: 1
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
updateState(e) {
|
|
313
|
-
var t;
|
|
314
|
-
super.updateState(e), e.changeFlags.extensionsChanged && ((t = this.state.model) == null || t.destroy(), this.state.model = this._getModel(), this.getAttributeManager().invalidateAll());
|
|
315
|
-
}
|
|
316
|
-
draw() {
|
|
317
|
-
const e = this.props.graph.getPointPositionTexture(), { model: t } = this.state;
|
|
318
|
-
if (!e || !t || e.pointCount === 0) return;
|
|
319
|
-
const i = {
|
|
320
|
-
pointsTextureSize: e.textureSize,
|
|
321
|
-
widthUnits: M[this.props.linkWidthUnits],
|
|
322
|
-
positionsTexture: e.texture
|
|
323
|
-
};
|
|
324
|
-
t.shaderInputs.setProps({ cosmosLinks: i }), t.draw(this.context.renderPass);
|
|
325
|
-
}
|
|
326
|
-
_getModel() {
|
|
327
|
-
return new j(this.context.device, {
|
|
328
|
-
...this.getShaders(),
|
|
329
|
-
id: this.props.id,
|
|
330
|
-
bufferLayout: this.getAttributeManager().getBufferLayouts(),
|
|
331
|
-
geometry: new G({
|
|
332
|
-
topology: "triangle-strip",
|
|
333
|
-
attributes: {
|
|
334
|
-
positions: { size: 3, value: new Float32Array([0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 0]) }
|
|
335
|
-
}
|
|
336
|
-
}),
|
|
337
|
-
isInstanced: !0
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
z.layerName = "CosmosLinksLayer", z.defaultProps = ie;
|
|
342
|
-
let I = z;
|
|
343
|
-
const oe = {
|
|
1
|
+
import { COORDINATE_SYSTEM as Q, Layer as tt } from "@deck.gl/core";
|
|
2
|
+
import { Graph as V } from "@cosmos.gl/graph";
|
|
3
|
+
const et = [
|
|
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
|
+
], W = (a) => (e) => e == null || typeof e == "function" || (a === "number" ? typeof e == "number" : Array.isArray(e) || ArrayBuffer.isView(e)), it = {
|
|
43
|
+
points: { type: "object", value: null, optional: !0 },
|
|
344
44
|
links: null,
|
|
345
45
|
getPointId: { type: "accessor", value: null },
|
|
346
46
|
getPointPosition: { type: "accessor", value: null },
|
|
347
|
-
getPointSize: { type: "accessor", value:
|
|
348
|
-
getPointColor: { type: "accessor", value:
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
getLinkWidth: { type: "accessor", value: 1 },
|
|
354
|
-
linkWidthUnits: "pixels",
|
|
47
|
+
getPointSize: { type: "accessor", value: null, validate: W("number") },
|
|
48
|
+
getPointColor: { type: "accessor", value: null, validate: W("color") },
|
|
49
|
+
getLinkSource: { type: "accessor", value: (a) => a.source },
|
|
50
|
+
getLinkTarget: { type: "accessor", value: (a) => a.target },
|
|
51
|
+
getLinkColor: { type: "accessor", value: null, validate: W("color") },
|
|
52
|
+
getLinkWidth: { type: "accessor", value: null, validate: W("number") },
|
|
355
53
|
enablePointDrag: !1,
|
|
356
54
|
dragReheatAlpha: 0.1,
|
|
357
55
|
unpinOnDragEnd: !0,
|
|
358
56
|
onPointDragStart: { type: "function", value: null, optional: !0 },
|
|
359
57
|
onPointDrag: { type: "function", value: null, optional: !0 },
|
|
360
58
|
onPointDragEnd: { type: "function", value: null, optional: !0 },
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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: Q.CARTESIAN
|
|
65
|
+
}, T = (a, e, t) => typeof a == "function" ? a(e, t) : a, M = (a, e) => a !== e && !(typeof a == "function" && typeof e == "function"), nt = (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
|
+
}, Y = (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 = T(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
|
+
}, Z = (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] = T(e, t == null ? void 0 : t[o], { index: o, data: s, target: [] });
|
|
92
|
+
return n;
|
|
93
|
+
}, X = /* @__PURE__ */ new WeakMap(), ot = Symbol("seeded"), $ = new Float32Array(0), E = new Float32Array(0), m = (a, e) => a != null || e != null, K = (a) => a && !Array.isArray(a) ? a.attributes : void 0, j = (a) => a && !Array.isArray(a) && !(a instanceof Float32Array) ? a.attributes : void 0, F = class F extends tt {
|
|
367
94
|
get isLoaded() {
|
|
368
95
|
var e;
|
|
369
96
|
return super.isLoaded && !!((e = this.state) != null && e.isReady);
|
|
370
97
|
}
|
|
371
98
|
initializeState() {
|
|
372
|
-
var s, n;
|
|
373
99
|
const { device: e, timeline: t } = this.context;
|
|
374
100
|
if (e.type !== "webgl")
|
|
375
101
|
throw new Error(
|
|
376
|
-
`@cosmos.gl/deck-layers requires a WebGL 2 device —
|
|
102
|
+
`@cosmos.gl/deck-layers requires a WebGL 2 device — cosmos.gl is WebGL-only, got '${e.type}'`
|
|
377
103
|
);
|
|
378
|
-
const i = new B(this.props.simulationConfig, Promise.resolve(e));
|
|
379
104
|
this.state = {
|
|
380
|
-
|
|
105
|
+
providedGraph: null,
|
|
381
106
|
isReady: !1,
|
|
107
|
+
isIngestPending: !1,
|
|
108
|
+
hasLoaded: !1,
|
|
382
109
|
pointCount: 0,
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
linkIndices: null,
|
|
110
|
+
linkCount: 0,
|
|
111
|
+
keptLinks: null,
|
|
386
112
|
draggedPointIndex: null,
|
|
113
|
+
holdsHover: !1,
|
|
387
114
|
// Step the simulation exactly once per animation frame, independent of
|
|
388
|
-
// draw passes (draw runs per viewport
|
|
389
|
-
animationHandle: t.attachAnimation({ setTime: () => this._onTimelineTick() })
|
|
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
|
-
});
|
|
115
|
+
// draw passes (draw runs per viewport)
|
|
116
|
+
animationHandle: t.attachAnimation({ setTime: (i) => this._onTimelineTick(i) })
|
|
117
|
+
}, this._attachGraph(this.props.graph ?? null);
|
|
397
118
|
}
|
|
398
119
|
updateState(e) {
|
|
399
120
|
super.updateState(e);
|
|
400
|
-
const { props: t, oldProps: i, changeFlags:
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
121
|
+
const { props: t, oldProps: i, changeFlags: n } = e, s = t.graph ?? null, o = s !== this.state.providedGraph;
|
|
122
|
+
o && (this._releaseGraph(), this._attachGraph(s));
|
|
123
|
+
const r = this.state.graph;
|
|
124
|
+
if (!r) return;
|
|
125
|
+
!s && !o && !nt(t.config, i.config) && r.setConfig(this._graphConfig());
|
|
126
|
+
const p = typeof n.updateTriggersChanged == "object" ? n.updateTriggersChanged : void 0, h = (z) => !!(p != null && p.all || p != null && p[z]), y = o || t.points !== i.points || h("getPointPosition"), A = h("getPointId"), d = o || t.links !== i.links || h("getLinkSource") || h("getLinkTarget") || A, u = y || h("getPointColor") || h("getPointSize") || M(t.getPointColor, i.getPointColor) || M(t.getPointSize, i.getPointSize), I = d || h("getLinkColor") || h("getLinkWidth") || M(t.getLinkColor, i.getLinkColor) || M(t.getLinkWidth, i.getLinkWidth);
|
|
127
|
+
if (!y && !d && !u && !I) return;
|
|
128
|
+
const k = !!i.points && !o, g = K(i.points), P = K(t.points), C = j(i.links), c = j(t.links), S = (z, _) => k && z && !_, R = {
|
|
129
|
+
pointColorUnset: S(m(i.getPointColor, g == null ? void 0 : g.getPointColor), m(t.getPointColor, P == null ? void 0 : P.getPointColor)),
|
|
130
|
+
pointSizeUnset: S(m(i.getPointSize, g == null ? void 0 : g.getPointSize), m(t.getPointSize, P == null ? void 0 : P.getPointSize)),
|
|
131
|
+
linkColorUnset: S(m(i.getLinkColor, C == null ? void 0 : C.getLinkColor), m(t.getLinkColor, c == null ? void 0 : c.getLinkColor)),
|
|
132
|
+
linkWidthUnset: S(m(i.getLinkWidth, C == null ? void 0 : C.getLinkWidth), m(t.getLinkWidth, c == null ? void 0 : c.getLinkWidth))
|
|
133
|
+
};
|
|
134
|
+
t.points ? this.state.isReady ? this._load({ pointsChanged: y, linksChanged: d, idsChanged: A, pointStyleChanged: u, linkStyleChanged: I, ...R }) : 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);
|
|
405
135
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
getLinkColor: p.getLinkColor,
|
|
418
|
-
getLinkWidth: p.getLinkWidth
|
|
136
|
+
draw(e) {
|
|
137
|
+
var o, r, p, h;
|
|
138
|
+
const { graph: t, isReady: i } = this.state;
|
|
139
|
+
if (!t || !i) return;
|
|
140
|
+
const { viewport: n } = this.context, s = this._viewTransform(t, n);
|
|
141
|
+
if (s) {
|
|
142
|
+
if (t.setViewTransform(s, [n.width, n.height]), (r = (o = e.shaderModuleProps) == null ? void 0 : o.picking) != null && r.isActive) {
|
|
143
|
+
t.drawToRenderPass(this.context.renderPass, {
|
|
144
|
+
picking: {
|
|
145
|
+
alpha: ((h = (p = e.parameters) == null ? void 0 : p.blendColor) == null ? void 0 : h[3]) ?? 1,
|
|
146
|
+
linkIndexOffset: t.graph.pointsNumber ?? 0
|
|
419
147
|
}
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
// rendered links are exactly the simulated ones
|
|
433
|
-
getLinkSource: (S, { index: r }) => o[r * 2],
|
|
434
|
-
getLinkTarget: (S, { index: r }) => o[r * 2 + 1]
|
|
435
|
-
} : {}
|
|
436
|
-
)
|
|
437
|
-
), v.push(
|
|
438
|
-
new _(
|
|
439
|
-
this.getSubLayerProps({
|
|
440
|
-
id: "points",
|
|
441
|
-
updateTriggers: {
|
|
442
|
-
getPointSize: p.getPointSize,
|
|
443
|
-
getPointColor: p.getPointColor
|
|
444
|
-
}
|
|
445
|
-
}),
|
|
446
|
-
{
|
|
447
|
-
data: s,
|
|
448
|
-
graph: e,
|
|
449
|
-
getPointSize: a,
|
|
450
|
-
getPointColor: l,
|
|
451
|
-
pointSizeUnits: c,
|
|
452
|
-
// getSubLayerProps does not forward `transitions`
|
|
453
|
-
transitions: this.props.transitions
|
|
454
|
-
}
|
|
455
|
-
)
|
|
456
|
-
), v;
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
t.drawToRenderPass(this.context.renderPass);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
getPickingInfo({ info: e }) {
|
|
155
|
+
var r;
|
|
156
|
+
const t = e, i = this.state.graph;
|
|
157
|
+
if (!i || e.index < 0) return t;
|
|
158
|
+
const n = i.graph.pointsNumber ?? 0, { points: s, links: o } = this.props;
|
|
159
|
+
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;
|
|
457
160
|
}
|
|
458
161
|
onDragStart(e, t) {
|
|
459
|
-
var
|
|
460
|
-
const {
|
|
461
|
-
return !
|
|
162
|
+
var r, p, h;
|
|
163
|
+
const { graph: i } = this.state, { enablePointDrag: n, dragReheatAlpha: s } = this.props, o = e;
|
|
164
|
+
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), (h = (p = this.props).onPointDragStart) == null || h.call(p, o), !0);
|
|
462
165
|
}
|
|
463
166
|
onDrag(e, t) {
|
|
464
|
-
var
|
|
465
|
-
const {
|
|
466
|
-
if (!i ||
|
|
467
|
-
const
|
|
468
|
-
return i.setPointPosition(
|
|
167
|
+
var o, r, p;
|
|
168
|
+
const { graph: i, draggedPointIndex: n } = this.state;
|
|
169
|
+
if (!i || n === null) return !1;
|
|
170
|
+
const s = this._dragPosition(i, e);
|
|
171
|
+
return s && i.setPointPosition(n, s[0], s[1]), (o = t.stopImmediatePropagation) == null || o.call(t), (this.getCurrentLayer() ?? this).setNeedsRedraw(), (p = (r = this.props).onPointDrag) == null || p.call(r, e), !0;
|
|
469
172
|
}
|
|
470
173
|
onDragEnd(e, t) {
|
|
471
|
-
var
|
|
472
|
-
const {
|
|
473
|
-
return !i ||
|
|
174
|
+
var s, o, r;
|
|
175
|
+
const { graph: i, draggedPointIndex: n } = this.state;
|
|
176
|
+
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);
|
|
474
177
|
}
|
|
475
|
-
|
|
476
|
-
const t = e.info;
|
|
477
|
-
return e.sourceLayer && (t.elementType = e.sourceLayer.id.endsWith("-links") ? "link" : "point"), t;
|
|
478
|
-
}
|
|
479
|
-
/** The whole simulation space; lets deck's viewport helpers frame the graph. */
|
|
178
|
+
/** The whole simulation space, in space coordinates; lets deck's viewport helpers frame the graph. */
|
|
480
179
|
getBounds() {
|
|
481
|
-
|
|
482
|
-
const e = ((t = this.props.simulationConfig) == null ? void 0 : t.spaceSize) ?? O.spaceSize;
|
|
180
|
+
const e = this._spaceSize();
|
|
483
181
|
return [[0, 0, 0], [e, e, 0]];
|
|
484
182
|
}
|
|
485
183
|
finalizeState(e) {
|
|
486
|
-
var t
|
|
487
|
-
((t = this.state) == null ? void 0 : t.animationHandle) !== void 0 && this.context.timeline.detachAnimation(this.state.animationHandle),
|
|
184
|
+
var t;
|
|
185
|
+
((t = this.state) == null ? void 0 : t.animationHandle) !== void 0 && this.context.timeline.detachAnimation(this.state.animationHandle), this.state && this._releaseGraph(), super.finalizeState(e);
|
|
186
|
+
}
|
|
187
|
+
/** No deck attributes: cosmos.gl holds every channel and draws them itself. */
|
|
188
|
+
_getAttributeManager() {
|
|
189
|
+
return null;
|
|
488
190
|
}
|
|
489
191
|
/**
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
192
|
+
* deck's auto-highlight, through cosmos.gl's own hover emphasis: the hovered point
|
|
193
|
+
* gets the hover ring, the hovered link the hovered-link width and color. It is the
|
|
194
|
+
* graph's host hover, so the graph's config — focus included — stays the
|
|
195
|
+
* application's. deck's picking module has no model of ours to tint, so
|
|
196
|
+
* `highlightColor` does not apply.
|
|
493
197
|
*/
|
|
494
198
|
_updateAutoHighlight(e) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
199
|
+
const { graph: t, isReady: i } = this.state;
|
|
200
|
+
if (!t || !i) return;
|
|
201
|
+
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;
|
|
202
|
+
t.setHostHoveredPoint(s), t.setHostHoveredLink(o), this.state.holdsHover = s !== void 0 || o !== void 0, this.setNeedsRedraw();
|
|
498
203
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
204
|
+
/**
|
|
205
|
+
* The pointer in space coordinates, through the view of the viewport the pointer
|
|
206
|
+
* is in — the same derivation `draw` hands cosmos, inverted — under a map as well
|
|
207
|
+
* as an orthographic view. Not through the view cosmos holds: that is whichever
|
|
208
|
+
* viewport drew the graph last, a thumbnail's as easily as the one being dragged
|
|
209
|
+
* in. Pixels are relative to that viewport. Where the view cannot be derived the
|
|
210
|
+
* point stays where it is.
|
|
211
|
+
*/
|
|
212
|
+
_dragPosition(e, t) {
|
|
213
|
+
const i = t.viewport ?? this.context.viewport, n = this._viewTransform(e, i);
|
|
214
|
+
return n ? [(t.x - i.x - n.originX) / n.k, (n.originY - (t.y - i.y)) / n.k] : null;
|
|
508
215
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
216
|
+
/** Adopts the provided graph, or creates a headless one on deck's device when `provided` is `null`. */
|
|
217
|
+
_attachGraph(e) {
|
|
218
|
+
var n, s;
|
|
219
|
+
const { device: t } = this.context, i = e ?? new V(null, this._graphConfig(), Promise.resolve(t));
|
|
220
|
+
this.setState({
|
|
221
|
+
graph: i,
|
|
222
|
+
providedGraph: e,
|
|
223
|
+
isReady: !1,
|
|
224
|
+
hasLoaded: !1,
|
|
225
|
+
loadedPositions: void 0,
|
|
226
|
+
loadedPairs: null,
|
|
227
|
+
idToIndex: null,
|
|
228
|
+
keptLinks: null
|
|
229
|
+
}), e || (s = (n = this.props).onGraphCreated) == null || s.call(n, i), i.ready.then(() => {
|
|
230
|
+
var r;
|
|
231
|
+
if (((r = this.state) == null ? void 0 : r.graph) !== i) return;
|
|
232
|
+
const o = this.getCurrentLayer() ?? this;
|
|
233
|
+
if (i.simulation.device !== o.context.device) {
|
|
234
|
+
console.error(
|
|
235
|
+
"@cosmos.gl/deck-layers: the provided graph runs on a different device than deck — construct it with the device from deck's onDeviceInitialized"
|
|
236
|
+
);
|
|
237
|
+
return;
|
|
521
238
|
}
|
|
522
|
-
|
|
239
|
+
o.state.isIngestPending && (o.state.isIngestPending = !1, o._load({
|
|
240
|
+
pointsChanged: !0,
|
|
241
|
+
linksChanged: !0,
|
|
242
|
+
idsChanged: !0,
|
|
243
|
+
pointStyleChanged: !0,
|
|
244
|
+
linkStyleChanged: !0,
|
|
245
|
+
pointColorUnset: !1,
|
|
246
|
+
pointSizeUnset: !1,
|
|
247
|
+
linkColorUnset: !1,
|
|
248
|
+
linkWidthUnset: !1
|
|
249
|
+
})), o.setState({ isReady: !0 });
|
|
250
|
+
}).catch((o) => {
|
|
251
|
+
console.error("@cosmos.gl/deck-layers: the graph failed to initialize", o);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Destroys a layer-created graph; a provided one is left to the application, without
|
|
256
|
+
* the hover this layer put on it. deck sends no leave to a layer it removes.
|
|
257
|
+
*/
|
|
258
|
+
_releaseGraph() {
|
|
259
|
+
const { graph: e, providedGraph: t, holdsHover: i } = this.state;
|
|
260
|
+
e && t ? i && (e.setHostHoveredPoint(void 0), e.setHostHoveredLink(void 0)) : e && e.destroy(), this.state.graph = void 0, this.state.holdsHover = !1;
|
|
261
|
+
}
|
|
262
|
+
/** The graph's space size — authoritative for a provided graph too. */
|
|
263
|
+
_spaceSize() {
|
|
264
|
+
var e, t, i, n;
|
|
265
|
+
return ((t = (e = this.state) == null ? void 0 : e.graph) == null ? void 0 : t.config.spaceSize) ?? ((i = this.props.config) == null ? void 0 : i.spaceSize) ?? ((n = V.prototype.config) == null ? void 0 : n.spaceSize) ?? 4096;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The config for a layer-created graph: the prop without the keys deck owns,
|
|
269
|
+
* and the pixel ratio deck's canvas draws at, so cosmos sizes pixels alike.
|
|
270
|
+
*/
|
|
271
|
+
_graphConfig() {
|
|
272
|
+
const e = { ...this.props.config };
|
|
273
|
+
for (const t of et) delete e[t];
|
|
274
|
+
return e.pixelRatio = this._pixelRatio(), e;
|
|
275
|
+
}
|
|
276
|
+
/** deck's device pixels per CSS pixel, as its canvas context reports them. */
|
|
277
|
+
_pixelRatio() {
|
|
278
|
+
var i;
|
|
279
|
+
const e = this.context.device.canvasContext, t = (i = e == null ? void 0 : e.cssToDeviceRatio) == null ? void 0 : i.call(e);
|
|
280
|
+
return t && Number.isFinite(t) ? t : typeof window < "u" && window.devicePixelRatio || 1;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* cosmos's view for a deck viewport: a uniform scale `k` (pixels per space
|
|
284
|
+
* unit) and a translation, per `setViewTransform`'s space → screen formula,
|
|
285
|
+
* inverted. Three anchors through deck's projection — the space origin, its
|
|
286
|
+
* x axis, its y axis — give the scale and tell whether the view is one cosmos
|
|
287
|
+
* can draw: unrotated, unpitched, y up. The space origin's pixel is returned
|
|
288
|
+
* too, for mapping the other way.
|
|
289
|
+
*/
|
|
290
|
+
_viewTransform(e, t) {
|
|
291
|
+
const i = e.config.spaceSize, n = this.props.modelMatrix, s = (g, P) => {
|
|
292
|
+
const C = n ? n[0] * g + n[4] * P + n[12] : g, c = n ? n[1] * g + n[5] * P + n[13] : P, S = t.unprojectPosition([C, c, 0]), R = t.project(S);
|
|
293
|
+
return [R[0], R[1]];
|
|
294
|
+
}, [o, r] = s(0, 0), [p, h] = s(i, 0), [y, A] = s(0, i), d = (p - o) / i, u = 1e-3 * Math.max(1, Math.abs(p - o)), I = Math.abs(h - r) > u || Math.abs(y - o) > u, k = A > r;
|
|
295
|
+
return I || k || !(d > 0) ? (this.state.viewWarned || (this.state.viewWarned = !0, console.warn(
|
|
296
|
+
"@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."
|
|
297
|
+
)), null) : (this.state.viewWarned = !1, {
|
|
298
|
+
k: d,
|
|
299
|
+
x: o - d * (t.width - i) / 2,
|
|
300
|
+
y: r - d * (i + (t.height - i) / 2),
|
|
301
|
+
originX: o,
|
|
302
|
+
originY: r
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
_onTimelineTick(e) {
|
|
306
|
+
const { graph: t, isReady: i } = this.state ?? {};
|
|
307
|
+
!t || !i || !t.isSimulationRunning || (X.get(t) !== e && (X.set(t, e), t.step()), (this.getCurrentLayer() ?? this).setNeedsRedraw());
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Load mode: puts the layer's `points`, `links` and styles into the graph.
|
|
311
|
+
* Each channel is sent only when its own input changed — a restyle leaves the
|
|
312
|
+
* layout alone, a changed id map re-resolves array links without touching the
|
|
313
|
+
* positions.
|
|
314
|
+
*/
|
|
315
|
+
_load(e) {
|
|
316
|
+
var O, G;
|
|
317
|
+
const t = this.state.graph;
|
|
318
|
+
if (!t) return;
|
|
319
|
+
const { points: i, links: n, getPointId: s, getPointPosition: o } = this.props;
|
|
320
|
+
if (!i) return;
|
|
321
|
+
const r = !this.state.hasLoaded, p = this._spaceSize(), h = () => p * t.simulation.store.getRandomFloat(0.25, 0.75);
|
|
322
|
+
let y, A = null, d, u = null, I = this.state.loadedPositions, k = this.state.idToIndex ?? null;
|
|
323
|
+
if (Array.isArray(i)) {
|
|
324
|
+
const l = i;
|
|
325
|
+
if (y = l.length, A = l, r || e.pointsChanged) {
|
|
326
|
+
u = new Float32Array(y * 2), k = s ? /* @__PURE__ */ new Map() : null;
|
|
327
|
+
for (let f = 0; f < y; f += 1) {
|
|
328
|
+
const v = l[f], D = { index: f, data: l, target: [] }, L = o ? T(o, v, D) : null;
|
|
329
|
+
u[f * 2] = L ? L[0] : h(), u[f * 2 + 1] = L ? L[1] : h(), k && s && k.set(T(s, v, D), f);
|
|
330
|
+
}
|
|
331
|
+
I = l;
|
|
332
|
+
} else if (e.idsChanged && (k = s ? /* @__PURE__ */ new Map() : null, k && s))
|
|
333
|
+
for (let f = 0; f < y; f += 1) {
|
|
334
|
+
const v = { index: f, data: l, target: [] };
|
|
335
|
+
k.set(T(s, l[f], v), f);
|
|
336
|
+
}
|
|
523
337
|
} else {
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
338
|
+
const l = i;
|
|
339
|
+
y = l.length, d = l.attributes, k = null;
|
|
340
|
+
const f = l.initialPositions ?? ot;
|
|
341
|
+
if (r || f !== this.state.loadedPositions || y !== this.state.pointCount) {
|
|
342
|
+
if (l.initialPositions)
|
|
343
|
+
u = l.initialPositions;
|
|
344
|
+
else {
|
|
345
|
+
u = new Float32Array(y * 2);
|
|
346
|
+
for (let v = 0; v < u.length; v += 1) u[v] = h();
|
|
347
|
+
}
|
|
348
|
+
I = f;
|
|
530
349
|
}
|
|
531
|
-
P = r.attributes ? { length: l, attributes: r.attributes } : { length: l };
|
|
532
350
|
}
|
|
533
|
-
let
|
|
534
|
-
if (
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
351
|
+
let g = null, P = this.state.linkCount, C = this.state.keptLinks, c;
|
|
352
|
+
if (n instanceof Float32Array || n && !Array.isArray(n) && "pairs" in n) {
|
|
353
|
+
const l = n instanceof Float32Array ? n : n.pairs;
|
|
354
|
+
c = n instanceof Float32Array ? void 0 : n.attributes, C = null, P = l.length / 2, (r || l !== this.state.loadedPairs) && (g = l);
|
|
355
|
+
} else if (Array.isArray(n)) {
|
|
356
|
+
if (r || e.linksChanged || u) {
|
|
357
|
+
const l = n, { getLinkSource: f, getLinkTarget: v } = this.props, D = (x) => {
|
|
358
|
+
const w = k ? k.get(x) : x;
|
|
359
|
+
return typeof w == "number" && Number.isInteger(w) && w >= 0 && w < y ? w : void 0;
|
|
360
|
+
}, L = [], b = [];
|
|
361
|
+
for (let x = 0; x < l.length; x += 1) {
|
|
362
|
+
const w = l[x], N = { index: x, data: l, target: [] }, B = D(T(f, w, N)), U = D(T(v, w, N));
|
|
363
|
+
B === void 0 || U === void 0 || (L.push(w), b.push(B, U));
|
|
364
|
+
}
|
|
365
|
+
const H = l.length - L.length;
|
|
366
|
+
if (H > 0) {
|
|
367
|
+
const x = k ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
|
|
368
|
+
console.warn(
|
|
369
|
+
`@cosmos.gl/deck-layers: dropped ${H} of ${l.length} links whose source or target is not a point — check ${x}`
|
|
370
|
+
);
|
|
540
371
|
}
|
|
541
|
-
|
|
542
|
-
else if (Array.isArray(i)) {
|
|
543
|
-
const r = i, { getLinkSource: u, getLinkTarget: C } = this.props, x = (g) => {
|
|
544
|
-
const h = f ? f.get(g) : g;
|
|
545
|
-
return typeof h == "number" && Number.isInteger(h) && h >= 0 && h < l ? h : void 0;
|
|
546
|
-
}, m = [], b = [];
|
|
547
|
-
for (let g = 0; g < r.length; g += 1) {
|
|
548
|
-
const h = r[g], E = { index: g, data: r, target: [] }, w = x(k(u, h, E)), R = x(k(C, h, E));
|
|
549
|
-
w === void 0 || R === void 0 || (m.push(h), b.push(w, R));
|
|
372
|
+
g = Float32Array.from(b), C = L, P = L.length;
|
|
550
373
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
374
|
+
} else
|
|
375
|
+
C = null, P = 0, (r || this.state.loadedPairs !== $) && (g = $);
|
|
376
|
+
u && t.setPointPositions(u, t.config.rescalePositions === void 0 ? !0 : void 0), g && t.setLinks(g);
|
|
377
|
+
const { getPointColor: S, getPointSize: R, getLinkColor: z, getLinkWidth: _ } = this.props;
|
|
378
|
+
(u || e.pointStyleChanged) && (m(S, d == null ? void 0 : d.getPointColor) ? t.setPointColors(Y(y, S, A, d == null ? void 0 : d.getPointColor)) : e.pointColorUnset && t.setPointColors(E), m(R, d == null ? void 0 : d.getPointSize) ? t.setPointSizes(Z(y, R, A, d == null ? void 0 : d.getPointSize)) : e.pointSizeUnset && t.setPointSizes(E)), (g || e.linkStyleChanged) && (m(z, c == null ? void 0 : c.getLinkColor) ? t.setLinkColors(Y(P, z, C, c == null ? void 0 : c.getLinkColor)) : e.linkColorUnset && t.setLinkColors(E), m(_, c == null ? void 0 : c.getLinkWidth) ? t.setLinkWidths(Z(P, _, C, c == null ? void 0 : c.getLinkWidth)) : e.linkWidthUnset && t.setLinkWidths(E)), t.render();
|
|
379
|
+
const J = k !== this.state.idToIndex;
|
|
380
|
+
if (this.setState({
|
|
381
|
+
hasLoaded: !0,
|
|
382
|
+
pointCount: y,
|
|
383
|
+
linkCount: P,
|
|
384
|
+
keptLinks: C,
|
|
385
|
+
loadedPositions: I,
|
|
386
|
+
loadedPairs: g ?? this.state.loadedPairs,
|
|
387
|
+
idToIndex: k
|
|
388
|
+
}), u || g || J)
|
|
389
|
+
try {
|
|
390
|
+
(G = (O = this.props).onGraphDataLoaded) == null || G.call(O, {
|
|
391
|
+
graph: t,
|
|
392
|
+
pointsLoaded: !!u,
|
|
393
|
+
linksLoaded: !!g,
|
|
394
|
+
pointIndexById: k,
|
|
395
|
+
links: Array.isArray(n) ? C : null
|
|
396
|
+
});
|
|
397
|
+
} catch (l) {
|
|
398
|
+
this.raiseError(l, "onGraphDataLoaded");
|
|
557
399
|
}
|
|
558
|
-
y = Float32Array.from(b), v = y, p = m;
|
|
559
|
-
}
|
|
560
|
-
e.setPointPositions(c), e.setLinks(y ?? new Float32Array(0)), e.applyData(), this.setState({ pointCount: l, pointsData: P, linksData: p, linkIndices: v });
|
|
561
400
|
}
|
|
562
401
|
};
|
|
563
|
-
|
|
564
|
-
let
|
|
402
|
+
F.layerName = "CosmosGraphLayer", F.defaultProps = it;
|
|
403
|
+
let q = F;
|
|
565
404
|
export {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
_ as CosmosPointsLayer
|
|
405
|
+
q as CosmosGraphLayer,
|
|
406
|
+
et as DECK_OWNED_CONFIG_KEYS
|
|
569
407
|
};
|
|
570
408
|
//# sourceMappingURL=index.js.map
|