footprint-explainable-ui 0.25.2 → 0.25.3

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/dist/index.js CHANGED
@@ -3564,6 +3564,18 @@ function centerForkParents(graph, options = {}) {
3564
3564
  }
3565
3565
  return minX <= maxX ? Math.max(minX, Math.min(maxX, desiredX)) : x0;
3566
3566
  };
3567
+ const evenFanKids = (forkCenter, kids) => {
3568
+ if (kids.length < 2) return;
3569
+ const sorted = [...kids].sort((a, b) => centerX(a) - centerX(b));
3570
+ let gap = 0;
3571
+ for (let i = 0; i < sorted.length - 1; i++) {
3572
+ gap = Math.max(gap, width.get(sorted[i]) / 2 + nodeSep + width.get(sorted[i + 1]) / 2);
3573
+ }
3574
+ const mid = (sorted.length - 1) / 2;
3575
+ for (let i = 0; i < sorted.length; i++) {
3576
+ workingX.set(sorted[i], forkCenter + (i - mid) * gap - width.get(sorted[i]) / 2);
3577
+ }
3578
+ };
3567
3579
  const order = [...graph.nodes].sort(
3568
3580
  (a, b) => b.position.y - a.position.y || a.position.x - b.position.x || a.id.localeCompare(b.id)
3569
3581
  );
@@ -3582,6 +3594,11 @@ function centerForkParents(graph, options = {}) {
3582
3594
  const wN = width.get(n.id);
3583
3595
  const span = (Math.min(...centers) + Math.max(...centers)) / 2;
3584
3596
  workingX.set(n.id, clampX(n.id, span - wN / 2));
3597
+ if (isFork) {
3598
+ const succSets = kin.map((k) => childrenOf.get(k) ?? []);
3599
+ const isDiamond = kin.length >= 2 && succSets[0].some((s) => succSets.every((ss) => ss.includes(s)));
3600
+ if (isDiamond) evenFanKids(centerX(n.id), kin);
3601
+ }
3585
3602
  const stepOf = isFork ? predsOf : childrenOf;
3586
3603
  let curId = n.id;
3587
3604
  const walked = /* @__PURE__ */ new Set([curId]);
@@ -3598,6 +3615,28 @@ function centerForkParents(graph, options = {}) {
3598
3615
  curId = m;
3599
3616
  }
3600
3617
  }
3618
+ for (const n of order) {
3619
+ const outD = outDegree.get(n.id) ?? 0;
3620
+ const inD = inDegree.get(n.id) ?? 0;
3621
+ if (!(outD >= 2 && inD <= 1)) continue;
3622
+ const kids = (childrenOf.get(n.id) ?? []).filter(
3623
+ (k) => byId.get(k)?.parentId === n.parentId
3624
+ );
3625
+ if (kids.length < 2) continue;
3626
+ const succSets = kids.map((k) => childrenOf.get(k) ?? []);
3627
+ const isDiamond = succSets[0].some((s) => succSets.every((ss) => ss.includes(s)));
3628
+ if (isDiamond) continue;
3629
+ const ps = predsOf.get(n.id);
3630
+ if (!ps || ps.length !== 1) continue;
3631
+ const pred = ps[0];
3632
+ if ((outDegree.get(pred) ?? 0) !== 1) continue;
3633
+ if (byId.get(pred)?.parentId !== byId.get(n.id)?.parentId) continue;
3634
+ const before = centerX(n.id);
3635
+ workingX.set(n.id, clampX(n.id, centerX(pred) - width.get(n.id) / 2));
3636
+ const delta = centerX(n.id) - before;
3637
+ if (delta === 0) continue;
3638
+ for (const k of kids) workingX.set(k, clampX(k, workingX.get(k) + delta));
3639
+ }
3601
3640
  const nodes = graph.nodes.map(
3602
3641
  (n) => workingX.get(n.id) === n.position.x ? n : { ...n, position: { x: workingX.get(n.id), y: n.position.y } }
3603
3642
  );