@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/index.cjs CHANGED
@@ -3862,6 +3862,7 @@ function routeEdge(input) {
3862
3862
  const diagnostics = [];
3863
3863
  const softObstacles = input.obstacles ?? [];
3864
3864
  const hardObstacles = input.hardObstacles ?? [];
3865
+ const maxAttempts = input.maxRoutingAttempts ?? 5;
3865
3866
  const defaultAnchors = defaultAnchorsForGeometry(
3866
3867
  input.source.box,
3867
3868
  input.target.box,
@@ -3970,7 +3971,7 @@ function routeEdge(input) {
3970
3971
  const rerouted2 = greedyRerouteAroundObstacles(
3971
3972
  candidate.points,
3972
3973
  allObstacles,
3973
- 3
3974
+ maxAttempts
3974
3975
  );
3975
3976
  if (!routeCrossesBoxes(rerouted2, allObstacles) && !routeIntersectsEndpointInteriors(
3976
3977
  rerouted2,
@@ -3990,7 +3991,7 @@ function routeEdge(input) {
3990
3991
  const rerouted = greedyRerouteAroundObstacles(
3991
3992
  bestPoints2,
3992
3993
  allObstacles,
3993
- 3
3994
+ Math.min(maxAttempts, 3)
3994
3995
  );
3995
3996
  const reroutedAvoidsEndpointInteriors = !routeIntersectsEndpointInteriors(
3996
3997
  rerouted,
@@ -4025,7 +4026,7 @@ function routeEdge(input) {
4025
4026
  const rerouted = greedyRerouteAroundObstacles(
4026
4027
  candidate.points,
4027
4028
  allObstacles,
4028
- 5
4029
+ maxAttempts
4029
4030
  );
4030
4031
  if (!routeCrossesBoxes(rerouted, allObstacles)) {
4031
4032
  return {
@@ -4042,7 +4043,7 @@ function routeEdge(input) {
4042
4043
  bestPoints2 = greedyRerouteAroundObstacles(
4043
4044
  candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
4044
4045
  allObstacles,
4045
- 5
4046
+ maxAttempts
4046
4047
  );
4047
4048
  }
4048
4049
  diagnostics.push({
@@ -4067,7 +4068,7 @@ function routeEdge(input) {
4067
4068
  const rerouted = greedyRerouteAroundObstacles(
4068
4069
  candidate.points,
4069
4070
  allObstacles,
4070
- 5
4071
+ maxAttempts
4071
4072
  );
4072
4073
  if (!routeCrossesBoxes(rerouted, allObstacles)) {
4073
4074
  return {
@@ -4084,7 +4085,7 @@ function routeEdge(input) {
4084
4085
  bestPoints = greedyRerouteAroundObstacles(
4085
4086
  candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
4086
4087
  allObstacles,
4087
- 5
4088
+ maxAttempts
4088
4089
  );
4089
4090
  }
4090
4091
  diagnostics.push({
@@ -4919,7 +4920,9 @@ function solveDiagram(diagram, options = {}) {
4919
4920
  ...baseTextAnnotations.map((annotation) => annotation.box),
4920
4921
  ...frameTextAnnotation.map((annotation) => annotation.box)
4921
4922
  ],
4922
- options.textMeasurer
4923
+ options.textMeasurer,
4924
+ options.labelPlacement,
4925
+ options.labelOffset
4923
4926
  );
4924
4927
  const textAnnotations = [
4925
4928
  ...baseTextAnnotations,
@@ -6860,7 +6863,8 @@ function coordinateBaseTextAnnotations(input) {
6860
6863
  }
6861
6864
  return annotations;
6862
6865
  }
6863
- function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
6866
+ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer, labelPlacement, labelOffset3) {
6867
+ const labelBaseOffset = labelPlacement === "beside" ? labelOffset3 ?? 16 : 10;
6864
6868
  const measurer = textMeasurer ?? createDefaultTextMeasurer();
6865
6869
  const annotations = [];
6866
6870
  const placedLabelBoxes = [];
@@ -6887,7 +6891,8 @@ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
6887
6891
  layout2,
6888
6892
  edges,
6889
6893
  obstacleBoxes,
6890
- placedLabelBoxes
6894
+ placedLabelBoxes,
6895
+ labelBaseOffset
6891
6896
  );
6892
6897
  placedLabelBoxes.push({
6893
6898
  x: center.x - layout2.box.width / 2,
@@ -7171,8 +7176,8 @@ function fallbackLabelLayout(text) {
7171
7176
  diagnostics: []
7172
7177
  };
7173
7178
  }
7174
- function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes) {
7175
- const placement = labelPlacementOnPolyline2(edge.points);
7179
+ function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes, baseOffset = 10) {
7180
+ const placement = labelPlacementOnPolyline2(edge.points, baseOffset);
7176
7181
  if (placement === void 0) {
7177
7182
  return { x: 0, y: 0 };
7178
7183
  }
@@ -7317,10 +7322,10 @@ function edgeLabelAnchorCandidates(points, placement, layout2) {
7317
7322
  }
7318
7323
  return candidates;
7319
7324
  }
7320
- function labelPlacementOnPolyline2(points) {
7321
- return labelSegmentOnPolyline(points)?.placement;
7325
+ function labelPlacementOnPolyline2(points, baseOffset = 10) {
7326
+ return labelSegmentOnPolyline(points, baseOffset)?.placement;
7322
7327
  }
7323
- function labelSegmentOnPolyline(points) {
7328
+ function labelSegmentOnPolyline(points, baseOffset = 10) {
7324
7329
  const segments = nonZeroSegments2(points);
7325
7330
  const totalLength = segments.reduce(
7326
7331
  (sum, segment) => sum + segment.length,
@@ -7335,7 +7340,7 @@ function labelSegmentOnPolyline(points) {
7335
7340
  const ratio = remaining / segment.length;
7336
7341
  const x = segment.start.x + (segment.end.x - segment.start.x) * ratio;
7337
7342
  const y = segment.start.y + (segment.end.y - segment.start.y) * ratio;
7338
- const offset2 = labelOffset2(segment);
7343
+ const offset2 = labelOffset2(segment, baseOffset);
7339
7344
  return {
7340
7345
  start: segment.start,
7341
7346
  end: segment.end,
@@ -7398,8 +7403,8 @@ function labelPlacementAtRatio(points, ratio, totalLength) {
7398
7403
  }
7399
7404
  return void 0;
7400
7405
  }
7401
- function labelOffset2(segment) {
7402
- const offset = 10;
7406
+ function labelOffset2(segment, baseOffset = 10) {
7407
+ const offset = baseOffset;
7403
7408
  const dx = segment.end.x - segment.start.x;
7404
7409
  const dy = segment.end.y - segment.start.y;
7405
7410
  return {