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