@@ -2543,7 +2543,9 @@ def __call__(self, x0, y0, width, height, mutation_size):
2543
2543
dx = (y1 - y0 ) / 2
2544
2544
dxx = dx / 2
2545
2545
2546
- x0 += pad / 1.4 # adjust by ~sqrt(2)
2546
+ # Pad text to position text and its padding margin exactly inside arrow tail
2547
+ padding_offset = (0.5 * pad ) + (0.25 * mutation_size )
2548
+ x0 -= padding_offset
2547
2549
2548
2550
# The width adjustment is the distance that must be subtracted from
2549
2551
# y0 and added to y1 to reach the non-tip vertices of the head.
@@ -2567,26 +2569,14 @@ def __call__(self, x0, y0, width, height, mutation_size):
2567
2569
# (dx+width_adjustment)/(dxx+angle_adjustment).
2568
2570
angle_adjustment = ((dx + width_adjustment ) / tan_half_angle ) - dxx
2569
2571
2570
- # Check padding; the left end of the text should have a minimum
2571
- # clearance of pad from the head
2572
- if - width_adjustment < pad :
2573
- # Only do this if the text fits into the head
2574
- text_clearance = (width_adjustment / tan_half_angle ) + \
2575
- pad * ((1 / tan_half_angle ) - 1 )
2572
+ # If there is sufficient space available, shorten the arrow tail to push
2573
+ # some of the text padding margin into the head
2574
+ if self .head_width > 1 and pad * tan_half_angle < width_adjustment :
2575
+ # Pad text into head
2576
+ x0 += pad
2576
2577
2577
- if text_clearance < pad :
2578
- # Lengthen arrow body to accommodate text
2579
- x0 += text_clearance - pad
2580
- else :
2581
- # Pad away from head straight-edge
2582
-
2583
- a , b = 1.214 , 0.250 # Empirical factors
2584
- padding_offset = (a * pad ) + (b * mutation_size )
2585
-
2586
- x0 -= padding_offset
2587
-
2588
- return Path ._create_closed (
2589
- [(x0 + dxx , y0 ),
2578
+ return Path ._create_closed ([
2579
+ (x0 + dxx , y0 ),
2590
2580
(x1 , y0 ),
2591
2581
(x1 , y1 ),
2592
2582
(x0 + dxx , y1 ),
@@ -2598,14 +2588,6 @@ def __call__(self, x0, y0, width, height, mutation_size):
2598
2588
else :
2599
2589
# Reversed arrow head (>---)
2600
2590
2601
- # Distance to pad x0 by, in order to ensure consistent spacing
2602
- a , b = 1.214 , 0.250 # Empirical factors
2603
- padding_offset = (a * pad ) + (b * mutation_size )
2604
-
2605
- # No arrow head available for enclosed text to spill over into; add
2606
- # padding to left of text
2607
- x0 -= padding_offset
2608
-
2609
2591
# tan(1/2 * angle subtended by arrow tip)
2610
2592
tan_half_angle = - np .tan (self .head_angle * (math .pi / 360 ))
2611
2593
@@ -2704,7 +2686,10 @@ def __call__(self, x0, y0, width, height, mutation_size):
2704
2686
dx = (y1 - y0 ) / 2
2705
2687
dxx = dx / 2
2706
2688
2707
- x0 += pad / 1.4 # adjust by ~sqrt(2)
2689
+ # Pad text
2690
+ padding_offset = (0.5 * pad ) + (0.25 * mutation_size )
2691
+ x0 -= padding_offset
2692
+ x1 += padding_offset
2708
2693
2709
2694
# The width adjustment is the distance that must be subtracted from
2710
2695
# y0 and added to y1 to reach the non-tip vertices of the head.
@@ -2728,25 +2713,12 @@ def __call__(self, x0, y0, width, height, mutation_size):
2728
2713
# (dx+width_adjustment)/(dxx+angle_adjustment).
2729
2714
angle_adjustment = ((dx + width_adjustment ) / tan_half_angle ) - dxx
2730
2715
2731
- # Check padding; the ends of the text should have a minimum
2732
- # clearance of pad from the heads
2733
- if - width_adjustment < pad :
2734
- # Only do this if the text fits into the head
2735
- text_clearance = (width_adjustment / tan_half_angle ) + \
2736
- pad * ((1 / tan_half_angle ) - 1 )
2737
-
2738
- if text_clearance < pad :
2739
- # Lengthen arrow body to accommodate text
2740
- x0 -= pad - text_clearance
2741
- x1 += pad - text_clearance
2742
- else :
2743
- # Pad away from head straight-edges
2744
-
2745
- a , b = 1.214 , 0.250 # Empirical factors
2746
- padding_offset = (a * pad ) + (b * mutation_size )
2747
-
2748
- x0 -= padding_offset
2749
- x1 += padding_offset
2716
+ # If there is sufficient space available, shorten the arrow tail to push
2717
+ # some of the text padding margin into the heads
2718
+ if self .head_width > 1 and pad * tan_half_angle < width_adjustment :
2719
+ # Pad text into heads
2720
+ x0 += pad
2721
+ x1 -= pad
2750
2722
2751
2723
return Path ._create_closed ([
2752
2724
(x0 + dxx , y0 ),
@@ -2764,15 +2736,6 @@ def __call__(self, x0, y0, width, height, mutation_size):
2764
2736
else :
2765
2737
# Reversed arrow heads (>---<)
2766
2738
2767
- # Distance to pad x0 and x1 by, in order to ensure consistent spacing
2768
- a , b = 1.214 , 0.250 # Empirical factors
2769
- padding_offset = (a * pad ) + (b * mutation_size )
2770
-
2771
- # No arrow head available for enclosed text to spill over into; add
2772
- # padding to both sides of text
2773
- x0 -= padding_offset
2774
- x1 += padding_offset
2775
-
2776
2739
# tan(1/2 * angle subtended by arrow tip)
2777
2740
tan_half_angle = - np .tan (self .head_angle * (math .pi / 360 ))
2778
2741
0 commit comments