@crazyhappyone/auto-graph 0.2.0 → 0.2.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.
package/dist/cli/index.js CHANGED
@@ -3378,15 +3378,25 @@ function isValidDimension(value) {
3378
3378
  }
3379
3379
 
3380
3380
  // src/routing/astar.ts
3381
- function findObstacleFreePath(source, target, obstacles, options = {}) {
3381
+ function findObstacleFreePath(source, target, obstacles, options = {}, diagnostics) {
3382
3382
  const margin = options.margin ?? 0;
3383
3383
  const turnPenalty = options.turnPenalty ?? 50;
3384
3384
  const segmentPenalty = options.segmentPenalty ?? 1;
3385
3385
  const endpointObstacles = options.endpointObstacles ?? [];
3386
- const maxNodes = options.maxNodes ?? 4e3;
3386
+ const maxNodes = options.maxNodes ?? (obstacles.length > 30 ? 16e3 : 4e3);
3387
3387
  const xs = collectXs(source, target, obstacles, margin);
3388
3388
  const ys = collectYs(source, target, obstacles, margin);
3389
3389
  if (xs.length * ys.length > maxNodes) {
3390
+ diagnostics?.push({
3391
+ severity: "warning",
3392
+ code: "routing.astar.grid_overflow",
3393
+ message: `A* grid overflow: ${xs.length * ys.length} nodes > ${maxNodes} limit. Falling back to heuristic routing.`,
3394
+ detail: {
3395
+ xsCount: xs.length,
3396
+ ysCount: ys.length,
3397
+ maxNodes
3398
+ }
3399
+ });
3390
3400
  return null;
3391
3401
  }
3392
3402
  const { nodes, nodeIndex } = buildGraph(xs, ys);
@@ -3404,24 +3414,41 @@ function findObstacleFreePath(source, target, obstacles, options = {}) {
3404
3414
  return simplifyRoute(path);
3405
3415
  }
3406
3416
  function collectXs(source, target, obstacles, margin) {
3407
- const set = /* @__PURE__ */ new Set();
3408
- set.add(source.x);
3409
- set.add(target.x);
3417
+ const raw = [];
3410
3418
  for (const obs of obstacles) {
3411
- set.add(obs.x - margin - 2);
3412
- set.add(obs.x + obs.width + margin + 2);
3419
+ raw.push(obs.x - margin - 2, obs.x + obs.width + margin + 2);
3413
3420
  }
3414
- return [...set].sort((a, b) => a - b);
3421
+ const deduped = dedupSorted(raw);
3422
+ for (const v of [source.x, target.x]) {
3423
+ if (!deduped.includes(v)) {
3424
+ deduped.push(v);
3425
+ }
3426
+ }
3427
+ return deduped.sort((a, b) => a - b);
3415
3428
  }
3416
3429
  function collectYs(source, target, obstacles, margin) {
3417
- const set = /* @__PURE__ */ new Set();
3418
- set.add(source.y);
3419
- set.add(target.y);
3430
+ const raw = [];
3420
3431
  for (const obs of obstacles) {
3421
- set.add(obs.y - margin - 2);
3422
- set.add(obs.y + obs.height + margin + 2);
3432
+ raw.push(obs.y - margin - 2, obs.y + obs.height + margin + 2);
3433
+ }
3434
+ const deduped = dedupSorted(raw);
3435
+ for (const v of [source.y, target.y]) {
3436
+ if (!deduped.includes(v)) {
3437
+ deduped.push(v);
3438
+ }
3423
3439
  }
3424
- return [...set].sort((a, b) => a - b);
3440
+ return deduped.sort((a, b) => a - b);
3441
+ }
3442
+ function dedupSorted(values) {
3443
+ const sorted = [...values].sort((a, b) => a - b);
3444
+ const result = [];
3445
+ for (const v of sorted) {
3446
+ const last = result[result.length - 1];
3447
+ if (last === void 0 || v - last > 2) {
3448
+ result.push(v);
3449
+ }
3450
+ }
3451
+ return result;
3425
3452
  }
3426
3453
  function buildGraph(xs, ys) {
3427
3454
  const nodes = [];
@@ -3651,7 +3678,8 @@ function routeEdge(input) {
3651
3678
  [...softObstacles, ...hardObstacles],
3652
3679
  {
3653
3680
  endpointObstacles
3654
- }
3681
+ },
3682
+ diagnostics
3655
3683
  );
3656
3684
  if (path !== null && path.length >= 2) {
3657
3685
  const finalized = finalizeRoute(
@@ -4502,7 +4530,7 @@ function solveDiagram(diagram, options = {}) {
4502
4530
  direction: diagram.direction,
4503
4531
  overlapSpacing: options?.overlapSpacing ?? 40,
4504
4532
  ...options.minSiblingGap === void 0 ? {} : { minSiblingGap: options.minSiblingGap },
4505
- ...options.distributeContainedChildren === void 0 ? {} : { distributeContainedChildren: options.distributeContainedChildren },
4533
+ distributeContainedChildren: options.distributeContainedChildren ?? true,
4506
4534
  boxes: initialNodeBoxes,
4507
4535
  nodes: styledNodes,
4508
4536
  constraints