@crazyhappyone/auto-graph 0.1.2 → 0.1.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/README.md +6 -1
- package/README.zh-CN.md +6 -1
- package/dist/cli/index.cjs +22 -17
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +22 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +22 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +22 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,12 @@ if (parsed.value === undefined) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const normalized = normalizeDiagramDsl(parsed.value);
|
|
73
|
-
const coordinated = solveDiagram(normalized.diagram
|
|
73
|
+
const coordinated = solveDiagram(normalized.diagram, {
|
|
74
|
+
routeKind: "obstacle-avoiding",
|
|
75
|
+
maxRoutingAttempts: 8,
|
|
76
|
+
labelPlacement: "beside",
|
|
77
|
+
labelOffset: 16,
|
|
78
|
+
});
|
|
74
79
|
|
|
75
80
|
const svg = exportSvg(coordinated, { title: "Architecture" });
|
|
76
81
|
const excalidraw = exportExcalidraw(coordinated);
|
package/README.zh-CN.md
CHANGED
|
@@ -70,7 +70,12 @@ if (parsed.value === undefined) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const normalized = normalizeDiagramDsl(parsed.value);
|
|
73
|
-
const coordinated = solveDiagram(normalized.diagram
|
|
73
|
+
const coordinated = solveDiagram(normalized.diagram, {
|
|
74
|
+
routeKind: "obstacle-avoiding",
|
|
75
|
+
maxRoutingAttempts: 8,
|
|
76
|
+
labelPlacement: "beside",
|
|
77
|
+
labelOffset: 16,
|
|
78
|
+
});
|
|
74
79
|
|
|
75
80
|
const svg = exportSvg(coordinated, { title: "Architecture" });
|
|
76
81
|
const excalidraw = exportExcalidraw(coordinated);
|
package/dist/cli/index.cjs
CHANGED
|
@@ -3259,6 +3259,7 @@ function routeEdge(input) {
|
|
|
3259
3259
|
const diagnostics = [];
|
|
3260
3260
|
const softObstacles = input.obstacles ?? [];
|
|
3261
3261
|
const hardObstacles = input.hardObstacles ?? [];
|
|
3262
|
+
const maxAttempts = input.maxRoutingAttempts ?? 5;
|
|
3262
3263
|
const defaultAnchors = defaultAnchorsForGeometry(
|
|
3263
3264
|
input.source.box,
|
|
3264
3265
|
input.target.box,
|
|
@@ -3367,7 +3368,7 @@ function routeEdge(input) {
|
|
|
3367
3368
|
const rerouted2 = greedyRerouteAroundObstacles(
|
|
3368
3369
|
candidate.points,
|
|
3369
3370
|
allObstacles,
|
|
3370
|
-
|
|
3371
|
+
maxAttempts
|
|
3371
3372
|
);
|
|
3372
3373
|
if (!routeCrossesBoxes(rerouted2, allObstacles) && !routeIntersectsEndpointInteriors(
|
|
3373
3374
|
rerouted2,
|
|
@@ -3387,7 +3388,7 @@ function routeEdge(input) {
|
|
|
3387
3388
|
const rerouted = greedyRerouteAroundObstacles(
|
|
3388
3389
|
bestPoints2,
|
|
3389
3390
|
allObstacles,
|
|
3390
|
-
3
|
|
3391
|
+
Math.min(maxAttempts, 3)
|
|
3391
3392
|
);
|
|
3392
3393
|
const reroutedAvoidsEndpointInteriors = !routeIntersectsEndpointInteriors(
|
|
3393
3394
|
rerouted,
|
|
@@ -3422,7 +3423,7 @@ function routeEdge(input) {
|
|
|
3422
3423
|
const rerouted = greedyRerouteAroundObstacles(
|
|
3423
3424
|
candidate.points,
|
|
3424
3425
|
allObstacles,
|
|
3425
|
-
|
|
3426
|
+
maxAttempts
|
|
3426
3427
|
);
|
|
3427
3428
|
if (!routeCrossesBoxes(rerouted, allObstacles)) {
|
|
3428
3429
|
return {
|
|
@@ -3439,7 +3440,7 @@ function routeEdge(input) {
|
|
|
3439
3440
|
bestPoints2 = greedyRerouteAroundObstacles(
|
|
3440
3441
|
candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
|
|
3441
3442
|
allObstacles,
|
|
3442
|
-
|
|
3443
|
+
maxAttempts
|
|
3443
3444
|
);
|
|
3444
3445
|
}
|
|
3445
3446
|
diagnostics.push({
|
|
@@ -3464,7 +3465,7 @@ function routeEdge(input) {
|
|
|
3464
3465
|
const rerouted = greedyRerouteAroundObstacles(
|
|
3465
3466
|
candidate.points,
|
|
3466
3467
|
allObstacles,
|
|
3467
|
-
|
|
3468
|
+
maxAttempts
|
|
3468
3469
|
);
|
|
3469
3470
|
if (!routeCrossesBoxes(rerouted, allObstacles)) {
|
|
3470
3471
|
return {
|
|
@@ -3481,7 +3482,7 @@ function routeEdge(input) {
|
|
|
3481
3482
|
bestPoints = greedyRerouteAroundObstacles(
|
|
3482
3483
|
candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
|
|
3483
3484
|
allObstacles,
|
|
3484
|
-
|
|
3485
|
+
maxAttempts
|
|
3485
3486
|
);
|
|
3486
3487
|
}
|
|
3487
3488
|
diagnostics.push({
|
|
@@ -4316,7 +4317,9 @@ function solveDiagram(diagram, options = {}) {
|
|
|
4316
4317
|
...baseTextAnnotations.map((annotation) => annotation.box),
|
|
4317
4318
|
...frameTextAnnotation.map((annotation) => annotation.box)
|
|
4318
4319
|
],
|
|
4319
|
-
options.textMeasurer
|
|
4320
|
+
options.textMeasurer,
|
|
4321
|
+
options.labelPlacement,
|
|
4322
|
+
options.labelOffset
|
|
4320
4323
|
);
|
|
4321
4324
|
const textAnnotations = [
|
|
4322
4325
|
...baseTextAnnotations,
|
|
@@ -6254,7 +6257,8 @@ function coordinateBaseTextAnnotations(input) {
|
|
|
6254
6257
|
}
|
|
6255
6258
|
return annotations;
|
|
6256
6259
|
}
|
|
6257
|
-
function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
|
|
6260
|
+
function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer, labelPlacement, labelOffset3) {
|
|
6261
|
+
const labelBaseOffset = labelPlacement === "beside" ? labelOffset3 ?? 16 : 10;
|
|
6258
6262
|
const measurer = textMeasurer ?? createDefaultTextMeasurer();
|
|
6259
6263
|
const annotations = [];
|
|
6260
6264
|
const placedLabelBoxes = [];
|
|
@@ -6281,7 +6285,8 @@ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
|
|
|
6281
6285
|
layout2,
|
|
6282
6286
|
edges,
|
|
6283
6287
|
obstacleBoxes,
|
|
6284
|
-
placedLabelBoxes
|
|
6288
|
+
placedLabelBoxes,
|
|
6289
|
+
labelBaseOffset
|
|
6285
6290
|
);
|
|
6286
6291
|
placedLabelBoxes.push({
|
|
6287
6292
|
x: center.x - layout2.box.width / 2,
|
|
@@ -6565,8 +6570,8 @@ function fallbackLabelLayout(text) {
|
|
|
6565
6570
|
diagnostics: []
|
|
6566
6571
|
};
|
|
6567
6572
|
}
|
|
6568
|
-
function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes) {
|
|
6569
|
-
const placement = labelPlacementOnPolyline2(edge.points);
|
|
6573
|
+
function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes, baseOffset = 10) {
|
|
6574
|
+
const placement = labelPlacementOnPolyline2(edge.points, baseOffset);
|
|
6570
6575
|
if (placement === void 0) {
|
|
6571
6576
|
return { x: 0, y: 0 };
|
|
6572
6577
|
}
|
|
@@ -6711,10 +6716,10 @@ function edgeLabelAnchorCandidates(points, placement, layout2) {
|
|
|
6711
6716
|
}
|
|
6712
6717
|
return candidates;
|
|
6713
6718
|
}
|
|
6714
|
-
function labelPlacementOnPolyline2(points) {
|
|
6715
|
-
return labelSegmentOnPolyline(points)?.placement;
|
|
6719
|
+
function labelPlacementOnPolyline2(points, baseOffset = 10) {
|
|
6720
|
+
return labelSegmentOnPolyline(points, baseOffset)?.placement;
|
|
6716
6721
|
}
|
|
6717
|
-
function labelSegmentOnPolyline(points) {
|
|
6722
|
+
function labelSegmentOnPolyline(points, baseOffset = 10) {
|
|
6718
6723
|
const segments = nonZeroSegments2(points);
|
|
6719
6724
|
const totalLength = segments.reduce(
|
|
6720
6725
|
(sum, segment) => sum + segment.length,
|
|
@@ -6729,7 +6734,7 @@ function labelSegmentOnPolyline(points) {
|
|
|
6729
6734
|
const ratio = remaining / segment.length;
|
|
6730
6735
|
const x = segment.start.x + (segment.end.x - segment.start.x) * ratio;
|
|
6731
6736
|
const y = segment.start.y + (segment.end.y - segment.start.y) * ratio;
|
|
6732
|
-
const offset2 = labelOffset2(segment);
|
|
6737
|
+
const offset2 = labelOffset2(segment, baseOffset);
|
|
6733
6738
|
return {
|
|
6734
6739
|
start: segment.start,
|
|
6735
6740
|
end: segment.end,
|
|
@@ -6792,8 +6797,8 @@ function labelPlacementAtRatio(points, ratio, totalLength) {
|
|
|
6792
6797
|
}
|
|
6793
6798
|
return void 0;
|
|
6794
6799
|
}
|
|
6795
|
-
function labelOffset2(segment) {
|
|
6796
|
-
const offset =
|
|
6800
|
+
function labelOffset2(segment, baseOffset = 10) {
|
|
6801
|
+
const offset = baseOffset;
|
|
6797
6802
|
const dx = segment.end.x - segment.start.x;
|
|
6798
6803
|
const dy = segment.end.y - segment.start.y;
|
|
6799
6804
|
return {
|