@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/dist/cli/index.js CHANGED
@@ -3256,6 +3256,7 @@ function routeEdge(input) {
3256
3256
  const diagnostics = [];
3257
3257
  const softObstacles = input.obstacles ?? [];
3258
3258
  const hardObstacles = input.hardObstacles ?? [];
3259
+ const maxAttempts = input.maxRoutingAttempts ?? 5;
3259
3260
  const defaultAnchors = defaultAnchorsForGeometry(
3260
3261
  input.source.box,
3261
3262
  input.target.box,
@@ -3364,7 +3365,7 @@ function routeEdge(input) {
3364
3365
  const rerouted2 = greedyRerouteAroundObstacles(
3365
3366
  candidate.points,
3366
3367
  allObstacles,
3367
- 3
3368
+ maxAttempts
3368
3369
  );
3369
3370
  if (!routeCrossesBoxes(rerouted2, allObstacles) && !routeIntersectsEndpointInteriors(
3370
3371
  rerouted2,
@@ -3384,7 +3385,7 @@ function routeEdge(input) {
3384
3385
  const rerouted = greedyRerouteAroundObstacles(
3385
3386
  bestPoints2,
3386
3387
  allObstacles,
3387
- 3
3388
+ Math.min(maxAttempts, 3)
3388
3389
  );
3389
3390
  const reroutedAvoidsEndpointInteriors = !routeIntersectsEndpointInteriors(
3390
3391
  rerouted,
@@ -3419,7 +3420,7 @@ function routeEdge(input) {
3419
3420
  const rerouted = greedyRerouteAroundObstacles(
3420
3421
  candidate.points,
3421
3422
  allObstacles,
3422
- 5
3423
+ maxAttempts
3423
3424
  );
3424
3425
  if (!routeCrossesBoxes(rerouted, allObstacles)) {
3425
3426
  return {
@@ -3436,7 +3437,7 @@ function routeEdge(input) {
3436
3437
  bestPoints2 = greedyRerouteAroundObstacles(
3437
3438
  candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
3438
3439
  allObstacles,
3439
- 5
3440
+ maxAttempts
3440
3441
  );
3441
3442
  }
3442
3443
  diagnostics.push({
@@ -3461,7 +3462,7 @@ function routeEdge(input) {
3461
3462
  const rerouted = greedyRerouteAroundObstacles(
3462
3463
  candidate.points,
3463
3464
  allObstacles,
3464
- 5
3465
+ maxAttempts
3465
3466
  );
3466
3467
  if (!routeCrossesBoxes(rerouted, allObstacles)) {
3467
3468
  return {
@@ -3478,7 +3479,7 @@ function routeEdge(input) {
3478
3479
  bestPoints = greedyRerouteAroundObstacles(
3479
3480
  candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
3480
3481
  allObstacles,
3481
- 5
3482
+ maxAttempts
3482
3483
  );
3483
3484
  }
3484
3485
  diagnostics.push({
@@ -4313,7 +4314,9 @@ function solveDiagram(diagram, options = {}) {
4313
4314
  ...baseTextAnnotations.map((annotation) => annotation.box),
4314
4315
  ...frameTextAnnotation.map((annotation) => annotation.box)
4315
4316
  ],
4316
- options.textMeasurer
4317
+ options.textMeasurer,
4318
+ options.labelPlacement,
4319
+ options.labelOffset
4317
4320
  );
4318
4321
  const textAnnotations = [
4319
4322
  ...baseTextAnnotations,
@@ -6251,7 +6254,8 @@ function coordinateBaseTextAnnotations(input) {
6251
6254
  }
6252
6255
  return annotations;
6253
6256
  }
6254
- function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
6257
+ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer, labelPlacement, labelOffset3) {
6258
+ const labelBaseOffset = labelPlacement === "beside" ? labelOffset3 ?? 16 : 10;
6255
6259
  const measurer = textMeasurer ?? createDefaultTextMeasurer();
6256
6260
  const annotations = [];
6257
6261
  const placedLabelBoxes = [];
@@ -6278,7 +6282,8 @@ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
6278
6282
  layout2,
6279
6283
  edges,
6280
6284
  obstacleBoxes,
6281
- placedLabelBoxes
6285
+ placedLabelBoxes,
6286
+ labelBaseOffset
6282
6287
  );
6283
6288
  placedLabelBoxes.push({
6284
6289
  x: center.x - layout2.box.width / 2,
@@ -6562,8 +6567,8 @@ function fallbackLabelLayout(text) {
6562
6567
  diagnostics: []
6563
6568
  };
6564
6569
  }
6565
- function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes) {
6566
- const placement = labelPlacementOnPolyline2(edge.points);
6570
+ function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes, baseOffset = 10) {
6571
+ const placement = labelPlacementOnPolyline2(edge.points, baseOffset);
6567
6572
  if (placement === void 0) {
6568
6573
  return { x: 0, y: 0 };
6569
6574
  }
@@ -6708,10 +6713,10 @@ function edgeLabelAnchorCandidates(points, placement, layout2) {
6708
6713
  }
6709
6714
  return candidates;
6710
6715
  }
6711
- function labelPlacementOnPolyline2(points) {
6712
- return labelSegmentOnPolyline(points)?.placement;
6716
+ function labelPlacementOnPolyline2(points, baseOffset = 10) {
6717
+ return labelSegmentOnPolyline(points, baseOffset)?.placement;
6713
6718
  }
6714
- function labelSegmentOnPolyline(points) {
6719
+ function labelSegmentOnPolyline(points, baseOffset = 10) {
6715
6720
  const segments = nonZeroSegments2(points);
6716
6721
  const totalLength = segments.reduce(
6717
6722
  (sum, segment) => sum + segment.length,
@@ -6726,7 +6731,7 @@ function labelSegmentOnPolyline(points) {
6726
6731
  const ratio = remaining / segment.length;
6727
6732
  const x = segment.start.x + (segment.end.x - segment.start.x) * ratio;
6728
6733
  const y = segment.start.y + (segment.end.y - segment.start.y) * ratio;
6729
- const offset2 = labelOffset2(segment);
6734
+ const offset2 = labelOffset2(segment, baseOffset);
6730
6735
  return {
6731
6736
  start: segment.start,
6732
6737
  end: segment.end,
@@ -6789,8 +6794,8 @@ function labelPlacementAtRatio(points, ratio, totalLength) {
6789
6794
  }
6790
6795
  return void 0;
6791
6796
  }
6792
- function labelOffset2(segment) {
6793
- const offset = 10;
6797
+ function labelOffset2(segment, baseOffset = 10) {
6798
+ const offset = baseOffset;
6794
6799
  const dx = segment.end.x - segment.start.x;
6795
6800
  const dy = segment.end.y - segment.start.y;
6796
6801
  return {