@graphty/cytoscape-extensions 0.0.13 → 0.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphty/cytoscape-extensions",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Graphty layouts, algorithms, graph generators, sample datasets and file import/export as Cytoscape.js extensions",
5
5
  "author": "Adam Powers <apowers@ato.ms>",
6
6
  "type": "module",
@@ -71,9 +71,9 @@
71
71
  },
72
72
  "homepage": "https://github.com/graphty-org/graphty-monorepo/tree/master/cytoscape-extensions#readme",
73
73
  "dependencies": {
74
- "@graphty/graph-io": "^0.3.36",
75
- "@graphty/graph-samples": "^0.1.28",
76
- "@graphty/webgpu-graph-algorithms": "^0.6.48"
74
+ "@graphty/graph-io": "^0.3.38",
75
+ "@graphty/webgpu-graph-algorithms": "^0.6.50",
76
+ "@graphty/graph-samples": "^0.1.30"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@graphty/algorithms": "^3.0.0",
@@ -102,9 +102,9 @@
102
102
  "typescript": "^5.9.3",
103
103
  "vite": "^7.0.5",
104
104
  "vitest": "4.1.11",
105
- "@graphty/graph-format": "^1.3.13",
106
- "@graphty/algorithms": "^3.4.3",
107
- "@graphty/layout": "^2.4.3"
105
+ "@graphty/graph-format": "^1.3.15",
106
+ "@graphty/algorithms": "^3.4.5",
107
+ "@graphty/layout": "^2.4.5"
108
108
  },
109
109
  "scripts": {
110
110
  "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && vite build --config vite.bundle.config.ts --mode cdn --logLevel warn && vite build --config vite.bundle.config.ts --logLevel warn",
package/src/algorithms.ts CHANGED
@@ -1543,7 +1543,11 @@ const IMPLS = {
1543
1543
  hierarchicalClustering: (
1544
1544
  c: Ctx,
1545
1545
  _o: AlgorithmOptions & HierarchicalOptions = {},
1546
- ): { cut(height: number): Partition; readonly merges: number } => {
1546
+ ): {
1547
+ cut(height: number): Partition;
1548
+ cutAt(by: { readonly clusters: number } | { readonly distance: number }): Partition;
1549
+ readonly merges: number;
1550
+ } => {
1547
1551
  const r = hierarchicalClustering(c.s, c.rest);
1548
1552
  const quiet: Ctx = { ...c, field: undefined };
1549
1553
  const cut = (h: number): Partition => {
@@ -1555,7 +1559,9 @@ const IMPLS = {
1555
1559
  });
1556
1560
  return partition(quiet, labels, {});
1557
1561
  };
1558
- return { merges: r.left.length, cut };
1562
+ const cutAt = (by: { readonly clusters: number } | { readonly distance: number }): Partition =>
1563
+ partition(quiet, r.cutAt(by).labels, {});
1564
+ return { merges: r.left.length, cut, cutAt };
1559
1565
  },
1560
1566
  teraHAC: (c: Ctx, _o: AlgorithmOptions & TeraHacOptions = {}): Partition<{ merges: number }> => {
1561
1567
  const r = teraHAC(c.s, c.rest);
@@ -1892,11 +1898,7 @@ async function runAsync(eles: Collection, key: keyof Impls, options: AlgorithmOp
1892
1898
  d.gpu.accelerator.release(snapshot);
1893
1899
  }
1894
1900
  }
1895
- const backend = backendOf(
1896
- d,
1897
- rec?.used() ?? false,
1898
- "the options or the graph need the CPU implementation (the @graphty/algorithms dispatcher does not say which)",
1899
- );
1901
+ const backend = backendOf(d, rec?.used() ?? false, "the options or the graph need the CPU implementation");
1900
1902
  return Object.assign(value, { backend });
1901
1903
  }
1902
1904
 
package/src/io.ts CHANGED
@@ -143,10 +143,21 @@ export async function importElements(
143
143
  return { elements, directed: r.snapshot.directed, format: r.format, report };
144
144
  }
145
145
 
146
+ /** The loss notes about something graphtyImport always gives back (see lostForCytoscape). */
147
+ const CYTOSCAPE_KEEPS: ReadonlySet<string> = new Set([
148
+ "W_ID_TEXT_TYPE",
149
+ "W_ID_RENUMBERED",
150
+ "W_CSV_NODE_ORDER",
151
+ "W_STORAGE_CLASS_CHANGED",
152
+ ]);
153
+
146
154
  /**
147
155
  * Whether a graph-io loss note is a loss for a Cytoscape graph. graph-io's notes describe its own snapshot read back
148
156
  * by itself; graphtyImport restores some of what they report:
149
157
  * - W_ID_TEXT_TYPE: every id is turned back into a string;
158
+ * - W_ID_RENUMBERED (Pajek) and W_CSV_NODE_ORDER: graphtyImport gives the nodes their original ids back, and a
159
+ * Cytoscape node is known by its id, not by its place in the file;
160
+ * - W_STORAGE_CLASS_CHANGED: text stored as a dictionary or as plain strings reads back as the same strings;
150
161
  * - W_COLUMN_NAME_CHANGED on the edge `id`, the `parent` or the `position` (DOT reads them back as "key",
151
162
  * "graphty.parent" and "pos"): they are read back by their role, as the edge id, `data.parent` and the position;
152
163
  * - W_ROLE_DROPPED on `label`: the values read back as `data.label`, and Cytoscape has no label role to lose.
@@ -154,7 +165,7 @@ export async function importElements(
154
165
  * @returns false for a note about something graphtyImport gives back
155
166
  */
156
167
  function lostForCytoscape(n: LossNote): boolean {
157
- if (n.code === "W_ID_TEXT_TYPE") {
168
+ if (CYTOSCAPE_KEEPS.has(n.code)) {
158
169
  return false;
159
170
  }
160
171
  if (n.code === "W_COLUMN_NAME_CHANGED" && (n.column === "id" || n.column === "parent" || n.column === "position")) {
package/src/layouts.ts CHANGED
@@ -116,8 +116,8 @@ export interface LayoutOptionFields {
116
116
  */
117
117
  readonly dim?: 2 | 3;
118
118
  /**
119
- * Seed of the layouts that draw random numbers: graphty-random, graphty-spectral, graphty-planar, graphty-arf and
120
- * the three simulations. The same seed gives the same positions; without one, positions that depend on random
119
+ * Seed of the layouts that draw random numbers: graphty-random, graphty-spectral (above 500 nodes), graphty-arf
120
+ * and the three simulations. The same seed gives the same positions; without one, positions that depend on random
121
121
  * numbers differ from run to run. The other layouts ignore it.
122
122
  */
123
123
  readonly seed?: number;