2222 _node_label_clearance ,
2323 _self_loop_hover_label_text ,
2424)
25+ from .label_descriptors import _TextLabelDescriptor
2526from .plotter import _PlotAdapter
2627from .scene_state import _RenderedEdgeGeometry
2728from .vectors import _perpendicular_2d
@@ -119,6 +120,7 @@ def _draw_dangling_edge_labels(
119120 ax : Any ,
120121 scale : float ,
121122 zorder_label : float | None = None ,
123+ label_sink : list [_TextLabelDescriptor ] | None = None ,
122124) -> None :
123125 if not edge .label and not config .hover_labels :
124126 return
@@ -151,6 +153,11 @@ def _draw_dangling_edge_labels(
151153 return
152154
153155 raw_label = edge .label
156+ stub_segment = np .stack ([np .asarray (start , dtype = float ), np .asarray (end , dtype = float )], axis = 0 )
157+ stub_length = _polyline_arc_length_total (stub_segment )
158+ distance_from_tip = float (_PHYS_DANGLING_2D_FRAC_FROM_TIP ) * stub_length
159+ point , tangent = _point_tangent_along_polyline_from_end (stub_segment , distance_from_tip )
160+
154161 fontsize = _edge_index_fontsize_for_bond (
155162 raw_label ,
156163 bond_start = start ,
@@ -166,10 +173,6 @@ def _draw_dangling_edge_labels(
166173 bbox_pad = p .index_bbox_pad ,
167174 zorder = zorder_label ,
168175 )
169- stub_segment = np .stack ([np .asarray (start , dtype = float ), np .asarray (end , dtype = float )], axis = 0 )
170- stub_length = _polyline_arc_length_total (stub_segment )
171- distance_from_tip = float (_PHYS_DANGLING_2D_FRAC_FROM_TIP ) * stub_length
172- point , tangent = _point_tangent_along_polyline_from_end (stub_segment , distance_from_tip )
173176 if dimensions == 2 :
174177 start_2d = np .asarray (start [:2 ], dtype = float )
175178 end_2d = np .asarray (end [:2 ], dtype = float )
@@ -203,11 +206,18 @@ def _draw_dangling_edge_labels(
203206 scale = scale ,
204207 fontsize_pt = float (fontsize ),
205208 )
206- plotter .plot_text (
207- label_pos ,
208- format_tensor_node_label (raw_label ),
209- ** {** text_kwargs , ** align_kwargs },
210- )
209+ formatted = format_tensor_node_label (raw_label )
210+ kwargs = {** text_kwargs , ** align_kwargs }
211+ if label_sink is not None :
212+ label_sink .append (
213+ _TextLabelDescriptor (
214+ position = np .asarray (label_pos , dtype = float ).copy (),
215+ text = formatted ,
216+ kwargs = dict (kwargs ),
217+ )
218+ )
219+ return
220+ plotter .plot_text (label_pos , formatted , ** kwargs )
211221
212222
213223def _draw_self_loop_edge (
@@ -302,6 +312,7 @@ def _draw_self_loop_edge_labels(
302312 ax : Any ,
303313 scale : float ,
304314 zorder_label : float | None = None ,
315+ label_sink : list [_TextLabelDescriptor ] | None = None ,
305316) -> None :
306317 hover_targets = getattr (plotter , "_hover_edge_targets" , None )
307318 if config .hover_labels and hover_targets is not None :
@@ -391,11 +402,22 @@ def _draw_self_loop_edge_labels(
391402 dimensions = dimensions ,
392403 ),
393404 }
394- plotter .plot_text (
395- np .asarray (q_a , dtype = float ) + offset_a ,
396- format_tensor_node_label (caption_a ),
397- ** text_kwargs_a ,
398- )
405+ position_a = np .asarray (q_a , dtype = float ) + offset_a
406+ formatted_a = format_tensor_node_label (caption_a )
407+ if label_sink is not None :
408+ label_sink .append (
409+ _TextLabelDescriptor (
410+ position = np .asarray (position_a , dtype = float ).copy (),
411+ text = formatted_a ,
412+ kwargs = dict (text_kwargs_a ),
413+ )
414+ )
415+ else :
416+ plotter .plot_text (
417+ position_a ,
418+ formatted_a ,
419+ ** text_kwargs_a ,
420+ )
399421 if caption_b :
400422 offset_b = (
401423 - direction_unit
@@ -433,9 +455,20 @@ def _draw_self_loop_edge_labels(
433455 dimensions = dimensions ,
434456 ),
435457 }
458+ formatted_b = format_tensor_node_label (caption_b )
459+ position_b = np .asarray (q_b , dtype = float ) + offset_b
460+ if label_sink is not None :
461+ label_sink .append (
462+ _TextLabelDescriptor (
463+ position = np .asarray (position_b , dtype = float ).copy (),
464+ text = formatted_b ,
465+ kwargs = dict (text_kwargs_b ),
466+ )
467+ )
468+ return
436469 plotter .plot_text (
437- np . asarray ( q_b , dtype = float ) + offset_b ,
438- format_tensor_node_label ( caption_b ) ,
470+ position_b ,
471+ formatted_b ,
439472 ** text_kwargs_b ,
440473 )
441474
0 commit comments