@weasel-js/diagram 1.11.1 → 1.12.0

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.
@@ -1,4 +1,4 @@
1
- import { AUTO_POSE_DESCRIPTOR, rotatePoint, rectPath, polygonFromPoints, PATH_M, PATH_L, PATH_C, flattenCubic, PATH_Q, PATH_Z, PathBuilder, pointAlongPath } from '@weasel-js/core/math';
1
+ import { AUTO_POSE_DESCRIPTOR, rotatePoint, rectPath, polygonFromPoints, PATH_M, PATH_L, PATH_C, flattenCubic, PATH_Q, PATH_Z, PathBuilder, clipNothing, pointAlongPath } from '@weasel-js/core/math';
2
2
  import { transformPath, ellipsePath, PATH_M as PATH_M$1, PATH_CMD_LENGTHS, measurePath, forEachSegment, PATH_L as PATH_L$1, nearestOnLine, PATH_Q as PATH_Q$1, nearestOnQuadratic, PATH_C as PATH_C$1, nearestOnCubic } from '@weasel-js/geom';
3
3
  import { cssFamilyName } from '@weasel-js/font/metrics';
4
4
  import { createSimulation } from '@weasel-js/simulation';
@@ -502,6 +502,7 @@ function buildBody(spec, at2, opts) {
502
502
  layer: opts.layer,
503
503
  pose,
504
504
  data: opts.body(trait, pose),
505
+ clipFromPose: clipNothing,
505
506
  ...opts.id === void 0 ? {} : { id: opts.id }
506
507
  }];
507
508
  const leaf = (box, data, rowId) => {
@@ -2855,36 +2856,55 @@ function lineGaps(graph, line, hanging, rankGap, axes, packed) {
2855
2856
  for (const node of graph.nodes) {
2856
2857
  if (!index.has(node.id)) columns[index.get(hanging.owner.get(node.id))].push(node);
2857
2858
  }
2858
- const gaps = rankGaps(graph, columns, axes, rankGap);
2859
+ return bandGaps(graph, columns, axes, columns.slice(1).map(() => rankGap), (id) => packed.get(id)?.rank);
2860
+ }
2861
+ function levelGaps(graph, hanging, levelSize, axes, before, base) {
2862
+ const levels = Array.from(levelSize, () => []);
2863
+ for (const node of graph.nodes) (levels[hanging.level.get(node.id)] ??= []).push(node);
2864
+ const outward = { rank: axes.cross, cross: axes.rank, sign: before ? -1 : 1 };
2865
+ const from = [0];
2866
+ for (let k = 1; k < levelSize.length; k++) from[k] = from[k - 1] + (levelSize[k - 1] ?? 0);
2867
+ return bandGaps(graph, levels, outward, base, (id) => {
2868
+ const node = graph.node(id);
2869
+ const at2 = hanging.level.get(id);
2870
+ if (node === void 0 || at2 === void 0) return void 0;
2871
+ return at2 === 0 ? (levelSize[0] - extent(node.bounds, outward.rank)) / 2 : from[at2];
2872
+ });
2873
+ }
2874
+ function bandGaps(graph, bands, axes, gaps, start) {
2875
+ const insets = rankGaps(graph, bands, axes, 0);
2876
+ const out = gaps.map((gap, i) => gap + (insets[i] ?? 0));
2859
2877
  const groups = graph.groups ?? [];
2860
- if (axes.rank !== "x" || !groups.some((g) => g.minWidth !== void 0)) return gaps;
2861
- const columnOf = (id) => index.get(id) ?? index.get(hanging.owner.get(id));
2878
+ if (axes.rank !== "x" || !groups.some((g) => g.minWidth !== void 0)) return out;
2879
+ const bandOf = /* @__PURE__ */ new Map();
2880
+ bands.forEach((band, i) => band.forEach((n) => bandOf.set(n.id, i)));
2862
2881
  const children = /* @__PURE__ */ new Map();
2863
2882
  for (const g of groups) if (g.parent !== void 0) children.set(g.parent, [...children.get(g.parent) ?? [], g.id]);
2864
2883
  const byId = new Map(groups.map((g) => [g.id, g]));
2865
2884
  const span = (id, now) => {
2866
2885
  let [lo, hi] = [Infinity, -Infinity];
2867
2886
  for (const m of byId.get(id).members) {
2868
- const slot = packed.get(m);
2887
+ const at2 = start(m);
2888
+ const band = bandOf.get(m);
2869
2889
  const node = graph.node(m);
2870
- if (slot === void 0 || node === void 0) continue;
2871
- const from = slot.rank + now.slice(0, columnOf(m)).reduce((s, gap) => s + gap, 0);
2890
+ if (at2 === void 0 || band === void 0 || node === void 0) continue;
2891
+ const from = at2 + now.slice(0, band).reduce((s, gap) => s + gap, 0);
2872
2892
  [lo, hi] = [Math.min(lo, from), Math.max(hi, from + extent(node.bounds, axes.rank))];
2873
2893
  }
2874
2894
  return { lo, hi };
2875
2895
  };
2876
2896
  widenForMinWidth(deepestFirst(groups).map((g) => {
2877
- const cols = g.members.filter((id) => packed.has(id)).map(columnOf);
2897
+ const placed = g.members.flatMap((id) => bandOf.has(id) && start(id) !== void 0 ? [bandOf.get(id)] : []);
2878
2898
  return {
2879
2899
  id: g.id,
2880
2900
  ...g.minWidth !== void 0 ? { minWidth: g.minWidth } : {},
2881
2901
  inset: rankInset(g.inset, axes),
2882
2902
  children: children.get(g.id) ?? [],
2883
- before: cols.length === 0 ? -1 : Math.min(...cols) - 1,
2884
- after: cols.length === 0 ? -1 : Math.max(...cols)
2903
+ before: placed.length === 0 ? -1 : Math.min(...placed) - 1,
2904
+ after: placed.length === 0 ? -1 : Math.max(...placed)
2885
2905
  };
2886
- }), gaps, span);
2887
- return gaps;
2906
+ }), out, span);
2907
+ return out;
2888
2908
  }
