| 115 | |
| 116 | |
| 117 | class BboxConnector(Patch): |
| 118 | @staticmethod |
| 119 | def get_bbox_edge_pos(bbox, loc): |
| 120 | """ |
| 121 | Return the ``(x, y)`` coordinates of corner *loc* of *bbox*; parameters |
| 122 | behave as documented for the `.BboxConnector` constructor. |
| 123 | """ |
| 124 | x0, y0, x1, y1 = bbox.extents |
| 125 | if loc == 1: |
| 126 | return x1, y1 |
| 127 | elif loc == 2: |
| 128 | return x0, y1 |
| 129 | elif loc == 3: |
| 130 | return x0, y0 |
| 131 | elif loc == 4: |
| 132 | return x1, y0 |
| 133 | |
| 134 | @staticmethod |
| 135 | def connect_bbox(bbox1, bbox2, loc1, loc2=None): |
| 136 | """ |
| 137 | Construct a `.Path` connecting corner *loc1* of *bbox1* to corner |
| 138 | *loc2* of *bbox2*, where parameters behave as documented as for the |
| 139 | `.BboxConnector` constructor. |
| 140 | """ |
| 141 | if isinstance(bbox1, Rectangle): |
| 142 | bbox1 = TransformedBbox(Bbox.unit(), bbox1.get_transform()) |
| 143 | if isinstance(bbox2, Rectangle): |
| 144 | bbox2 = TransformedBbox(Bbox.unit(), bbox2.get_transform()) |
| 145 | if loc2 is None: |
| 146 | loc2 = loc1 |
| 147 | x1, y1 = BboxConnector.get_bbox_edge_pos(bbox1, loc1) |
| 148 | x2, y2 = BboxConnector.get_bbox_edge_pos(bbox2, loc2) |
| 149 | return Path([[x1, y1], [x2, y2]]) |
| 150 | |
| 151 | @_docstring.interpd |
| 152 | def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs): |
| 153 | """ |
| 154 | Connect two bboxes with a straight line. |
| 155 | |
| 156 | Parameters |
| 157 | ---------- |
| 158 | bbox1, bbox2 : `~matplotlib.transforms.Bbox` |
| 159 | Bounding boxes to connect. |
| 160 | |
| 161 | loc1, loc2 : {1, 2, 3, 4} |
| 162 | Corner of *bbox1* and *bbox2* to draw the line. Valid values are:: |
| 163 | |
| 164 | 'upper right' : 1, |
| 165 | 'upper left' : 2, |
| 166 | 'lower left' : 3, |
| 167 | 'lower right' : 4 |
| 168 | |
| 169 | *loc2* is optional and defaults to *loc1*. |
| 170 | |
| 171 | **kwargs |
| 172 | Patch properties for the line drawn. Valid arguments include: |
| 173 | |
| 174 | %(Patch:kwdoc)s |
no outgoing calls
no test coverage detected
searching dependent graphs…