tycho-components 0.25.12 → 0.26.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.
@@ -13,11 +13,15 @@ export default class CytoscapeTreeConverter {
13
13
  private isEmptyCategoryInChunk;
14
14
  private convertEmptyCategory;
15
15
  private convertChunk;
16
+ private shouldChunkClaimToken;
16
17
  private removeTemporaryEdges;
17
18
  private generateChunkId;
18
19
  private generateTokenId;
19
20
  private generateLeafId;
20
21
  private findParent;
22
+ private findContainingChunks;
23
+ private findTightestContainingChunk;
24
+ private tightestChunk;
21
25
  private initTree;
22
26
  private sortChunks;
23
27
  private convertToken;
@@ -160,7 +160,7 @@ export default class CytoscapeTreeConverter {
160
160
  });
161
161
  const tokens = this.getTokens(struct, chunk);
162
162
  for (const token of tokens) {
163
- if (token.ec)
163
+ if (!this.shouldChunkClaimToken(struct, chunk, token))
164
164
  continue;
165
165
  tree.edges.push({
166
166
  data: {
@@ -171,6 +171,20 @@ export default class CytoscapeTreeConverter {
171
171
  });
172
172
  }
173
173
  }
174
+ shouldChunkClaimToken(struct, chunk, token) {
175
+ if (token.ec)
176
+ return false;
177
+ if (token.l === 0 && chunk.l > 0) {
178
+ const dominator = this.findTightestContainingChunk(struct, token.p, token.p);
179
+ return (dominator !== null &&
180
+ this.generateChunkId(dominator) === this.generateChunkId(chunk));
181
+ }
182
+ if (token.l !== chunk.l)
183
+ return false;
184
+ const dominator = this.tightestChunk(this.findContainingChunks(struct, chunk.l, token.p, token.p));
185
+ return (dominator !== null &&
186
+ this.generateChunkId(dominator) === this.generateChunkId(chunk));
187
+ }
174
188
  removeTemporaryEdges(tree, struct, chunk) {
175
189
  let levelCount = 1;
176
190
  let leveledChunks = this.getChunksByLevel(struct, chunk, levelCount);
@@ -178,14 +192,16 @@ export default class CytoscapeTreeConverter {
178
192
  for (const upperChunk of leveledChunks) {
179
193
  const upperChunkId = this.generateChunkId(upperChunk);
180
194
  for (const token of this.getTokens(struct, chunk)) {
195
+ if (!this.shouldChunkClaimToken(struct, chunk, token))
196
+ continue;
181
197
  const tokenId = this.generateTokenId(token);
182
198
  tree.edges = [
183
199
  ...tree.edges.filter((e) => !(e.data.source === upperChunkId && e.data.target === tokenId)),
184
200
  ];
185
201
  }
186
202
  }
187
- leveledChunks = this.getChunksByLevel(struct, chunk, levelCount);
188
203
  levelCount++;
204
+ leveledChunks = this.getChunksByLevel(struct, chunk, levelCount);
189
205
  }
190
206
  }
191
207
  generateChunkId(chunk) {
@@ -212,18 +228,26 @@ export default class CytoscapeTreeConverter {
212
228
  return `${token.p}`;
213
229
  }
214
230
  findParent(struct, chunk) {
215
- const chunks = this.getChunksByLevel(struct, chunk, 1);
231
+ return this.tightestChunk(this.findContainingChunks(struct, chunk.l - 1, chunk.i, chunk.f));
232
+ }
233
+ findContainingChunks(struct, level, i, f) {
234
+ return struct.chunks.filter((c) => c.l === level && i >= c.i && f <= c.f);
235
+ }
236
+ findTightestContainingChunk(struct, i, f, minLevel = 1) {
237
+ return this.tightestChunk(struct.chunks.filter((c) => c.l >= minLevel && i >= c.i && f <= c.f));
238
+ }
239
+ tightestChunk(chunks) {
216
240
  if (chunks.length === 0)
217
241
  return null;
218
- for (const parent of chunks) {
219
- const tf = chunk.f;
220
- const ti = chunk.i;
221
- const ptf = parent.f;
222
- const pti = parent.i;
223
- if (tf <= ptf && ti >= pti)
224
- return parent;
225
- }
226
- return null;
242
+ return chunks.reduce((best, c) => {
243
+ const span = c.f - c.i;
244
+ const bestSpan = best.f - best.i;
245
+ if (span < bestSpan)
246
+ return c;
247
+ if (span > bestSpan)
248
+ return best;
249
+ return c.i > best.i ? c : best;
250
+ });
227
251
  }
228
252
  initTree(struct) {
229
253
  this.sortChunks(struct);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.25.12",
4
+ "version": "0.26.1",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -55,8 +55,8 @@
55
55
  "cytoscape-dagre": "^2.5.0",
56
56
  "cytoscape-node-html-label": "^1.2.2",
57
57
  "date-fns": "^4.1.0",
58
- "driver.js": "^1.4.0",
59
58
  "date-fns-tz": "^3.2.0",
59
+ "driver.js": "^1.4.0",
60
60
  "file-saver": "^2.0.5",
61
61
  "html2canvas": "^1.4.1",
62
62
  "js-cookie": "^3.0.5",
@@ -112,6 +112,7 @@
112
112
  "storybook": "^10.1.11",
113
113
  "typescript": "^5.7.3",
114
114
  "vite": "^7.0.0",
115
+ "vitest": "^3.2.6",
115
116
  "wavesurfer-react": "^2.2.2",
116
117
  "wavesurfer.js": "^6.6.3"
117
118
  },
@@ -120,6 +121,7 @@
120
121
  "build-storybook": "storybook build",
121
122
  "build": "tsc && node scripts/copy-package-json.js && npm run copy-css",
122
123
  "build-publish": "tsc && npm run copy-css",
123
- "copy-css": "node scripts/copy-css.js"
124
+ "copy-css": "node scripts/copy-css.js",
125
+ "test": "vitest run"
124
126
  }
125
127
  }