@cosmos.gl/deck-layers 3.5.0 → 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 +136 -69
- package/dist/cosmos-graph-layer.d.ts +230 -123
- package/dist/index.d.ts +6 -6
- package/dist/index.js +329 -592
- 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 -20
- package/dist/cosmos-links-layer.d.ts +0 -68
- package/dist/cosmos-points-layer-uniforms.d.ts +0 -18
- package/dist/cosmos-points-layer.d.ts +0 -52
package/dist/index.js
CHANGED
|
@@ -1,671 +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
|
-
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 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 = {
|
|
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:
|
|
365
|
-
getPointColor: { type: "accessor", value:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
getLinkWidth: { type: "accessor", value: 1 },
|
|
371
|
-
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") },
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
//
|
|
383
|
-
|
|
384
|
-
},
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
}
|
|
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 {
|
|
393
94
|
get isLoaded() {
|
|
394
|
-
var
|
|
395
|
-
return super.isLoaded && !!((
|
|
95
|
+
var e;
|
|
96
|
+
return super.isLoaded && !!((e = this.state) != null && e.isReady);
|
|
396
97
|
}
|
|
397
98
|
initializeState() {
|
|
398
|
-
const { device:
|
|
399
|
-
if (
|
|
99
|
+
const { device: e, timeline: t } = this.context;
|
|
100
|
+
if (e.type !== "webgl")
|
|
400
101
|
throw new Error(
|
|
401
|
-
`@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}'`
|
|
402
103
|
);
|
|
403
104
|
this.state = {
|
|
404
|
-
|
|
105
|
+
providedGraph: null,
|
|
405
106
|
isReady: !1,
|
|
406
107
|
isIngestPending: !1,
|
|
407
108
|
hasLoaded: !1,
|
|
408
109
|
pointCount: 0,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
linkIndices: null,
|
|
110
|
+
linkCount: 0,
|
|
111
|
+
keptLinks: null,
|
|
412
112
|
draggedPointIndex: null,
|
|
113
|
+
holdsHover: !1,
|
|
413
114
|
// Step the simulation exactly once per animation frame, independent of
|
|
414
|
-
// draw passes (draw runs per viewport
|
|
415
|
-
animationHandle:
|
|
416
|
-
}, this.
|
|
417
|
-
}
|
|
418
|
-
updateState(
|
|
419
|
-
super.updateState(
|
|
420
|
-
const { props:
|
|
421
|
-
o && (this.
|
|
422
|
-
const r = this.state.
|
|
115
|
+
// draw passes (draw runs per viewport)
|
|
116
|
+
animationHandle: t.attachAnimation({ setTime: (i) => this._onTimelineTick(i) })
|
|
117
|
+
}, this._attachGraph(this.props.graph ?? null);
|
|
118
|
+
}
|
|
119
|
+
updateState(e) {
|
|
120
|
+
super.updateState(e);
|
|
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;
|
|
423
124
|
if (!r) return;
|
|
424
|
-
!
|
|
425
|
-
const
|
|
426
|
-
!
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
|
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);
|
|
135
|
+
}
|
|
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
|
|
466
147
|
}
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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);
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
t.drawToRenderPass(this.context.renderPass);
|
|
152
|
+
}
|
|
484
153
|
}
|
|
485
|
-
|
|
486
|
-
var r
|
|
487
|
-
const
|
|
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;
|
|
160
|
+
}
|
|
161
|
+
onDragStart(e, t) {
|
|
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);
|
|
165
|
+
}
|
|
166
|
+
onDrag(e, t) {
|
|
167
|
+
var o, r, p;
|
|
168
|
+
const { graph: i, draggedPointIndex: n } = this.state;
|
|
488
169
|
if (!i || n === null) return !1;
|
|
489
|
-
const
|
|
490
|
-
return i.setPointPosition(n,
|
|
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;
|
|
491
172
|
}
|
|
492
|
-
onDragEnd(
|
|
493
|
-
var
|
|
494
|
-
const {
|
|
495
|
-
return !i || n === null ? !1 : (this.props.unpinOnDragEnd && i.setPinnedPoint(n, !1), this.state.draggedPointIndex = null, (
|
|
173
|
+
onDragEnd(e, t) {
|
|
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);
|
|
496
177
|
}
|
|
497
|
-
|
|
498
|
-
const e = t.info;
|
|
499
|
-
return t.sourceLayer && (e.elementType = t.sourceLayer.id.endsWith("-links") ? "link" : "point"), e;
|
|
500
|
-
}
|
|
501
|
-
/** 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. */
|
|
502
179
|
getBounds() {
|
|
503
|
-
const
|
|
504
|
-
return [[0, 0, 0], [
|
|
180
|
+
const e = this._spaceSize();
|
|
181
|
+
return [[0, 0, 0], [e, e, 0]];
|
|
505
182
|
}
|
|
506
|
-
finalizeState(
|
|
507
|
-
var
|
|
508
|
-
((
|
|
183
|
+
finalizeState(e) {
|
|
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;
|
|
509
190
|
}
|
|
510
191
|
/**
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
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.
|
|
514
197
|
*/
|
|
515
|
-
_updateAutoHighlight(
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
198
|
+
_updateAutoHighlight(e) {
|
|
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();
|
|
519
203
|
}
|
|
520
|
-
/**
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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;
|
|
215
|
+
}
|
|
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));
|
|
524
220
|
this.setState({
|
|
525
|
-
|
|
526
|
-
|
|
221
|
+
graph: i,
|
|
222
|
+
providedGraph: e,
|
|
527
223
|
isReady: !1,
|
|
528
224
|
hasLoaded: !1,
|
|
529
225
|
loadedPositions: void 0,
|
|
530
226
|
loadedPairs: null,
|
|
531
227
|
idToIndex: null,
|
|
532
|
-
|
|
533
|
-
}),
|
|
228
|
+
keptLinks: null
|
|
229
|
+
}), e || (s = (n = this.props).onGraphCreated) == null || s.call(n, i), i.ready.then(() => {
|
|
534
230
|
var r;
|
|
535
|
-
if (((r = this.state) == null ? void 0 : r.
|
|
231
|
+
if (((r = this.state) == null ? void 0 : r.graph) !== i) return;
|
|
536
232
|
const o = this.getCurrentLayer() ?? this;
|
|
537
|
-
if (i.device !== o.context.device) {
|
|
233
|
+
if (i.simulation.device !== o.context.device) {
|
|
538
234
|
console.error(
|
|
539
|
-
"@cosmos.gl/deck-layers: the provided
|
|
235
|
+
"@cosmos.gl/deck-layers: the provided graph runs on a different device than deck — construct it with the device from deck's onDeviceInitialized"
|
|
540
236
|
);
|
|
541
237
|
return;
|
|
542
238
|
}
|
|
543
|
-
o.state.isIngestPending
|
|
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 });
|
|
544
250
|
}).catch((o) => {
|
|
545
|
-
console.error("@cosmos.gl/deck-layers:
|
|
251
|
+
console.error("@cosmos.gl/deck-layers: the graph failed to initialize", o);
|
|
546
252
|
});
|
|
547
253
|
}
|
|
548
|
-
/**
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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;
|
|
552
261
|
}
|
|
553
|
-
/** The
|
|
262
|
+
/** The graph's space size — authoritative for a provided graph too. */
|
|
554
263
|
_spaceSize() {
|
|
555
|
-
var t,
|
|
556
|
-
return ((
|
|
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;
|
|
557
275
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const
|
|
562
|
-
|
|
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;
|
|
563
281
|
}
|
|
564
282
|
/**
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
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.
|
|
568
289
|
*/
|
|
569
|
-
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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
|
|
579
303
|
});
|
|
580
304
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
return [e[0], e[1]];
|
|
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());
|
|
585
308
|
}
|
|
586
309
|
/**
|
|
587
|
-
* Load mode: puts the layer's `points
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* re-resolves array links without touching the positions.
|
|
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.
|
|
592
314
|
*/
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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);
|
|
607
330
|
}
|
|
608
|
-
|
|
609
|
-
} else if (
|
|
610
|
-
for (let
|
|
611
|
-
const
|
|
612
|
-
|
|
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);
|
|
613
336
|
}
|
|
614
337
|
} else {
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
if (
|
|
619
|
-
if (
|
|
620
|
-
|
|
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;
|
|
621
344
|
else {
|
|
622
|
-
|
|
623
|
-
for (let
|
|
345
|
+
u = new Float32Array(y * 2);
|
|
346
|
+
for (let v = 0; v < u.length; v += 1) u[v] = h();
|
|
624
347
|
}
|
|
625
|
-
|
|
348
|
+
I = f;
|
|
626
349
|
}
|
|
627
350
|
}
|
|
628
|
-
let
|
|
629
|
-
if (
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
} else if (Array.isArray(
|
|
633
|
-
if (
|
|
634
|
-
const
|
|
635
|
-
const
|
|
636
|
-
return typeof
|
|
637
|
-
},
|
|
638
|
-
for (let
|
|
639
|
-
const
|
|
640
|
-
|
|
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));
|
|
641
364
|
}
|
|
642
|
-
const
|
|
643
|
-
if (
|
|
644
|
-
const
|
|
365
|
+
const H = l.length - L.length;
|
|
366
|
+
if (H > 0) {
|
|
367
|
+
const x = k ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
|
|
645
368
|
console.warn(
|
|
646
|
-
`@cosmos.gl/deck-layers: dropped ${
|
|
369
|
+
`@cosmos.gl/deck-layers: dropped ${H} of ${l.length} links whose source or target is not a point — check ${x}`
|
|
647
370
|
);
|
|
648
371
|
}
|
|
649
|
-
|
|
372
|
+
g = Float32Array.from(b), C = L, P = L.length;
|
|
650
373
|
}
|
|
651
374
|
} else
|
|
652
|
-
|
|
653
|
-
|
|
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({
|
|
654
381
|
hasLoaded: !0,
|
|
655
|
-
pointCount:
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
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");
|
|
399
|
+
}
|
|
664
400
|
}
|
|
665
401
|
};
|
|
666
|
-
|
|
667
|
-
let
|
|
402
|
+
F.layerName = "CosmosGraphLayer", F.defaultProps = it;
|
|
403
|
+
let q = F;
|
|
668
404
|
export {
|
|
669
|
-
|
|
405
|
+
q as CosmosGraphLayer,
|
|
406
|
+
et as DECK_OWNED_CONFIG_KEYS
|
|
670
407
|
};
|
|
671
408
|
//# sourceMappingURL=index.js.map
|