@@ -2545,6 +2545,92 @@ def connect(self, posA, posB):
25452545
25462546 _style_list ["arc" ] = Arc
25472547
2548+
2549+
2550+ class Bar (_Base ):
2551+ """
2552+ A line with *angle* between A and B with *armA* and
2553+ *armB*. One of the arm is extend so that they are connected in
2554+ a right angle. The length of armA is determined by (*armA*
2555+ + *fraction* x AB distance). Same for armB.
2556+ """
2557+
2558+ def __init__ (self , armA = 0. , armB = 0. , fraction = 0.3 , angle = None ):
2559+ """
2560+ *armA* : minimum length of armA
2561+ *armB* : minimum length of armB
2562+ *fraction* : a fraction of the distance between two points that will be added to armA and armB.
2563+ *angle* : anlge of the connecting line (if None, parallel to A and B)
2564+ """
2565+ self .armA = armA
2566+ self .armB = armB
2567+ self .fraction = fraction
2568+ self .angle = angle
2569+
2570+ def connect (self , posA , posB ):
2571+ x1 , y1 = posA
2572+ x20 , y20 = x2 , y2 = posB
2573+
2574+ x12 , y12 = (x1 + x2 )/ 2. , (y1 + y2 )/ 2.
2575+
2576+ theta1 = math .atan2 (y2 - y1 , x2 - x1 )
2577+ dx , dy = x2 - x1 , y2 - y1
2578+ dd = (dx * dx + dy * dy )** .5
2579+ ddx , ddy = dx / dd , dy / dd
2580+
2581+ armA , armB = self .armA , self .armB
2582+
2583+ if self .angle is not None :
2584+ #angle = self.angle % 180.
2585+ #if angle < 0. or angle > 180.:
2586+ # angle
2587+ theta0 = (self .angle % 180. )/ 180. * math .pi
2588+ #theta0 = (((self.angle+90)%180.) - 90.)/180.*math.pi
2589+ dtheta = theta1 - theta0
2590+ dl = dd * math .sin (dtheta )
2591+
2592+ dL = dd * math .cos (dtheta )
2593+
2594+ #x2, y2 = x2 + dl*ddy, y2 - dl*ddx
2595+ x2 , y2 = x1 + dL * math .cos (theta0 ), y1 + dL * math .sin (theta0 )
2596+
2597+ armB = armB - dl
2598+
2599+ # update
2600+ dx , dy = x2 - x1 , y2 - y1
2601+ dd2 = (dx * dx + dy * dy )** .5
2602+ ddx , ddy = dx / dd2 , dy / dd2
2603+
2604+ else :
2605+ dl = 0.
2606+
2607+ #if armA > armB:
2608+ # armB = armA + dl
2609+ #else:
2610+ # armA = armB - dl
2611+
2612+
2613+ arm = max (armA , armB )
2614+ f = self .fraction * dd + arm
2615+ #fB = self.fraction*dd + armB
2616+
2617+ cx1 , cy1 = x1 + f * ddy , y1 - f * ddx
2618+ cx2 , cy2 = x2 + f * ddy , y2 - f * ddx
2619+
2620+ vertices = [(x1 , y1 ),
2621+ (cx1 , cy1 ),
2622+ (cx2 , cy2 ),
2623+ (x20 , y20 )]
2624+ codes = [Path .MOVETO ,
2625+ Path .LINETO ,
2626+ Path .LINETO ,
2627+ Path .LINETO ]
2628+
2629+ return Path (vertices , codes )
2630+
2631+ _style_list ["bar" ] = Bar
2632+
2633+
25482634 __doc__ = cbook .dedent (__doc__ ) % \
25492635 {"AvailableConnectorstyles" : _pprint_styles (_style_list )}
25502636
0 commit comments