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/flowchart.js CHANGED
@@ -1994,6 +1994,18 @@ function centerForkParents(graph, options = {}) {
1994
1994
  }
1995
1995
  return minX <= maxX ? Math.max(minX, Math.min(maxX, desiredX)) : x0;
1996
1996
  };
1997
+ const evenFanKids = (forkCenter, kids) => {
1998
+ if (kids.length < 2) return;
1999
+ const sorted = [...kids].sort((a, b) => centerX(a) - centerX(b));
2000
+ let gap = 0;
2001
+ for (let i = 0; i < sorted.length - 1; i++) {
2002
+ gap = Math.max(gap, width.get(sorted[i]) / 2 + nodeSep + width.get(sorted[i + 1]) / 2);
2003
+ }
2004
+ const mid = (sorted.length - 1) / 2;
2005
+ for (let i = 0; i < sorted.length; i++) {
2006
+ workingX.set(sorted[i], forkCenter + (i - mid) * gap - width.get(sorted[i]) / 2);
2007
+ }
2008
+ };
1997
2009
  const order = [...graph.nodes].sort(
1998
2010
  (a, b) => b.position.y - a.position.y || a.position.x - b.position.x || a.id.localeCompare(b.id)
1999
2011
  );
@@ -2012,6 +2024,11 @@ function centerForkParents(graph, options = {}) {
2012
2024
  const wN = width.get(n.id);
2013
2025
  const span = (Math.min(...centers) + Math.max(...centers)) / 2;
2014
2026
  workingX.set(n.id, clampX(n.id, span - wN / 2));
2027
+ if (isFork) {
2028
+ const succSets = kin.map((k) => childrenOf.get(k) ?? []);
2029
+ const isDiamond = kin.length >= 2 && succSets[0].some((s) => succSets.every((ss) => ss.includes(s)));
2030
+ if (isDiamond) evenFanKids(centerX(n.id), kin);
2031
+ }
2015
2032
  const stepOf = isFork ? predsOf : childrenOf;
2016
2033
  let curId = n.id;
2017
2034
  const walked = /* @__PURE__ */ new Set([curId]);
@@ -2028,6 +2045,28 @@ function centerForkParents(graph, options = {}) {
2028
2045
  curId = m;
2029
2046
  }
2030
2047
  }
2048
+ for (const n of order) {
2049
+ const outD = outDegree.get(n.id) ?? 0;
2050
+ const inD = inDegree.get(n.id) ?? 0;
2051
+ if (!(outD >= 2 && inD <= 1)) continue;
2052
+ const kids = (childrenOf.get(n.id) ?? []).filter(
2053
+ (k) => byId.get(k)?.parentId === n.parentId
2054
+ );
2055
+ if (kids.length < 2) continue;
2056
+ const succSets = kids.map((k) => childrenOf.get(k) ?? []);
2057
+ const isDiamond = succSets[0].some((s) => succSets.every((ss) => ss.includes(s)));
2058
+ if (isDiamond) continue;
2059
+ const ps = predsOf.get(n.id);
2060
+ if (!ps || ps.length !== 1) continue;
2061
+ const pred = ps[0];
2062
+ if ((outDegree.get(pred) ?? 0) !== 1) continue;
2063
+ if (byId.get(pred)?.parentId !== byId.get(n.id)?.parentId) continue;
2064
+ const before = centerX(n.id);
2065
+ workingX.set(n.id, clampX(n.id, centerX(pred) - width.get(n.id) / 2));
2066
+ const delta = centerX(n.id) - before;
2067
+ if (delta === 0) continue;
2068
+ for (const k of kids) workingX.set(k, clampX(k, workingX.get(k) + delta));
2069
+ }
2031
2070
  const nodes = graph.nodes.map(
2032
2071
  (n) => workingX.get(n.id) === n.position.x ? n : { ...n, position: { x: workingX.get(n.id), y: n.position.y } }
2033
2072
  );