@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/index.js
CHANGED
|
@@ -3981,15 +3981,25 @@ function isValidDimension(value) {
|
|
|
3981
3981
|
}
|
|
3982
3982
|
|
|
3983
3983
|
// src/routing/astar.ts
|
|
3984
|
-
function findObstacleFreePath(source, target, obstacles, options = {}) {
|
|
3984
|
+
function findObstacleFreePath(source, target, obstacles, options = {}, diagnostics) {
|
|
3985
3985
|
const margin = options.margin ?? 0;
|
|
3986
3986
|
const turnPenalty = options.turnPenalty ?? 50;
|
|
3987
3987
|
const segmentPenalty = options.segmentPenalty ?? 1;
|
|
3988
3988
|
const endpointObstacles = options.endpointObstacles ?? [];
|
|
3989
|
-
const maxNodes = options.maxNodes ?? 4e3;
|
|
3989
|
+
const maxNodes = options.maxNodes ?? (obstacles.length > 30 ? 16e3 : 4e3);
|
|
3990
3990
|
const xs = collectXs(source, target, obstacles, margin);
|
|
3991
3991
|
const ys = collectYs(source, target, obstacles, margin);
|
|
3992
3992
|
if (xs.length * ys.length > maxNodes) {
|
|
3993
|
+
diagnostics?.push({
|
|
3994
|
+
severity: "warning",
|
|
3995
|
+
code: "routing.astar.grid_overflow",
|
|
3996
|
+
message: `A* grid overflow: ${xs.length * ys.length} nodes > ${maxNodes} limit. Falling back to heuristic routing.`,
|
|
3997
|
+
detail: {
|
|
3998
|
+
xsCount: xs.length,
|
|
3999
|
+
ysCount: ys.length,
|
|
4000
|
+
maxNodes
|
|
4001
|
+
}
|
|
4002
|
+
});
|
|
3993
4003
|
return null;
|
|
3994
4004
|
}
|
|
3995
4005
|
const { nodes, nodeIndex } = buildGraph(xs, ys);
|
|
@@ -4007,24 +4017,41 @@ function findObstacleFreePath(source, target, obstacles, options = {}) {
|
|
|
4007
4017
|
return simplifyRoute(path);
|
|
4008
4018
|
}
|
|
4009
4019
|
function collectXs(source, target, obstacles, margin) {
|
|
4010
|
-
const
|
|
4011
|
-
set.add(source.x);
|
|
4012
|
-
set.add(target.x);
|
|
4020
|
+
const raw = [];
|
|
4013
4021
|
for (const obs of obstacles) {
|
|
4014
|
-
|
|
4015
|
-
set.add(obs.x + obs.width + margin + 2);
|
|
4022
|
+
raw.push(obs.x - margin - 2, obs.x + obs.width + margin + 2);
|
|
4016
4023
|
}
|
|
4017
|
-
|
|
4024
|
+
const deduped = dedupSorted(raw);
|
|
4025
|
+
for (const v of [source.x, target.x]) {
|
|
4026
|
+
if (!deduped.includes(v)) {
|
|
4027
|
+
deduped.push(v);
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
return deduped.sort((a, b) => a - b);
|
|
4018
4031
|
}
|
|
4019
4032
|
function collectYs(source, target, obstacles, margin) {
|
|
4020
|
-
const
|
|
4021
|
-
set.add(source.y);
|
|
4022
|
-
set.add(target.y);
|
|
4033
|
+
const raw = [];
|
|
4023
4034
|
for (const obs of obstacles) {
|
|
4024
|
-
|
|
4025
|
-
|
|
4035
|
+
raw.push(obs.y - margin - 2, obs.y + obs.height + margin + 2);
|
|
4036
|
+
}
|
|
4037
|
+
const deduped = dedupSorted(raw);
|
|
4038
|
+
for (const v of [source.y, target.y]) {
|
|
4039
|
+
if (!deduped.includes(v)) {
|
|
4040
|
+
deduped.push(v);
|
|
4041
|
+
}
|
|
4026
4042
|
}
|
|
4027
|
-
return
|
|
4043
|
+
return deduped.sort((a, b) => a - b);
|
|
4044
|
+
}
|
|
4045
|
+
function dedupSorted(values) {
|
|
4046
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
4047
|
+
const result = [];
|
|
4048
|
+
for (const v of sorted) {
|
|
4049
|
+
const last = result[result.length - 1];
|
|
4050
|
+
if (last === void 0 || v - last > 2) {
|
|
4051
|
+
result.push(v);
|
|
4052
|
+
}
|
|
4053
|
+
}
|
|
4054
|
+
return result;
|
|
4028
4055
|
}
|
|
4029
4056
|
function buildGraph(xs, ys) {
|
|
4030
4057
|
const nodes = [];
|
|
@@ -4254,7 +4281,8 @@ function routeEdge(input) {
|
|
|
4254
4281
|
[...softObstacles, ...hardObstacles],
|
|
4255
4282
|
{
|
|
4256
4283
|
endpointObstacles
|
|
4257
|
-
}
|
|
4284
|
+
},
|
|
4285
|
+
diagnostics
|
|
4258
4286
|
);
|
|
4259
4287
|
if (path !== null && path.length >= 2) {
|
|
4260
4288
|
const finalized = finalizeRoute(
|
|
@@ -5105,7 +5133,7 @@ function solveDiagram(diagram, options = {}) {
|
|
|
5105
5133
|
direction: diagram.direction,
|
|
5106
5134
|
overlapSpacing: options?.overlapSpacing ?? 40,
|
|
5107
5135
|
...options.minSiblingGap === void 0 ? {} : { minSiblingGap: options.minSiblingGap },
|
|
5108
|
-
|
|
5136
|
+
distributeContainedChildren: options.distributeContainedChildren ?? true,
|
|
5109
5137
|
boxes: initialNodeBoxes,
|
|
5110
5138
|
nodes: styledNodes,
|
|
5111
5139
|
constraints
|