@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.d.cts CHANGED
@@ -688,6 +688,8 @@ interface RouteEdgeInput {
688
688
  targetAnchor?: AnchorName;
689
689
  obstacles?: readonly Box[];
690
690
  hardObstacles?: readonly Box[];
691
+ /** Maximum greedy rerouting iterations (default 5). */
692
+ maxRoutingAttempts?: number;
691
693
  }
692
694
  interface RouteEdgeResult {
693
695
  points: Point[];
@@ -729,6 +731,12 @@ interface SolveDiagramOptions {
729
731
  textMeasurer?: TextMeasurer;
730
732
  /** When true, promote deliverability-breaking diagnostics to errors. */
731
733
  strict?: boolean;
734
+ /** Maximum greedy rerouting iterations per edge (default 5). */
735
+ maxRoutingAttempts?: number;
736
+ /** Edge label placement mode: "beside" offsets away from the edge, "on-path" (default) places at the midpoint. */
737
+ labelPlacement?: "beside" | "on-path";
738
+ /** Pixels to offset edge labels from the edge path when labelPlacement is "beside". */
739
+ labelOffset?: number;
732
740
  }
733
741
  interface PortShiftingOptions {
734
742
  enabled?: boolean;
package/dist/index.d.ts CHANGED
@@ -688,6 +688,8 @@ interface RouteEdgeInput {
688
688
  targetAnchor?: AnchorName;
689
689
  obstacles?: readonly Box[];
690
690
  hardObstacles?: readonly Box[];
691
+ /** Maximum greedy rerouting iterations (default 5). */
692
+ maxRoutingAttempts?: number;
691
693
  }
692
694
  interface RouteEdgeResult {
693
695
  points: Point[];
@@ -729,6 +731,12 @@ interface SolveDiagramOptions {
729
731
  textMeasurer?: TextMeasurer;
730
732
  /** When true, promote deliverability-breaking diagnostics to errors. */
731
733
  strict?: boolean;
734
+ /** Maximum greedy rerouting iterations per edge (default 5). */
735
+ maxRoutingAttempts?: number;
736
+ /** Edge label placement mode: "beside" offsets away from the edge, "on-path" (default) places at the midpoint. */
737
+ labelPlacement?: "beside" | "on-path";
738
+ /** Pixels to offset edge labels from the edge path when labelPlacement is "beside". */
739
+ labelOffset?: number;
732
740
  }
733
741
  interface PortShiftingOptions {
734
742
  enabled?: boolean;
package/dist/index.js CHANGED
@@ -3859,6 +3859,7 @@ function routeEdge(input) {
3859
3859
  const diagnostics = [];
3860
3860
  const softObstacles = input.obstacles ?? [];
3861
3861
  const hardObstacles = input.hardObstacles ?? [];
3862
+ const maxAttempts = input.maxRoutingAttempts ?? 5;
3862
3863
  const defaultAnchors = defaultAnchorsForGeometry(
3863
3864
  input.source.box,
3864
3865
  input.target.box,
@@ -3967,7 +3968,7 @@ function routeEdge(input) {
3967
3968
  const rerouted2 = greedyRerouteAroundObstacles(
3968
3969
  candidate.points,
3969
3970
  allObstacles,
3970
- 3
3971
+ maxAttempts
3971
3972
  );
3972
3973
  if (!routeCrossesBoxes(rerouted2, allObstacles) && !routeIntersectsEndpointInteriors(
3973
3974
  rerouted2,
@@ -3987,7 +3988,7 @@ function routeEdge(input) {
3987
3988
  const rerouted = greedyRerouteAroundObstacles(
3988
3989
  bestPoints2,
3989
3990
  allObstacles,
3990
- 3
3991
+ Math.min(maxAttempts, 3)
3991
3992
  );
3992
3993
  const reroutedAvoidsEndpointInteriors = !routeIntersectsEndpointInteriors(
3993
3994
  rerouted,
@@ -4022,7 +4023,7 @@ function routeEdge(input) {
4022
4023
  const rerouted = greedyRerouteAroundObstacles(
4023
4024
  candidate.points,
4024
4025
  allObstacles,
4025
- 5
4026
+ maxAttempts
4026
4027
  );
4027
4028
  if (!routeCrossesBoxes(rerouted, allObstacles)) {
4028
4029
  return {
@@ -4039,7 +4040,7 @@ function routeEdge(input) {
4039
4040
  bestPoints2 = greedyRerouteAroundObstacles(
4040
4041
  candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
4041
4042
  allObstacles,
4042
- 5
4043
+ maxAttempts
4043
4044
  );
4044
4045
  }
4045
4046
  diagnostics.push({
@@ -4064,7 +4065,7 @@ function routeEdge(input) {
4064
4065
  const rerouted = greedyRerouteAroundObstacles(
4065
4066
  candidate.points,
4066
4067
  allObstacles,
4067
- 5
4068
+ maxAttempts
4068
4069
  );
4069
4070
  if (!routeCrossesBoxes(rerouted, allObstacles)) {
4070
4071
  return {
@@ -4081,7 +4082,7 @@ function routeEdge(input) {
4081
4082
  bestPoints = greedyRerouteAroundObstacles(
4082
4083
  candidateRoutes[0]?.points ?? fallbackRoute(input, defaultAnchors),
4083
4084
  allObstacles,
4084
- 5
4085
+ maxAttempts
4085
4086
  );
4086
4087
  }
4087
4088
  diagnostics.push({
@@ -4916,7 +4917,9 @@ function solveDiagram(diagram, options = {}) {
4916
4917
  ...baseTextAnnotations.map((annotation) => annotation.box),
4917
4918
  ...frameTextAnnotation.map((annotation) => annotation.box)
4918
4919
  ],
4919
- options.textMeasurer
4920
+ options.textMeasurer,
4921
+ options.labelPlacement,
4922
+ options.labelOffset
4920
4923
  );
4921
4924
  const textAnnotations = [
4922
4925
  ...baseTextAnnotations,
@@ -6857,7 +6860,8 @@ function coordinateBaseTextAnnotations(input) {
6857
6860
  }
6858
6861
  return annotations;
6859
6862
  }
6860
- function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
6863
+ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer, labelPlacement, labelOffset3) {
6864
+ const labelBaseOffset = labelPlacement === "beside" ? labelOffset3 ?? 16 : 10;
6861
6865
  const measurer = textMeasurer ?? createDefaultTextMeasurer();
6862
6866
  const annotations = [];
6863
6867
  const placedLabelBoxes = [];
@@ -6884,7 +6888,8 @@ function coordinateEdgeTextAnnotations(edges, obstacleBoxes, textMeasurer) {
6884
6888
  layout2,
6885
6889
  edges,
6886
6890
  obstacleBoxes,
6887
- placedLabelBoxes
6891
+ placedLabelBoxes,
6892
+ labelBaseOffset
6888
6893
  );
6889
6894
  placedLabelBoxes.push({
6890
6895
  x: center.x - layout2.box.width / 2,
@@ -7168,8 +7173,8 @@ function fallbackLabelLayout(text) {
7168
7173
  diagnostics: []
7169
7174
  };
7170
7175
  }
7171
- function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes) {
7172
- const placement = labelPlacementOnPolyline2(edge.points);
7176
+ function edgeLabelAnchor(edge, layout2, edges, obstacleBoxes, placedLabelBoxes, baseOffset = 10) {
7177
+ const placement = labelPlacementOnPolyline2(edge.points, baseOffset);
7173
7178
  if (placement === void 0) {
7174
7179
  return { x: 0, y: 0 };
7175
7180
  }
@@ -7314,10 +7319,10 @@ function edgeLabelAnchorCandidates(points, placement, layout2) {
7314
7319
  }
7315
7320
  return candidates;
7316
7321
  }
7317
- function labelPlacementOnPolyline2(points) {
7318
- return labelSegmentOnPolyline(points)?.placement;
7322
+ function labelPlacementOnPolyline2(points, baseOffset = 10) {
7323
+ return labelSegmentOnPolyline(points, baseOffset)?.placement;
7319
7324
  }
7320
- function labelSegmentOnPolyline(points) {
7325
+ function labelSegmentOnPolyline(points, baseOffset = 10) {
7321
7326
  const segments = nonZeroSegments2(points);
7322
7327
  const totalLength = segments.reduce(
7323
7328
  (sum, segment) => sum + segment.length,
@@ -7332,7 +7337,7 @@ function labelSegmentOnPolyline(points) {
7332
7337
  const ratio = remaining / segment.length;
7333
7338
  const x = segment.start.x + (segment.end.x - segment.start.x) * ratio;
7334
7339
  const y = segment.start.y + (segment.end.y - segment.start.y) * ratio;
7335
- const offset2 = labelOffset2(segment);
7340
+ const offset2 = labelOffset2(segment, baseOffset);
7336
7341
  return {
7337
7342
  start: segment.start,
7338
7343
  end: segment.end,
@@ -7395,8 +7400,8 @@ function labelPlacementAtRatio(points, ratio, totalLength) {
7395
7400
  }
7396
7401
  return void 0;
7397
7402
  }
7398
- function labelOffset2(segment) {
7399
- const offset = 10;
7403
+ function labelOffset2(segment, baseOffset = 10) {
7404
+ const offset = baseOffset;
7400
7405
  const dx = segment.end.x - segment.start.x;
7401
7406
  const dy = segment.end.y - segment.start.y;
7402
7407
  return {