@graphty/cytoscape-extensions 0.0.28 → 0.0.29

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.
Files changed (72) hide show
  1. package/dist/algorithm-options.d.ts +5 -0
  2. package/dist/algorithm-options.d.ts.map +1 -0
  3. package/dist/algorithm-options.js +285 -0
  4. package/dist/algorithm-options.js.map +1 -0
  5. package/dist/algorithms.d.ts +489 -0
  6. package/dist/algorithms.d.ts.map +1 -0
  7. package/dist/algorithms.js +1184 -0
  8. package/dist/algorithms.js.map +1 -0
  9. package/dist/cdn/chunks/elements-DkrLtNP8.js +1 -0
  10. package/dist/cdn/chunks/gpu-platform-browser-VBah74fl.js +2825 -0
  11. package/dist/cdn/chunks/index-C4RZkds_.js +10 -0
  12. package/dist/cdn/chunks/index-CAhmhhmb.js +1 -0
  13. package/dist/cdn/chunks/io-Da5POp5D.js +268 -0
  14. package/dist/cdn/chunks/preload-helper-DEpZAvig.js +1 -0
  15. package/dist/cdn/chunks/samples-BkLzaDJ3.js +1 -0
  16. package/dist/cdn/chunks/sigv4-EokFic1V-CWJiFeEe.js +3 -0
  17. package/dist/cdn/chunks/sources-cypher-BGGD4kJ9.js +5 -0
  18. package/dist/cdn/chunks/sources-ndex-CxnPOYff.js +1 -0
  19. package/dist/cdn/chunks/sources-rest-BPNV8mX-.js +1 -0
  20. package/dist/cdn/chunks/sources-sparql-BiqRQuHD.js +5 -0
  21. package/dist/cdn/cytoscape-extensions.js +1 -0
  22. package/dist/cdn/io.js +1 -0
  23. package/dist/cytoscape-extensions.bundle.js +2825 -0
  24. package/dist/elements.d.ts +69 -0
  25. package/dist/elements.d.ts.map +1 -0
  26. package/dist/elements.js +343 -0
  27. package/dist/elements.js.map +1 -0
  28. package/dist/gpu-platform-browser.d.ts +11 -0
  29. package/dist/gpu-platform-browser.d.ts.map +1 -0
  30. package/dist/gpu-platform-browser.js +22 -0
  31. package/dist/gpu-platform-browser.js.map +1 -0
  32. package/dist/gpu-platform-node.d.ts +15 -0
  33. package/dist/gpu-platform-node.d.ts.map +1 -0
  34. package/dist/gpu-platform-node.js +27 -0
  35. package/dist/gpu-platform-node.js.map +1 -0
  36. package/dist/gpu.d.ts +149 -0
  37. package/dist/gpu.d.ts.map +1 -0
  38. package/dist/gpu.js +312 -0
  39. package/dist/gpu.js.map +1 -0
  40. package/dist/graph-data.d.ts +101 -0
  41. package/dist/graph-data.d.ts.map +1 -0
  42. package/dist/graph-data.js +147 -0
  43. package/dist/graph-data.js.map +1 -0
  44. package/dist/index.d.ts +36 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +48 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/io.d.ts +111 -0
  49. package/dist/io.d.ts.map +1 -0
  50. package/dist/io.js +258 -0
  51. package/dist/io.js.map +1 -0
  52. package/dist/layouts.d.ts +207 -0
  53. package/dist/layouts.d.ts.map +1 -0
  54. package/dist/layouts.js +615 -0
  55. package/dist/layouts.js.map +1 -0
  56. package/dist/lazy.d.ts +21 -0
  57. package/dist/lazy.d.ts.map +1 -0
  58. package/dist/lazy.js +32 -0
  59. package/dist/lazy.js.map +1 -0
  60. package/dist/samples.d.ts +115 -0
  61. package/dist/samples.d.ts.map +1 -0
  62. package/dist/samples.js +237 -0
  63. package/dist/samples.js.map +1 -0
  64. package/dist/snapshot.d.ts +81 -0
  65. package/dist/snapshot.d.ts.map +1 -0
  66. package/dist/snapshot.js +225 -0
  67. package/dist/snapshot.js.map +1 -0
  68. package/dist/webgpu-provider.d.ts +25 -0
  69. package/dist/webgpu-provider.d.ts.map +1 -0
  70. package/dist/webgpu-provider.js +53 -0
  71. package/dist/webgpu-provider.js.map +1 -0
  72. package/package.json +13 -9
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Conversion between a graph-format snapshot with its attributes and Cytoscape element definitions, for the import,
3
+ * export, generator and dataset methods. Unlike toSnapshot() (topology and one weight, for the algorithms), these
4
+ * carry every data field across.
5
+ */
6
+ import { type GraphSnapshot } from "@graphty/graph-format";
7
+ import type { Collection, ElementDefinition } from "cytoscape";
8
+ /**
9
+ * A y coordinate between Cytoscape (y grows downward) and graph-io (y grows upward, so a Cytoscape-family file's
10
+ * screen y is negated on import and negated back on export). Never yields -0.
11
+ * @param y - the coordinate
12
+ * @returns the negated coordinate
13
+ */
14
+ export declare function flipY(y: number): number;
15
+ /** A column that arrives under another data field name, because Cytoscape reserves its own. */
16
+ interface RenamedColumn {
17
+ readonly domain: "node" | "edge";
18
+ readonly from: string;
19
+ readonly to: string;
20
+ }
21
+ /**
22
+ * Cytoscape element definitions for a snapshot. Node ids are the snapshot's ids as strings. Every node and edge
23
+ * column becomes a data field of the same name, except that one named `id`, `source`, `target` or `parent` (which
24
+ * Cytoscape reserves) becomes `<name>#<the attribute's id in the file>`, or `<name>#2` when it has none, and:
25
+ * - a node column with the role "position" becomes the node's position (x and y; a z is dropped);
26
+ * - a node column with the role "parent" (a compound parent, as Cytoscape JSON, GraphML nested graphs and DOT
27
+ * clusters carry it) becomes `data.parent`;
28
+ * - an edge column with the role "id" becomes the edge's id when that id is not a node id and not used by an
29
+ * earlier edge; otherwise the edge gets no id, Cytoscape assigns one, and `onIdDropped` hears about it;
30
+ * - the edge weights become `data.weight`: the weight column when the file had one, else the snapshot's weights
31
+ * when it is weighted.
32
+ * @param snapshot - the snapshot
33
+ * @param onRename - told about each column renamed because its name is reserved
34
+ * @param onIdDropped - told about each edge id dropped, and whether a node or an earlier edge has it
35
+ * @param styled - whether the file's styles are read as a stylesheet: then the columns that hold styles (a GEXF
36
+ * `viz:color`, `viz:size`, `viz:shape`, its image and `viz:thickness`) are left out of data, because the
37
+ * stylesheet carries them
38
+ * @returns the nodes, then the edges
39
+ */
40
+ export declare function snapshotToElements(snapshot: GraphSnapshot, onRename?: (renamed: RenamedColumn) => void, onIdDropped?: (id: string, takenBy: "node" | "edge") => void, styled?: boolean): ElementDefinition[];
41
+ /**
42
+ * The edges of a collection that elementsToSnapshot() writes, in its order: those whose two ends are in it.
43
+ * @param eles - the collection
44
+ * @returns the edges
45
+ */
46
+ export declare function exportedEdges(eles: Collection): Collection;
47
+ /**
48
+ * A snapshot of a collection with every data field as a column and every node's position as a "position" column
49
+ * (y negated: graph-io's y grows upward), for an exporter. Edges whose endpoints are not both in the collection are left out. A numeric edge field named
50
+ * `weight` becomes the snapshot's edge weights when every edge has one. Edge ids become an "id" column, and a
51
+ * compound node's parent a "parent" column when the parent is in the collection too (a parent outside it is left
52
+ * out, so the node is written as a top-level node). Hidden elements are written like any other: pass
53
+ * `cy.elements(":visible")` to leave them out.
54
+ * @param eles - the collection
55
+ * @param options - the direction and the id type
56
+ * @param options.directed - write a directed graph (default false)
57
+ * @param options.integerIds - when every node id is a non-negative integer written plainly ("0", "17"), give the
58
+ * snapshot number ids, so a format that holds only integer ids (GML, CX2) writes them as they are (default false)
59
+ * @param options.format - the format the snapshot is written in: the positions are spelled as its writer expects
60
+ * them (GML and Pajek draw y downward); without it they are graph-io's neutral form, y up
61
+ * @returns the snapshot
62
+ */
63
+ export declare function elementsToSnapshot(eles: Collection, options?: {
64
+ readonly directed?: boolean | undefined;
65
+ readonly integerIds?: boolean | undefined;
66
+ readonly format?: string | undefined;
67
+ }): GraphSnapshot;
68
+ export {};
69
+ //# sourceMappingURL=elements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiD,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE1G,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAkB/D;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED,+FAA+F;AAC/F,UAAU,aAAa;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAC9B,QAAQ,EAAE,aAAa,EACvB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,EAC3C,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,EAC5D,MAAM,UAAQ,GACf,iBAAiB,EAAE,CAUrB;AA6OD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAG1D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,UAAU,EAChB,OAAO,GAAE;IACL,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC,GACP,aAAa,CAuDf"}
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Conversion between a graph-format snapshot with its attributes and Cytoscape element definitions, for the import,
3
+ * export, generator and dataset methods. Unlike toSnapshot() (topology and one weight, for the algorithms), these
4
+ * carry every data field across.
5
+ */
6
+ import { fromEdgeArrays } from "@graphty/graph-format";
7
+ import { writtenPositions } from "@graphty/graph-io/positions";
8
+ /**
9
+ * Data fields Cytoscape gives a meaning of its own, and "__proto__", whose assignment would set the data object's
10
+ * prototype (and with it inherited id, source, target or parent fields). An element's own data fields of these names
11
+ * are not exported as columns; a column with one of these names is imported under another name (see fieldNames).
12
+ */
13
+ const RESERVED = new Set(["id", "source", "target", "parent", "__proto__"]);
14
+ /**
15
+ * A column value as Cytoscape data: a typed array (a multi-component column) becomes a plain array.
16
+ * @param v - the column value
17
+ * @returns the value to store
18
+ */
19
+ function plain(v) {
20
+ return ArrayBuffer.isView(v) ? Array.from(v) : v;
21
+ }
22
+ /**
23
+ * A y coordinate between Cytoscape (y grows downward) and graph-io (y grows upward, so a Cytoscape-family file's
24
+ * screen y is negated on import and negated back on export). Never yields -0.
25
+ * @param y - the coordinate
26
+ * @returns the negated coordinate
27
+ */
28
+ export function flipY(y) {
29
+ return y === 0 ? 0 : -y;
30
+ }
31
+ /**
32
+ * Cytoscape element definitions for a snapshot. Node ids are the snapshot's ids as strings. Every node and edge
33
+ * column becomes a data field of the same name, except that one named `id`, `source`, `target` or `parent` (which
34
+ * Cytoscape reserves) becomes `<name>#<the attribute's id in the file>`, or `<name>#2` when it has none, and:
35
+ * - a node column with the role "position" becomes the node's position (x and y; a z is dropped);
36
+ * - a node column with the role "parent" (a compound parent, as Cytoscape JSON, GraphML nested graphs and DOT
37
+ * clusters carry it) becomes `data.parent`;
38
+ * - an edge column with the role "id" becomes the edge's id when that id is not a node id and not used by an
39
+ * earlier edge; otherwise the edge gets no id, Cytoscape assigns one, and `onIdDropped` hears about it;
40
+ * - the edge weights become `data.weight`: the weight column when the file had one, else the snapshot's weights
41
+ * when it is weighted.
42
+ * @param snapshot - the snapshot
43
+ * @param onRename - told about each column renamed because its name is reserved
44
+ * @param onIdDropped - told about each edge id dropped, and whether a node or an earlier edge has it
45
+ * @param styled - whether the file's styles are read as a stylesheet: then the columns that hold styles (a GEXF
46
+ * `viz:color`, `viz:size`, `viz:shape`, its image and `viz:thickness`) are left out of data, because the
47
+ * stylesheet carries them
48
+ * @returns the nodes, then the edges
49
+ */
50
+ export function snapshotToElements(snapshot, onRename, onIdDropped, styled = false) {
51
+ const ids = [];
52
+ for (let i = 0; i < snapshot.nodeCount; i++) {
53
+ ids.push(String(snapshot.ids.idOf(i)));
54
+ }
55
+ const keep = styled ? (c) => kept(c) && !holdsStyle(c) : kept;
56
+ return [
57
+ ...nodeElements(snapshot, ids, onRename, keep),
58
+ ...edgeElements(snapshot, ids, onRename, onIdDropped, keep),
59
+ ];
60
+ }
61
+ /**
62
+ * Whether a column becomes a data field of its own (not the id or the parent, which the element gets as such).
63
+ * @param c - the column
64
+ * @returns true to copy it into data
65
+ */
66
+ function kept(c) {
67
+ return c.meta.role !== "id" && c.meta.role !== "parent";
68
+ }
69
+ /** The roles of the columns that hold styles, which graph-io reads as a file's styles. */
70
+ const STYLE_ROLES = new Set(["color", "size", "shape", "thickness"]);
71
+ /**
72
+ * Whether a column holds styles: one with a style role, or GEXF's image of an `image` shape.
73
+ * @param c - the column
74
+ * @returns true for a style column
75
+ */
76
+ function holdsStyle(c) {
77
+ const { role, name, origin } = c.meta;
78
+ return (role !== null && STYLE_ROLES.has(role)) || (name === "shape.uri" && origin?.namespace === "viz");
79
+ }
80
+ /**
81
+ * The data field name of each column: its own, or for a reserved name `<name>#<origin id>` (`<name>#2`, `#3`, ...
82
+ * without one, or when that is taken), the rule graph-io follows when two attributes share a name.
83
+ * @param cols - the columns copied into data
84
+ * @param domain - node or edge, for onRename
85
+ * @param onRename - told about each renamed column
86
+ * @returns the field name by column
87
+ */
88
+ function fieldNames(cols, domain, onRename) {
89
+ const taken = new Set([...RESERVED, ...cols.map((c) => c.meta.name)]);
90
+ const out = new Map();
91
+ for (const c of cols) {
92
+ const from = c.meta.name;
93
+ if (!RESERVED.has(from)) {
94
+ out.set(c, from);
95
+ continue;
96
+ }
97
+ const id = c.meta.origin?.id ?? null;
98
+ const base = id === null ? from : `${from}#${id}`;
99
+ let to = base;
100
+ if (id === null || taken.has(base)) {
101
+ let n = 2;
102
+ while (taken.has(`${base}#${n}`)) {
103
+ n++;
104
+ }
105
+ to = `${base}#${n}`;
106
+ }
107
+ taken.add(to);
108
+ out.set(c, to);
109
+ onRename?.({ domain, from, to });
110
+ }
111
+ return out;
112
+ }
113
+ /**
114
+ * One row's set values as data fields.
115
+ * @param cols - the columns to copy
116
+ * @param row - the node or edge index
117
+ * @param fieldOf - the data field a column's value goes to
118
+ * @returns the data, one field per column with a value in this row
119
+ */
120
+ function rowData(cols, row, fieldOf) {
121
+ const data = {};
122
+ for (const c of cols) {
123
+ if (c.isSet(row)) {
124
+ data[fieldOf(c)] = plain(c.value(row));
125
+ }
126
+ }
127
+ return data;
128
+ }
129
+ /**
130
+ * The node elements of snapshotToElements().
131
+ * @param snapshot - the snapshot
132
+ * @param ids - the node ids as strings, by node index
133
+ * @param onRename - told about each renamed column
134
+ * @param keep - whether a column becomes a data field
135
+ * @returns one element per node
136
+ */
137
+ function nodeElements(snapshot, ids, onRename, keep) {
138
+ const nodeCols = [...snapshot.nodes].filter(keep);
139
+ const position = nodeCols.find((c) => c.meta.role === "position" && c.meta.components >= 2);
140
+ const nodeData = nodeCols.filter((c) => c !== position);
141
+ const names = fieldNames(nodeData, "node", onRename);
142
+ const parent = snapshot.nodes.byRole("parent");
143
+ const out = [];
144
+ for (let i = 0; i < snapshot.nodeCount; i++) {
145
+ const data = rowData(nodeData, i, (c) => names.get(c) ?? c.meta.name);
146
+ data.id = ids[i];
147
+ const p = parent?.isSet(i) === true ? parent.value(i) : undefined;
148
+ if (typeof p === "number" && p !== i && p < ids.length) {
149
+ data.parent = ids[p];
150
+ }
151
+ const el = { group: "nodes", data: data };
152
+ const xy = position?.isSet(i) === true ? position.value(i) : undefined;
153
+ if (xy !== undefined && Number.isFinite(xy[0]) && Number.isFinite(xy[1])) {
154
+ el.position = { x: xy[0], y: xy[1] };
155
+ }
156
+ out.push(el);
157
+ }
158
+ return out;
159
+ }
160
+ /**
161
+ * The edge elements of snapshotToElements().
162
+ * @param snapshot - the snapshot
163
+ * @param ids - the node ids as strings, by node index
164
+ * @param onRename - told about each renamed column
165
+ * @param onIdDropped - told about each dropped edge id
166
+ * @param keep - whether a column becomes a data field
167
+ * @returns one element per edge
168
+ */
169
+ function edgeElements(snapshot, ids, onRename, onIdDropped, keep) {
170
+ const edgeCols = [...snapshot.edges].filter(keep);
171
+ const named = edgeCols.some((c) => c.meta.name === "weight");
172
+ const weightColumn = edgeCols.find((c) => c.meta.role === "weight");
173
+ const names = fieldNames(edgeCols, "edge", onRename);
174
+ const fieldOf = (c) => (c === weightColumn && !named ? "weight" : (names.get(c) ?? c.meta.name));
175
+ const edgeIds = snapshot.edges.byRole("id");
176
+ const nodeIds = new Set(ids);
177
+ const usedEdgeIds = new Set();
178
+ const out = [];
179
+ for (let e = 0; e < snapshot.edgeCount; e++) {
180
+ const data = rowData(edgeCols, e, fieldOf);
181
+ if (weightColumn === undefined && !named && snapshot.weights !== null) {
182
+ data.weight = snapshot.weights[snapshot.edgeToArc[e]];
183
+ }
184
+ const id = edgeIds?.isSet(e) === true
185
+ ? claimEdgeId(String(edgeIds.value(e)), nodeIds, usedEdgeIds, onIdDropped)
186
+ : undefined;
187
+ if (id !== undefined) {
188
+ data.id = id;
189
+ }
190
+ data.source = ids[snapshot.edgeSource(e)];
191
+ data.target = ids[snapshot.edgeTarget(e)];
192
+ out.push({ group: "edges", data: data });
193
+ }
194
+ return out;
195
+ }
196
+ /**
197
+ * An edge's own id, unless a node or an earlier edge already has it.
198
+ * @param id - the edge's id in the snapshot
199
+ * @param nodeIds - every node id
200
+ * @param usedEdgeIds - the edge ids handed out so far; the id is added when it is kept
201
+ * @param onIdDropped - told when the id is dropped, and what has it
202
+ * @returns the id, or undefined when it is dropped
203
+ */
204
+ function claimEdgeId(id, nodeIds, usedEdgeIds, onIdDropped) {
205
+ if (nodeIds.has(id) || usedEdgeIds.has(id)) {
206
+ onIdDropped?.(id, nodeIds.has(id) ? "node" : "edge");
207
+ return undefined;
208
+ }
209
+ usedEdgeIds.add(id);
210
+ return id;
211
+ }
212
+ /**
213
+ * A column of data values: f64 when every set value is a number (NaN and the infinities included), bool when every one is a boolean, string
214
+ * when every one is a string, json otherwise. A missing value (undefined or null) is an unset row.
215
+ * @param values - one value per row
216
+ * @param label - whether this is the `label` field: a string one gets the role "label", so a format with a label
217
+ * of its own (GEXF, Pajek, DOT, ...) writes it there and reads it back under the same name
218
+ * @returns the column, or undefined when no row has a value
219
+ */
220
+ function column(values, label) {
221
+ const set = values.filter((v) => v !== undefined && v !== null);
222
+ if (set.length === 0) {
223
+ return undefined;
224
+ }
225
+ const rows = values.map((v) => (v === undefined ? null : v));
226
+ const all = (test) => set.every(test);
227
+ if (all((v) => typeof v === "number")) {
228
+ return { data: rows, decl: { dtype: "f64" } };
229
+ }
230
+ if (all((v) => typeof v === "boolean")) {
231
+ return { data: rows, decl: { dtype: "bool" } };
232
+ }
233
+ if (all((v) => typeof v === "string")) {
234
+ return { data: rows, decl: { dtype: "string", ...(label ? { role: "label" } : {}) } };
235
+ }
236
+ // in a json column null is a set value (JSON null), which a format would write as the text "null"
237
+ return { data: values.map((v) => v ?? undefined), decl: { dtype: "json" } };
238
+ }
239
+ /**
240
+ * The columns of a set of elements' data, one per field, skipping the reserved ones.
241
+ * @param records - each element's data
242
+ * @returns the columns by name
243
+ */
244
+ function columns(records) {
245
+ const names = new Set();
246
+ for (const r of records) {
247
+ for (const k of Object.keys(r)) {
248
+ if (!RESERVED.has(k)) {
249
+ names.add(k);
250
+ }
251
+ }
252
+ }
253
+ const out = {};
254
+ for (const name of names) {
255
+ const c = column(records.map((r) => r[name]), name === "label");
256
+ if (c !== undefined) {
257
+ out[name] = c;
258
+ }
259
+ }
260
+ return out;
261
+ }
262
+ /**
263
+ * The edges of a collection that elementsToSnapshot() writes, in its order: those whose two ends are in it.
264
+ * @param eles - the collection
265
+ * @returns the edges
266
+ */
267
+ export function exportedEdges(eles) {
268
+ const ids = new Set(eles.nodes().map((n) => n.id()));
269
+ return eles.edges().filter((e) => ids.has(e.source().id()) && ids.has(e.target().id()));
270
+ }
271
+ /**
272
+ * A snapshot of a collection with every data field as a column and every node's position as a "position" column
273
+ * (y negated: graph-io's y grows upward), for an exporter. Edges whose endpoints are not both in the collection are left out. A numeric edge field named
274
+ * `weight` becomes the snapshot's edge weights when every edge has one. Edge ids become an "id" column, and a
275
+ * compound node's parent a "parent" column when the parent is in the collection too (a parent outside it is left
276
+ * out, so the node is written as a top-level node). Hidden elements are written like any other: pass
277
+ * `cy.elements(":visible")` to leave them out.
278
+ * @param eles - the collection
279
+ * @param options - the direction and the id type
280
+ * @param options.directed - write a directed graph (default false)
281
+ * @param options.integerIds - when every node id is a non-negative integer written plainly ("0", "17"), give the
282
+ * snapshot number ids, so a format that holds only integer ids (GML, CX2) writes them as they are (default false)
283
+ * @param options.format - the format the snapshot is written in: the positions are spelled as its writer expects
284
+ * them (GML and Pajek draw y downward); without it they are graph-io's neutral form, y up
285
+ * @returns the snapshot
286
+ */
287
+ export function elementsToSnapshot(eles, options = {}) {
288
+ const nodes = eles.nodes();
289
+ const index = new Map();
290
+ const names = nodes.map((n, i) => {
291
+ index.set(n.id(), i);
292
+ return n.id();
293
+ });
294
+ const integers = options.integerIds === true && names.every((id) => /^(?:0|[1-9]\d{0,14})$/.test(id));
295
+ const ids = integers ? names.map(Number) : names;
296
+ const edges = exportedEdges(eles);
297
+ const src = new Uint32Array(edges.length);
298
+ const dst = new Uint32Array(edges.length);
299
+ edges.forEach((e, k) => {
300
+ src[k] = index.get(e.source().id()) ?? 0;
301
+ dst[k] = index.get(e.target().id()) ?? 0;
302
+ });
303
+ const xyz = new Float64Array(nodes.length * 3);
304
+ nodes.forEach((n, i) => {
305
+ const p = n.position();
306
+ xyz[3 * i] = p.x;
307
+ xyz[3 * i + 1] = flipY(p.y);
308
+ });
309
+ // spelled as the format's writer expects its position column (GML and Pajek: y down)
310
+ const written = options.format === undefined ? xyz : writtenPositions(options.format, xyz);
311
+ const xy = new Float64Array(nodes.length * 2);
312
+ for (let i = 0; i < nodes.length; i++) {
313
+ xy[2 * i] = written[3 * i];
314
+ xy[2 * i + 1] = written[3 * i + 1];
315
+ }
316
+ const parents = nodes.map((n) => index.get(n.parent().first().id()) ?? null);
317
+ const edgeColumns = columns(edges.map((e) => e.data()));
318
+ let weights;
319
+ const w = edgeColumns.weight;
320
+ if (w?.decl.dtype === "f64" && w.data.every((v) => v !== null)) {
321
+ weights = Float64Array.from(w.data);
322
+ delete edgeColumns.weight;
323
+ }
324
+ return fromEdgeArrays({
325
+ directed: options.directed ?? false,
326
+ ids,
327
+ src,
328
+ dst,
329
+ weights,
330
+ nodeColumns: {
331
+ ...columns(nodes.map((n) => n.data())),
332
+ position: { data: xy, decl: { dtype: "f64", components: 2, role: "position" } },
333
+ ...(parents.some((p) => p !== null)
334
+ ? { parent: { data: parents, decl: { dtype: "u32", role: "parent", refersTo: "node" } } }
335
+ : {}),
336
+ },
337
+ edgeColumns: {
338
+ ...edgeColumns,
339
+ id: { data: edges.map((e) => e.id()), decl: { dtype: "string", role: "id", unique: true } },
340
+ },
341
+ });
342
+ }
343
+ //# sourceMappingURL=elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiC,cAAc,EAAsB,MAAM,uBAAuB,CAAC;AAC1G,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D;;;;GAIG;AACH,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AAEjG;;;;GAIG;AACH,SAAS,KAAK,CAAC,CAAU;IACrB,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAiC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AASD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAC9B,QAAuB,EACvB,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CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;gBAC/B,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE;gBACzF,CAAC,CAAC,EAAE,CAAC;SACZ;QACD,WAAW,EAAE;YACT,GAAG,WAAW;YACd,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;SAC9F;KACJ,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * What "#gpu-platform" loads in a browser (the package's `imports` field): the provider on `navigator.gpu`.
3
+ */
4
+ import type { GpuProvider, WebGpuOptions } from "./gpu.js";
5
+ /**
6
+ * The browser's provider.
7
+ * @param options - the options
8
+ * @returns the provider
9
+ */
10
+ export declare function gpuProvider(options: WebGpuOptions): GpuProvider;
11
+ //# sourceMappingURL=gpu-platform-browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-platform-browser.d.ts","sourceRoot":"","sources":["../src/gpu-platform-browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG3D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAc/D"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * What "#gpu-platform" loads in a browser (the package's `imports` field): the provider on `navigator.gpu`.
3
+ */
4
+ import { probeBrowserWebGpu, requestGpuContext } from "@graphty/webgpu-graph-algorithms/browser";
5
+ import { providerFor } from "./webgpu-provider.js";
6
+ /**
7
+ * The browser's provider.
8
+ * @param options - the options
9
+ * @returns the provider
10
+ */
11
+ export function gpuProvider(options) {
12
+ return providerFor({
13
+ probe: (rejectSoftware) => probeBrowserWebGpu({ rejectSoftware }),
14
+ open: (probe, rejectSoftware, residentSnapshots) => requestGpuContext({
15
+ adapter: probe.adapter ?? undefined,
16
+ rejectSoftware,
17
+ warnUnreleasedSnapshots: residentSnapshots,
18
+ }),
19
+ fixes: {},
20
+ }, options);
21
+ }
22
+ //# sourceMappingURL=gpu-platform-browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-platform-browser.js","sourceRoot":"","sources":["../src/gpu-platform-browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAGjG,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAAsB;IAC9C,OAAO,WAAW,CACd;QACI,KAAK,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAC;QACjE,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,EAAE,CAC/C,iBAAiB,CAAC;YACd,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,SAAS;YACnC,cAAc;YACd,uBAAuB,EAAE,iBAAiB;SAC7C,CAAC;QACN,KAAK,EAAE,EAAE;KACZ,EACD,OAAO,CACV,CAAC;AACN,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What "#gpu-platform" loads under Node (the package's `imports` field): the provider on Dawn. The GPU package loads
3
+ * the optional `webgpu` package at run time; without it the probe declines and every run is on the CPU, saying why.
4
+ */
5
+ import type { GpuProvider, WebGpuOptions } from "./gpu.js";
6
+ import { type Platform } from "./webgpu-provider.js";
7
+ /** What a Node user can do about a refusal. */
8
+ export declare const NODE_FIXES: Platform["fixes"];
9
+ /**
10
+ * The Node provider.
11
+ * @param options - the options; `adapter` picks the Dawn adapter by name
12
+ * @returns the provider
13
+ */
14
+ export declare function gpuProvider(options: WebGpuOptions): GpuProvider;
15
+ //# sourceMappingURL=gpu-platform-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-platform-node.d.ts","sourceRoot":"","sources":["../src/gpu-platform-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,sBAAsB,CAAC;AAElE,+CAA+C;AAC/C,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,OAAO,CAExC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAc/D"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * What "#gpu-platform" loads under Node (the package's `imports` field): the provider on Dawn. The GPU package loads
3
+ * the optional `webgpu` package at run time; without it the probe declines and every run is on the CPU, saying why.
4
+ */
5
+ import { createNodeGpuContext, probeNodeWebGpu } from "@graphty/webgpu-graph-algorithms/node";
6
+ import { providerFor } from "./webgpu-provider.js";
7
+ /** What a Node user can do about a refusal. */
8
+ export const NODE_FIXES = {
9
+ E_NO_WEBGPU: "install the optional webgpu package (npm install webgpu), which brings Dawn to Node",
10
+ };
11
+ /**
12
+ * The Node provider.
13
+ * @param options - the options; `adapter` picks the Dawn adapter by name
14
+ * @returns the provider
15
+ */
16
+ export function gpuProvider(options) {
17
+ return providerFor({
18
+ probe: (rejectSoftware) => probeNodeWebGpu({ adapter: options.adapter, rejectSoftware }),
19
+ open: (_probe, rejectSoftware, residentSnapshots) => createNodeGpuContext({
20
+ adapter: options.adapter,
21
+ rejectSoftware,
22
+ warnUnreleasedSnapshots: residentSnapshots,
23
+ }),
24
+ fixes: NODE_FIXES,
25
+ }, options);
26
+ }
27
+ //# sourceMappingURL=gpu-platform-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-platform-node.js","sourceRoot":"","sources":["../src/gpu-platform-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAG9F,OAAO,EAAiB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAElE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAsB;IACzC,WAAW,EAAE,qFAAqF;CACrG,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAAsB;IAC9C,OAAO,WAAW,CACd;QACI,KAAK,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC;QACxF,IAAI,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,EAAE,CAChD,oBAAoB,CAAC;YACjB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,cAAc;YACd,uBAAuB,EAAE,iBAAiB;SAC7C,CAAC;QACN,KAAK,EAAE,UAAU;KACpB,EACD,OAAO,CACV,CAAC;AACN,CAAC"}