@graphty/cytoscape-extensions 0.0.28 → 0.0.30

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-DIunzJUl.js +1 -0
  10. package/dist/cdn/chunks/gpu-platform-browser-DnQwf3s0.js +2825 -0
  11. package/dist/cdn/chunks/index-C-jUF_Ve.js +1 -0
  12. package/dist/cdn/chunks/index-C4RZkds_.js +10 -0
  13. package/dist/cdn/chunks/io-D-Vr0j3W.js +269 -0
  14. package/dist/cdn/chunks/preload-helper-Crt_PPe8.js +1 -0
  15. package/dist/cdn/chunks/samples-Dja23zzq.js +1 -0
  16. package/dist/cdn/chunks/sigv4-BXwVbza3-DZCCNyQA.js +3 -0
  17. package/dist/cdn/chunks/sources-cypher-oj3S6pKb.js +5 -0
  18. package/dist/cdn/chunks/sources-ndex-BgZhxHsL.js +1 -0
  19. package/dist/cdn/chunks/sources-rest-E6On5P3z.js +1 -0
  20. package/dist/cdn/chunks/sources-sparql-BAxh1dw-.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 @@
1
+ {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qFAAqF;AACrF,eAAO,MAAM,QAAQ,OAAO,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAatE"}
package/dist/lazy.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Loading the parts of the package that are fetched on first use (the generators and datasets, the file formats, the
3
+ * WebGPU code), with a warning when one never arrives.
4
+ */
5
+ /** How long a part may take to load before the call warns that it may never load. */
6
+ export const STALL_MS = 5000;
7
+ /**
8
+ * A part of the package loaded on first use, warning on the console when it has not loaded after STALL_MS.
9
+ *
10
+ * In a Vite 6 or 7 (Rollup) production build, the part's chunk imports the chunk that holds the consumer's entry
11
+ * module, because both use @graphty/graph-format and Rollup puts shared code in the chunk that loads first. When that
12
+ * entry module awaits the call at its top level, the entry chunk is still evaluating, so the part can never run and
13
+ * the await never settles. ES modules report nothing, and no package layout avoids it (the package's synchronous
14
+ * methods need @graphty/graph-format up front), so the warning names the cause. A slow network shows it too; the
15
+ * call then carries on.
16
+ * @param load - the dynamic import
17
+ * @param call - what is waiting, as the reader wrote it ("graphtyDataset")
18
+ * @returns the import
19
+ */
20
+ export function loadPart(load, call) {
21
+ const timer = setTimeout(() => {
22
+ console.warn(`graphty: ${call} has waited ${String(STALL_MS / 1000)} s for part of @graphty/cytoscape-extensions to load. ` +
23
+ `If a module awaits ${call} at its top level, a Vite 6 or 7 production build never loads it: call it ` +
24
+ "inside an async function, or with .then(), instead. On a slow network the call carries on.");
25
+ }, STALL_MS);
26
+ const clear = () => {
27
+ clearTimeout(timer);
28
+ };
29
+ load.then(clear, clear);
30
+ return load;
31
+ }
32
+ //# sourceMappingURL=lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qFAAqF;AACrF,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAI,IAAgB,EAAE,IAAY;IACtD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;QAC1B,OAAO,CAAC,IAAI,CACR,YAAY,IAAI,eAAe,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,wDAAwD;YAC1G,sBAAsB,IAAI,4EAA4E;YACtG,4FAA4F,CACnG,CAAC;IACN,CAAC,EAAE,QAAQ,CAAC,CAAC;IACb,MAAM,KAAK,GAAG,GAAS,EAAE;QACrB,YAAY,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,CAAC;IACF,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * `@graphty/cytoscape-extensions/samples`: the seeded generators and the sample datasets of @graphty/graph-samples
3
+ * as Cytoscape elements. cy.graphtyGenerate() and cy.graphtyDataset() load this module on their first call; every
4
+ * dataset downloads from graphty.app when it is asked for (no dataset's data ships in the package).
5
+ */
6
+ import { type FetchDatasetOptions, type SampleGraph } from "@graphty/graph-samples";
7
+ import * as g from "@graphty/graph-samples/generators";
8
+ import type { ElementDefinition } from "cytoscape";
9
+ /**
10
+ * Every generator by its name: the graph-samples function name in kebab case without "Graph". Each takes that
11
+ * function's options; the random ones take `seed` (default 0) and give the same graph for the same options on
12
+ * every platform.
13
+ */
14
+ export declare const GENERATORS: {
15
+ readonly ak: typeof g.akGraph;
16
+ readonly "balanced-tree": typeof g.balancedTreeGraph;
17
+ readonly "barabasi-albert": typeof g.barabasiAlbertGraph;
18
+ readonly barbell: typeof g.barbellGraph;
19
+ readonly "bianconi-barabasi": typeof g.bianconiBarabasiGraph;
20
+ readonly "bipartite-configuration-model": typeof g.bipartiteConfigurationModelGraph;
21
+ readonly caveman: typeof g.cavemanGraph;
22
+ readonly "chung-lu": typeof g.chungLuGraph;
23
+ readonly "circular-ladder": typeof g.circularLadderGraph;
24
+ readonly complete: typeof g.completeGraph;
25
+ readonly "complete-bipartite": typeof g.completeBipartiteGraph;
26
+ readonly "complete-multipartite": typeof g.completeMultipartiteGraph;
27
+ readonly "configuration-model": typeof g.configurationModelGraph;
28
+ readonly "connected-caveman": typeof g.connectedCavemanGraph;
29
+ readonly cycle: typeof g.cycleGraph;
30
+ readonly "degree-corrected-sbm": typeof g.degreeCorrectedSbmGraph;
31
+ readonly "directed-configuration-model": typeof g.directedConfigurationModelGraph;
32
+ readonly "duplication-divergence": typeof g.duplicationDivergenceGraph;
33
+ readonly empty: typeof g.emptyGraph;
34
+ readonly "erdos-renyi": typeof g.erdosRenyiGraph;
35
+ readonly "erdos-renyi-gnm": typeof g.erdosRenyiGnmGraph;
36
+ readonly "forest-fire": typeof g.forestFireGraph;
37
+ readonly genrmf: typeof g.genrmfGraph;
38
+ readonly grid: typeof g.gridGraph;
39
+ readonly "grid-3d": typeof g.grid3dGraph;
40
+ readonly "grid-flow-network": typeof g.gridFlowNetwork;
41
+ readonly "hexagonal-lattice": typeof g.hexagonalLatticeGraph;
42
+ readonly hyperbolic: typeof g.hyperbolicGraph;
43
+ readonly hypercube: typeof g.hypercubeGraph;
44
+ readonly knn: typeof g.knnGraph;
45
+ readonly kronecker: typeof g.kroneckerGraph;
46
+ readonly ladder: typeof g.ladderGraph;
47
+ readonly "layered-flow-network": typeof g.layeredFlowNetwork;
48
+ readonly lfr: typeof g.lfrGraph;
49
+ readonly lollipop: typeof g.lollipopGraph;
50
+ readonly "mobius-ladder": typeof g.mobiusLadderGraph;
51
+ readonly named: (o: {
52
+ name: g.NamedGraphName;
53
+ } & g.WeightOptions) => SampleGraph;
54
+ readonly "newman-watts": typeof g.newmanWattsGraph;
55
+ readonly path: typeof g.pathGraph;
56
+ readonly petersen: typeof g.petersenGraph;
57
+ readonly "planted-partition": typeof g.plantedPartitionGraph;
58
+ readonly price: typeof g.priceGraph;
59
+ readonly "random-apollonian": typeof g.randomApollonianGraph;
60
+ readonly "random-bipartite": typeof g.randomBipartiteGraph;
61
+ readonly "random-dag": typeof g.randomDagGraph;
62
+ readonly "random-geometric": typeof g.randomGeometricGraph;
63
+ readonly "random-order-dag": typeof g.randomOrderDagGraph;
64
+ readonly "random-recursive-tree": typeof g.randomRecursiveTreeGraph;
65
+ readonly "random-regular": typeof g.randomRegularGraph;
66
+ readonly "random-tree": typeof g.randomTreeGraph;
67
+ readonly "ring-of-cliques": typeof g.ringOfCliquesGraph;
68
+ readonly rmat: typeof g.rmatGraph;
69
+ readonly star: typeof g.starGraph;
70
+ readonly "stochastic-block-model": typeof g.stochasticBlockModelGraph;
71
+ readonly "triangular-lattice": typeof g.triangularLatticeGraph;
72
+ readonly "watts-strogatz": typeof g.wattsStrogatzGraph;
73
+ readonly waxman: typeof g.waxmanGraph;
74
+ readonly wheel: typeof g.wheelGraph;
75
+ readonly "wilson-maze": typeof g.wilsonMazeGraph;
76
+ };
77
+ /** A generator name. */
78
+ export type GeneratorName = keyof typeof GENERATORS;
79
+ /** The graphs the "named" generator knows, for `graphtyGenerate("named", { name })`. */
80
+ export { NAMED_GRAPH_NAMES } from "@graphty/graph-samples/generators";
81
+ /** The options of a generator. */
82
+ export type GeneratorOptions<N extends GeneratorName> = Parameters<(typeof GENERATORS)[N]>[0];
83
+ /**
84
+ * The small datasets, which the package used to bundle. Every dataset now downloads from graphty.app like the rest.
85
+ * @deprecated every dataset is downloaded; graph-samples' `DATASET_NAMES` lists them all
86
+ */
87
+ export declare const BUNDLED_DATASET_NAMES: readonly string[];
88
+ /** A generated graph or a dataset as Cytoscape element definitions. */
89
+ export interface SampleElements {
90
+ /** The nodes, then the edges. Node ids are the dataset's names, or "0", "1", ... for a generated graph. */
91
+ readonly elements: ElementDefinition[];
92
+ /** Whether the graph is directed: pass it as `directed` to the algorithms. */
93
+ readonly directed: boolean;
94
+ }
95
+ /**
96
+ * Generates a graph. Ground-truth columns (`community`, `side`, `layer`, ...) become node data fields; weights
97
+ * become `data.weight`; coordinates (`x` and `y`) become node positions. Edge k gets the id "e<k>", so the same
98
+ * options and seed give the same element ids as well as the same graph.
99
+ * @param name - the generator
100
+ * @param options - the generator's options
101
+ * @returns the elements and the direction
102
+ * @throws RangeError for an unknown generator name, or an option the generator does not take
103
+ */
104
+ export declare function generateElements<N extends GeneratorName>(name: N, options: GeneratorOptions<N>): SampleElements;
105
+ /**
106
+ * Loads a sample dataset from graphty.app (see graph-samples' `DATASETS` for the list, with each one's source,
107
+ * citation and license). A drawn dataset's saved `x` and `y` become node positions, placed where Cytoscape drew them.
108
+ * @param name - the dataset name, e.g. "karate"
109
+ * @param options - the base URL (a mirror of your own), the fetch implementation and an abort signal
110
+ * @returns the elements and the direction
111
+ * @throws the signal's reason (an AbortError) when it is aborted before the dataset is decoded
112
+ * @throws RangeError for a name that is not a known dataset, unless `baseUrl` is given
113
+ */
114
+ export declare function datasetElements(name: string, options?: FetchDatasetOptions): Promise<SampleElements>;
115
+ //# sourceMappingURL=samples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"samples.d.ts","sourceRoot":"","sources":["../src/samples.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAA+B,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjH,OAAO,KAAK,CAAC,MAAM,mCAAmC,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAKnD;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqCR;QAAE,IAAI,EAAE,CAAC,CAAC,cAAc,CAAA;KAAE,GAAG,CAAC,CAAC,aAAa;;;;;;;;;;;;;;;;;;;;;;;CA6BjD,CAAC;AAEX,wBAAwB;AACxB,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,UAAU,CAAC;AAEpD,wFAAwF;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,kCAAkC;AAClC,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,aAAa,IAAI,UAAU,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9F;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAiBlD,CAAC;AAyCF,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC3B,2GAA2G;IAC3G,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC9B;AAoCD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,cAAc,CAuB/G;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC,CAoB9G"}
@@ -0,0 +1,237 @@
1
+ /**
2
+ * `@graphty/cytoscape-extensions/samples`: the seeded generators and the sample datasets of @graphty/graph-samples
3
+ * as Cytoscape elements. cy.graphtyGenerate() and cy.graphtyDataset() load this module on their first call; every
4
+ * dataset downloads from graphty.app when it is asked for (no dataset's data ships in the package).
5
+ */
6
+ import { fromEdgeArrays } from "@graphty/graph-format";
7
+ import { DATASET_NAMES, fetchDataset } from "@graphty/graph-samples";
8
+ import * as g from "@graphty/graph-samples/generators";
9
+ import { GENERATOR_OPTION_NAMES } from "./algorithm-options.js";
10
+ import { flipY, snapshotToElements } from "./elements.js";
11
+ /**
12
+ * Every generator by its name: the graph-samples function name in kebab case without "Graph". Each takes that
13
+ * function's options; the random ones take `seed` (default 0) and give the same graph for the same options on
14
+ * every platform.
15
+ */
16
+ export const GENERATORS = {
17
+ ak: g.akGraph,
18
+ "balanced-tree": g.balancedTreeGraph,
19
+ "barabasi-albert": g.barabasiAlbertGraph,
20
+ barbell: g.barbellGraph,
21
+ "bianconi-barabasi": g.bianconiBarabasiGraph,
22
+ "bipartite-configuration-model": g.bipartiteConfigurationModelGraph,
23
+ caveman: g.cavemanGraph,
24
+ "chung-lu": g.chungLuGraph,
25
+ "circular-ladder": g.circularLadderGraph,
26
+ complete: g.completeGraph,
27
+ "complete-bipartite": g.completeBipartiteGraph,
28
+ "complete-multipartite": g.completeMultipartiteGraph,
29
+ "configuration-model": g.configurationModelGraph,
30
+ "connected-caveman": g.connectedCavemanGraph,
31
+ cycle: g.cycleGraph,
32
+ "degree-corrected-sbm": g.degreeCorrectedSbmGraph,
33
+ "directed-configuration-model": g.directedConfigurationModelGraph,
34
+ "duplication-divergence": g.duplicationDivergenceGraph,
35
+ empty: g.emptyGraph,
36
+ "erdos-renyi": g.erdosRenyiGraph,
37
+ "erdos-renyi-gnm": g.erdosRenyiGnmGraph,
38
+ "forest-fire": g.forestFireGraph,
39
+ genrmf: g.genrmfGraph,
40
+ grid: g.gridGraph,
41
+ "grid-3d": g.grid3dGraph,
42
+ "grid-flow-network": g.gridFlowNetwork,
43
+ "hexagonal-lattice": g.hexagonalLatticeGraph,
44
+ hyperbolic: g.hyperbolicGraph,
45
+ hypercube: g.hypercubeGraph,
46
+ knn: g.knnGraph,
47
+ kronecker: g.kroneckerGraph,
48
+ ladder: g.ladderGraph,
49
+ "layered-flow-network": g.layeredFlowNetwork,
50
+ lfr: g.lfrGraph,
51
+ lollipop: g.lollipopGraph,
52
+ "mobius-ladder": g.mobiusLadderGraph,
53
+ named: (o) => {
54
+ // checked here: graph-samples' own error points at a list this package's readers cannot see
55
+ if (!g.NAMED_GRAPH_NAMES.includes(o.name)) {
56
+ throw unknownName("named graph", o.name, g.NAMED_GRAPH_NAMES);
57
+ }
58
+ return g.namedGraph(o.name, o);
59
+ },
60
+ "newman-watts": g.newmanWattsGraph,
61
+ path: g.pathGraph,
62
+ petersen: g.petersenGraph,
63
+ "planted-partition": g.plantedPartitionGraph,
64
+ price: g.priceGraph,
65
+ "random-apollonian": g.randomApollonianGraph,
66
+ "random-bipartite": g.randomBipartiteGraph,
67
+ "random-dag": g.randomDagGraph,
68
+ "random-geometric": g.randomGeometricGraph,
69
+ "random-order-dag": g.randomOrderDagGraph,
70
+ "random-recursive-tree": g.randomRecursiveTreeGraph,
71
+ "random-regular": g.randomRegularGraph,
72
+ "random-tree": g.randomTreeGraph,
73
+ "ring-of-cliques": g.ringOfCliquesGraph,
74
+ rmat: g.rmatGraph,
75
+ star: g.starGraph,
76
+ "stochastic-block-model": g.stochasticBlockModelGraph,
77
+ "triangular-lattice": g.triangularLatticeGraph,
78
+ "watts-strogatz": g.wattsStrogatzGraph,
79
+ waxman: g.waxmanGraph,
80
+ wheel: g.wheelGraph,
81
+ "wilson-maze": g.wilsonMazeGraph,
82
+ };
83
+ /** The graphs the "named" generator knows, for `graphtyGenerate("named", { name })`. */
84
+ export { NAMED_GRAPH_NAMES } from "@graphty/graph-samples/generators";
85
+ /**
86
+ * The small datasets, which the package used to bundle. Every dataset now downloads from graphty.app like the rest.
87
+ * @deprecated every dataset is downloaded; graph-samples' `DATASET_NAMES` lists them all
88
+ */
89
+ export const BUNDLED_DATASET_NAMES = [
90
+ "karate",
91
+ "florentine-families",
92
+ "davis-southern-women",
93
+ "les-miserables",
94
+ "football",
95
+ "political-books",
96
+ "dolphins",
97
+ "contiguous-usa",
98
+ "knuth-miles",
99
+ "celegans-neural",
100
+ "political-blogs",
101
+ "openflights",
102
+ "yeast-perturbation",
103
+ "stelzl-interactome",
104
+ "wikipathways-senescence-autophagy",
105
+ "go-slim-generic",
106
+ ];
107
+ /**
108
+ * The number of single-character edits that turn one string into the other.
109
+ * @param a - one string
110
+ * @param b - the other
111
+ * @returns the Levenshtein distance
112
+ */
113
+ function editDistance(a, b) {
114
+ let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
115
+ for (let i = 1; i <= a.length; i++) {
116
+ const row = [i];
117
+ for (let j = 1; j <= b.length; j++) {
118
+ row[j] = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
119
+ }
120
+ prev = row;
121
+ }
122
+ return prev[b.length];
123
+ }
124
+ /**
125
+ * The error for an unknown name, naming the closest known one when one is close and listing them all.
126
+ * @param kind - what the name names ("dataset", "generator", "named graph")
127
+ * @param name - the unknown name
128
+ * @param names - the known names
129
+ * @returns a RangeError
130
+ */
131
+ function unknownName(kind, name, names) {
132
+ let best = "";
133
+ let bestDistance = Infinity;
134
+ for (const known of names) {
135
+ const d = editDistance(name, known);
136
+ if (d < bestDistance) {
137
+ best = known;
138
+ bestDistance = d;
139
+ }
140
+ }
141
+ const hint = bestDistance <= Math.max(2, name.length / 3) ? ` (did you mean ${JSON.stringify(best)}?)` : "";
142
+ return new RangeError(`unknown ${kind} ${JSON.stringify(name)}${hint}; the ${kind}s are ${names.join(", ")}`);
143
+ }
144
+ /**
145
+ * The elements of a graph-samples graph.
146
+ * @param graph - the graph
147
+ * @returns the elements and the direction
148
+ */
149
+ function fromSample(graph) {
150
+ const snapshot = "src" in graph ? fromEdgeArrays(graph) : graph;
151
+ return { elements: snapshotToElements(snapshot), directed: snapshot.directed };
152
+ }
153
+ /**
154
+ * A generated graph with its coordinate columns `x` and `y` (the lattices with `positions: true`, and the geometric
155
+ * generators) as one position column, so they become node positions; `z` stays a data field.
156
+ * @param graph - the generated graph
157
+ * @returns the graph, its x and y as a position
158
+ */
159
+ function withPosition(graph) {
160
+ const { x, y, ...rest } = graph.nodeColumns ?? {};
161
+ if (!ArrayBuffer.isView(x) || !ArrayBuffer.isView(y)) {
162
+ return graph;
163
+ }
164
+ const xs = x;
165
+ const ys = y;
166
+ const xy = new Float64Array(2 * graph.nodeCount);
167
+ for (let i = 0; i < graph.nodeCount; i++) {
168
+ xy[2 * i] = xs[i];
169
+ xy[2 * i + 1] = ys[i];
170
+ }
171
+ return {
172
+ ...graph,
173
+ nodeColumns: { ...rest, position: { data: xy, decl: { dtype: "f64", components: 2, role: "position" } } },
174
+ };
175
+ }
176
+ /**
177
+ * Generates a graph. Ground-truth columns (`community`, `side`, `layer`, ...) become node data fields; weights
178
+ * become `data.weight`; coordinates (`x` and `y`) become node positions. Edge k gets the id "e<k>", so the same
179
+ * options and seed give the same element ids as well as the same graph.
180
+ * @param name - the generator
181
+ * @param options - the generator's options
182
+ * @returns the elements and the direction
183
+ * @throws RangeError for an unknown generator name, or an option the generator does not take
184
+ */
185
+ export function generateElements(name, options) {
186
+ const make = GENERATORS[name];
187
+ if (make === undefined) {
188
+ throw unknownName("generator", name, Object.keys(GENERATORS));
189
+ }
190
+ // a misspelled option (seeed, position) would otherwise run with the default and give a plausible graph
191
+ const known = GENERATOR_OPTION_NAMES[name] ?? [];
192
+ for (const [k, v] of Object.entries(options ?? {})) {
193
+ if (v !== undefined && !known.includes(k)) {
194
+ throw new RangeError(`generator ${JSON.stringify(name)}: unknown option ${k}; the options are ${known.join(", ")}`);
195
+ }
196
+ }
197
+ const r = fromSample(withPosition(make(options)));
198
+ let k = 0;
199
+ for (const el of r.elements) {
200
+ // node ids are "0", "1", ..., so "e<k>" never collides with one
201
+ if (el.group === "edges") {
202
+ el.data.id = `e${String(k++)}`;
203
+ }
204
+ }
205
+ return r;
206
+ }
207
+ /**
208
+ * Loads a sample dataset from graphty.app (see graph-samples' `DATASETS` for the list, with each one's source,
209
+ * citation and license). A drawn dataset's saved `x` and `y` become node positions, placed where Cytoscape drew them.
210
+ * @param name - the dataset name, e.g. "karate"
211
+ * @param options - the base URL (a mirror of your own), the fetch implementation and an abort signal
212
+ * @returns the elements and the direction
213
+ * @throws the signal's reason (an AbortError) when it is aborted before the dataset is decoded
214
+ * @throws RangeError for a name that is not a known dataset, unless `baseUrl` is given
215
+ */
216
+ export async function datasetElements(name, options = {}) {
217
+ // checked here too, not only by fetch: a custom fetch may ignore the signal
218
+ options.signal?.throwIfAborted();
219
+ // only graphty.app's own list is checked: a custom baseUrl may serve any name
220
+ if (options.baseUrl === undefined && !DATASET_NAMES.includes(name)) {
221
+ throw unknownName("dataset", name, DATASET_NAMES);
222
+ }
223
+ const graph = await fetchDataset(name, options);
224
+ options.signal?.throwIfAborted();
225
+ const r = fromSample(graph);
226
+ // a drawn dataset's saved x and y (y growing upward) become the position Cytoscape drew (y growing downward)
227
+ for (const el of r.elements) {
228
+ const { x, y } = el.data;
229
+ if (typeof x === "number" && typeof y === "number") {
230
+ el.position = { x, y: flipY(y) };
231
+ delete el.data.x;
232
+ delete el.data.y;
233
+ }
234
+ }
235
+ return r;
236
+ }
237
+ //# sourceMappingURL=samples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"samples.js","sourceRoot":"","sources":["../src/samples.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAsB,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,YAAY,EAA8C,MAAM,wBAAwB,CAAC;AACjH,OAAO,KAAK,CAAC,MAAM,mCAAmC,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,EAAE,EAAE,CAAC,CAAC,OAAO;IACb,eAAe,EAAE,CAAC,CAAC,iBAAiB;IACpC,iBAAiB,EAAE,CAAC,CAAC,mBAAmB;IACxC,OAAO,EAAE,CAAC,CAAC,YAAY;IACvB,mBAAmB,EAAE,CAAC,CAAC,qBAAqB;IAC5C,+BAA+B,EAAE,CAAC,CAAC,gCAAgC;IACnE,OAAO,EAAE,CAAC,CAAC,YAAY;IACvB,UAAU,EAAE,CAAC,CAAC,YAAY;IAC1B,iBAAiB,EAAE,CAAC,CAAC,mBAAmB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AAC;QACzB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YACjD,EAAE,CAAC,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;YACjB,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IACD,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Conversion between Cytoscape elements and the graph-format snapshot every graphty layout and algorithm takes.
3
+ *
4
+ * A snapshot addresses nodes and edges by dense index. Here node index i is `nodes[i]` and edge index e is
5
+ * `edges[e]`, in the collection order Cytoscape gave, so a result array maps back to elements by position.
6
+ */
7
+ import { type GraphSnapshot } from "@graphty/graph-format";
8
+ import type { Collection, Core, EdgeCollection, EdgeSingular, NodeCollection } from "cytoscape";
9
+ /** How to read a Cytoscape collection as a graph. */
10
+ export interface SnapshotOptions {
11
+ /** Build a directed snapshot. Default false. */
12
+ readonly directed?: boolean | undefined;
13
+ /**
14
+ * The edge weight: an edge data field (a missing or non-numeric value counts as 1), or a function of the edge
15
+ * as Cytoscape's built-in algorithms take it. Default: unweighted. A function result is not cached.
16
+ */
17
+ readonly weight?: string | ((edge: EdgeSingular) => number) | undefined;
18
+ }
19
+ /** A node set given the Cytoscape way: a selector over the collection's nodes, or a collection. */
20
+ export type NodeSelection = string | Collection | NodeCollection;
21
+ /** A snapshot of a Cytoscape collection plus the element arrays its indices refer to. */
22
+ export interface CytoscapeSnapshot {
23
+ readonly snapshot: GraphSnapshot;
24
+ /** Node index i is `nodes[i]`. */
25
+ readonly nodes: NodeCollection;
26
+ /** Edge index e is `edges[e]`: the collection's edges whose two endpoints are both in `nodes`. */
27
+ readonly edges: EdgeCollection;
28
+ }
29
+ /**
30
+ * The core of a collection. Every collection has `cy()` at run time; Cytoscape's typings declare it only on single
31
+ * elements.
32
+ * @param eles - the collection
33
+ * @returns its core
34
+ */
35
+ export declare function coreOf(eles: Collection | NodeCollection | EdgeCollection): Core;
36
+ /**
37
+ * Keeps a snapshot from being released while a run uses it: when the cache drops it (a data change, say) during
38
+ * the run, its release waits until every hold on it is let go.
39
+ * @param s - the snapshot
40
+ * @returns lets go of the hold; calling it again does nothing
41
+ */
42
+ export declare function hold(s: GraphSnapshot): () => void;
43
+ /**
44
+ * Subscribes to the snapshots a core's cache lets go of.
45
+ * @param cy - the core
46
+ * @param listener - called with the dropped snapshots
47
+ * @returns the unsubscriber
48
+ */
49
+ export declare function onSnapshotsDropped(cy: Core, listener: (dropped: readonly GraphSnapshot[]) => void): () => void;
50
+ /**
51
+ * Builds (or returns the cached) snapshot of a collection. The cache holds one snapshot per option set per core and
52
+ * is dropped when an element is added, removed, moved to other endpoints, or has its data changed.
53
+ * @param eles - the collection to read: its nodes, and its edges whose endpoints are both in it
54
+ * @param options - directed flag and weight field
55
+ * @returns the snapshot and the element arrays its indices refer to
56
+ */
57
+ export declare function toSnapshot(eles: Collection | NodeCollection | EdgeCollection, options?: SnapshotOptions): CytoscapeSnapshot;
58
+ /**
59
+ * Writes one value per element into its data, in one batch (one style pass).
60
+ * @param elements - `nodes` or `edges` of a CytoscapeSnapshot, in index order
61
+ * @param values - one value per element
62
+ * @param field - the data field to write
63
+ */
64
+ export declare function writeData(elements: NodeCollection | EdgeCollection, values: ArrayLike<number>, field: string): void;
65
+ /**
66
+ * Indices of the snapshot's nodes in a selection.
67
+ * @param cs - the snapshot
68
+ * @param sel - a selector or a collection
69
+ * @returns the node indices, in collection order
70
+ */
71
+ export declare function indicesOf(cs: CytoscapeSnapshot, sel: NodeSelection): number[];
72
+ /**
73
+ * The index of the first node of a selection.
74
+ * @param cs - the snapshot
75
+ * @param sel - a selector or a collection, or undefined
76
+ * @param what - the option name, for the error
77
+ * @returns the index, or undefined when no selection was given
78
+ * @throws Error when the selection matches no node of the snapshot
79
+ */
80
+ export declare function indexOf(cs: CytoscapeSnapshot, sel: NodeSelection | undefined, what: string): number | undefined;
81
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhG,qDAAqD;AACrD,MAAM,WAAW,eAAe;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,YAAY,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAC3E;AAED,mGAAmG;AACnG,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,cAAc,CAAC;AAEjE,yFAAyF;AACzF,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;CAClC;AAsBD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,GAAG,cAAc,GAAG,IAAI,CAE/E;AAsDD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,IAAI,CAoBjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE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