2889
2909
  function widenForMinWidth(groups, gaps, span) {
2890
2910
  const byId = new Map(groups.map((g) => [g.id, g]));
@@ -3078,21 +3098,26 @@ function chainPlan(graph, opts = {}) {
3078
3098
  }
3079
3099
  for (const [id, column] of rows) if (column[1]) column[1] = inPortOrder(graph, id, column[1], axes);
3080
3100
  const before = opts.chainSide === "before";
3081
- const slots = (rank, side2) => slotsFor(line, rows, levelSize, axes, { node: nodeGap, rank, side: side2 }, before);
3082
- const gaps = graph.groups?.length ? lineGaps(graph, line, hanging, rankGap, axes, slots(line.map(() => 0), nodeGap)) : line.map(() => rankGap);
3083
- const place = (side2) => settle(graph, slots(gaps, side2), opts);
3101
+ const grouped = (graph.groups?.length ?? 0) > 0;
3102
+ const across = (side2) => {
3103
+ const base = Array.from(levelSize.slice(1), (_, k) => k === 0 ? side2 : nodeGap);
3104
+ return grouped ? levelGaps(graph, hanging, levelSize, axes, before, base) : base;
3105
+ };
3106
+ const slots = (rank, level2) => slotsFor(line, rows, levelSize, axes, { node: nodeGap, rank, level: level2 }, before);
3107
+ const gaps = grouped ? lineGaps(graph, line, hanging, rankGap, axes, slots(line.map(() => 0), [])) : line.map(() => rankGap);
3108
+ const place = (side2) => settle(graph, slots(gaps, across(side2)), opts);
3084
3109
  let moves = place(nodeGap);
3085
3110
  const side = (tracksNeeded(graph, hanging, moves, axes, before) + 1) * SIDE_TRACK_GAP;
3086
3111
  if (side > nodeGap) moves = place(side);
3087
3112
  return { moves, waypoints: sideRoutes(graph, hanging, moves, axes, before) };
3088
3113
  }
3089
3114
  function slotsFor(line, rows, levelSize, axes, gaps, before) {
3090
- const { node: nodeGap, rank: rankGap } = gaps;
3115
+ const { node: nodeGap, rank: rankGap, level: levelGap } = gaps;
3091
3116
  const rowSpan = (row) => row.reduce((sum, n) => sum + extent(n.bounds, axes.rank), 0) + nodeGap * Math.max(row.length - 1, 0);
3092
3117
  const bandStart = (at2) => {
3093
3118
  let offset = 0;
3094
- const first = before ? 1 : 0;
3095
- for (let k = first; k < (before ? at2 + 1 : at2); k++) offset += (levelSize[k] ?? 0) + (k === first ? gaps.side : nodeGap);
3119
+ if (before) for (let k = 1; k <= at2; k++) offset += (levelSize[k] ?? 0) + (levelGap[k - 1] ?? 0);
3120
+ else for (let k = 0; k < at2; k++) offset += (levelSize[k] ?? 0) + (levelGap[k] ?? 0);
3096
3121
  return before ? -offset : offset;
3097
3122
  };
3098
3123
  const slots = /* @__PURE__ */ new Map();
@@ -3216,5 +3241,5 @@ var treeOnce = (graph, opts = {}) => {
3216
3241
  };
3217
3242
 
3218
3243
  export { COMPASS, DEFAULT_GROUP_INSET, DEFAULT_NODE_GAP, DEFAULT_PORTS, DEFAULT_RANK_GAP, DIAGRAM_TRAIT_KEY, PORT_LABEL_GAP, SIDE_TRACK_GAP, anchorOffset, authoredOver, axesFor, backEdges, bodyOutline, bodyTrait, boxForContent, buildBody, canvasMeasure, center, chain, contentBox, createDiagramNodes, dataKeyReader, diagramEdgeOf, diagramNodeOf, expandGroupEdges, extent, footprintNode, force, forceRelaxation, forestOf, graphOrder, grownBy, insetOf, isPinned, isPromise, labelCenter, labelSpotAt, layered, layeredPlan, layeredRoutes, layoutBody, layoutOwnsPort, layoutOwnsRoute, layoutRowPorts, layoutWritesRoute, marginOf, measureBody, outlinePath, outlinePolyline, packAcross, packClusters, pinnedSet, planOf, plannerPlan, portLabelBox, portLabelsOf, portOf, portSitesOf, portsOf, portsOnOutline, rankGaps, ranksByLength, ranksOf, rayHit, routeHolds, samePoints, seededOrder, settle, sizeToBody, subpathOf, translated, tree, untilSettled, widenForMinWidth };
3219
- //# sourceMappingURL=chunk-IM6DHWZO.js.map
3220
- //# sourceMappingURL=chunk-IM6DHWZO.js.map
3244
+ //# sourceMappingURL=chunk-R2XB6D32.js.map
3245
+ //# sourceMappingURL=chunk-R2XB6D32.js.map