
    z	iӚ                         S r SSKJr  SSKJrJr  SSKJr  SSKr	SSK
r
S/rSS jrSS jr            SS	 jr                   SS
 jr           SS jr             SS jrSS jrg)z'Draw a rustworkx graph with matplotlib.    )Iterable)islicecycle)NumberNmpl_drawc                     SSK Jn  Uc  UR                  5       nOUR	                  5       nUR                  S5        Uc3  UR                  (       a  UR                  5       nOUR                  S5      n[        U 4XX4S.UD6  UR                  5         UR                  5         UR                  5       (       a  Uc  U$ g! [         a  n[        S5      UeSnAff = f)a  Draw a graph with Matplotlib.

.. note::

    Matplotlib is an optional dependency and will not be installed with
    rustworkx by default. If you intend to use this function make sure that
    you install matplotlib with either ``pip install matplotlib`` or
    ``pip install 'rustworkx[mpl]'``

:param graph: A rustworkx graph, either a :class:`~rustworkx.PyGraph` or a
    :class:`~rustworkx.PyDiGraph`.
:param dict pos: An optional dictionary (or
    a :class:`~rustworkx.Pos2DMapping` object) with nodes as keys and
    positions as values. If not specified a spring layout positioning will
    be computed. See `layout_functions` for functions that compute
    node positions.
:param matplotlib.Axes ax: An optional Matplotlib Axes object to draw the
    graph in.
:param bool arrows: For :class:`~rustworkx.PyDiGraph` objects if ``True``
    draw arrowheads. (defaults to ``True``) Note, that the Arrows will
    be the same color as edges.
:param str arrowstyle: An optional string for directed graphs to choose
    the style of the arrowsheads. See
    :class:`matplotlib.patches.ArrowStyle` for more options. By default the
    value is set to ``'-\|>'``.
:param int arrow_size: For directed graphs, choose the size of the arrow
    head's length and width. See
    :class:`matplotlib.patches.FancyArrowPatch` attribute and constructor
    kwarg ``mutation_scale`` for more info. Defaults to 10.
:param bool with_labels: Set to ``True`` to draw labels on the nodes. Edge
    labels will only be drawn if the ``edge_labels`` parameter is set to a
    function. Defaults to ``False``.
:param list node_list: An optional list of node indices in the graph to
    draw. If not specified all nodes will be drawn.
:param list edge_list: An option list of edges in the graph to draw. If not
    specified all edges will be drawn
:param int|list node_size: Optional size of nodes. If an array is
    specified it must be the same length as node_list. Defaults to 300
:param node_color: Optional node color. Can be a single color or
    a sequence of colors with the same length as node_list. Color can be
    string or rgb (or rgba) tuple of floats from 0-1. If numeric values
    are specified they will be mapped to colors using the ``cmap`` and
    ``vmin``,``vmax`` parameters. See :func:`matplotlib.scatter` for more
    details. Defaults to ``'#1f78b4'``)
:param str node_shape: The optional shape node. The specification is the
    same as the :func:`matplotlib.pyplot.scatter` function's ``marker``
    kwarg, valid options are one of
    ``['s', 'o', '^', '>', 'v', '<', 'd', 'p', 'h', '8']``. Defaults to
    ``'o'``
:param float alpha: Optional value for node and edge transparency
:param matplotlib.colors.Colormap cmap: An optional Matplotlib colormap
    object for mapping intensities of nodes
:param float vmin: Optional minimum value for node colormap scaling
:param float vmax: Optional minimum value for node colormap scaling
:param float|sequence linewidths: An optional line width for symbol
    borders. If a sequence is specified it must be the same length as
    node_list. Defaults to 1.0
:param float|sequence width: An optional width to use for edges. Can
    either be a float or sequence  of floats. If a sequence is specified
    it must be the same length as node_list. Defaults to 1.0
:param str|sequence edge_color: color or array of colors (default='k')
    Edge color. Can be a single color or a sequence of colors with the same
    length as edge_list. Color can be string or rgb (or rgba) tuple of
    floats from 0-1. If numeric values are specified they will be
    mapped to colors using the ``edge_cmap`` and ``edge_vmin``,
    ``edge_vmax`` parameters.
:param matplotlib.colors.Colormap edge_cmap: An optional Matplotlib
    colormap for mapping intensities of edges.
:param float edge_vmin: Optional minimum value for edge colormap scaling
:param float edge_vmax: Optional maximum value for node colormap scaling
:param str style: An optional string to specify the edge line style.
    For example, ``'-'``, ``'--'``, ``'-.'``, ``':'`` or words like
    ``'solid'`` or ``'dashed'``. See the
    :class:`matplotlib.patches.FancyArrowPatch` attribute and kwarg
    ``linestyle`` for more details. Defaults to ``'solid'``.
:param func labels: An optional callback function that will be passed a
    node payload and return a string label for the node. For example::

        labels=str

    could be used to just return a string cast of the node's data payload.
    Or something like::

        labels=lambda node: node['label']

    could be used if the node payloads are dictionaries.
:param func edge_labels: An optional callback function that will be passed
    an edge payload and return a string label for the edge. For example::

        edge_labels=str

    could be used to just return a string cast of the edge's data payload.
    Or something like::

        edge_labels=lambda edge: edge['label']

    could be used if the edge payloads are dictionaries. If this is set
    edge labels will be drawn in the visualization.
:param int font_size: An optional fontsize to use for text labels, By
    default a value of 12 is used for nodes and 10 for edges.
:param str font_color: An optional font color for strings. By default
    ``'k'`` (ie black) is set.
:param str font_weight: An optional string used to specify the font weight.
    By default a value of ``'normal'`` is used.
:param str font_family: An optional font family to use for strings. By
    default ``'sans-serif'`` is used.
:param str label: An optional string label to use for the graph legend.
:param str connectionstyle: An optional value used to create a curved arc
    of rounding radius rad. For example,
    ``connectionstyle='arc3,rad=0.2'``. See
    :class:`matplotlib.patches.ConnectionStyle` and
    :class:`matplotlib.patches.FancyArrowPatch` for more info. By default
    this is set to ``"arc3"``.

:returns: A matplotlib figure for the visualization if not running with an
    interactive backend (like in jupyter) or if ``ax`` is not set.
:rtype: matplotlib.figure.Figure

For Example:

.. jupyter-execute::

    import matplotlib.pyplot as plt

    import rustworkx as rx
    from rustworkx.visualization import mpl_draw

    G = rx.generators.directed_path_graph(25)
    mpl_draw(G)
    plt.draw()
r   Nmatplotlib needs to be installed prior to running rustworkx.visualization.mpl_draw(). You can install matplotlib with:
'pip install matplotlib'w)r   r      r   )posaxarrowswith_labels)matplotlib.pyplotpyplotImportErrorgcf
get_figureset_facecoloraxesgcaadd_axes
draw_graphset_axis_offdraw_if_interactiveisinteractive)	graphr   r   r   r   kwdspltecfs	            \/home/james-whalen/.local/lib/python3.13/site-packages/rustworkx/visualization/matplotlib.pyr   r   B   s    H' 
zWWY]]_S	z77B\*BuU#VUPTUOO"*	 #-)  9
 		s   B= =
CCCc                 <    SSK Jn  1 Skn1 Skn1 Skn	1 Skn
Xx-  U	-  U
-  n[        U Vs/ s H  oU;  PM	     sn5      (       a7  SR	                  U Vs/ s H  oU;  d  M
  UPM     sn5      n[        S	U 35      eUR                  S
S5      nU(       a,  U R                  5        Vs0 s H  oU" X   5      _M     snUS
'   UR                  SS5      nU(       a5  U R                  5        Vs0 s H  oS   US   4U" US   5      _M     snUS'   UR                  5        VVs0 s H  u  nnX;   d  M  UU_M     nnnUR                  5        VVs0 s H  u  nnX;   d  M  UU_M     nnn[        UR                  S5      [        5      (       a  US	 UR                  5        VVs0 s H  u  nnX;   d  M  UU_M     nnnUR                  5        VVs0 s H  u  nnX;   d  M  UU_M     nnnUc  [        R                  " U 5      n[        X40 UD6  [!        X4SU0UD6  U(       a  [#        X40 UD6  U(       a  [%        X40 UD6  UR'                  5         g! [         a  n[        S5      UeSnAff = fs  snf s  snf s  snf s  snf s  snnf s  snnf s  snnf s  snnf )a  Draw the graph using Matplotlib.

Draw the graph with Matplotlib with options for node positions,
labeling, titles, and many other drawing features.
See draw() for simple drawing without labels or axes.

Parameters
----------
graph: A rustworkx :class:`~rustworkx.PyDiGraph` or
    :class:`~rustworkx.PyGraph`

pos : dictionary, optional
    A dictionary with nodes as keys and positions as values.
    If not specified a spring layout positioning will be computed.
    See :mod:`rustworkx.drawing.layout` for functions that
    compute node positions.


Notes
-----
For directed graphs, arrows  are drawn at the head end.  Arrows can be
turned off with keyword arrows=False.

r   Nr	   >   r   cmapvmaxvminalphalabel	node_list	node_size
edgecolors
linewidths
node_color
node_shape>   r   r'   r(   stylewidth	edge_cmap	edge_list	edge_vmax	edge_vminr)   r*   
arrow_size
arrowstyle
edge_colorr.   connectionstylemin_source_marginmin_target_margin>
   r   bboxr'   labels	font_size
font_colorfont_familyfont_weightverticalalignmenthorizontalalignment>   r   r;   r'   rotater=   r>   edge_labelsr?   r@   rA   rB   z, zReceived invalid argument(s): r<   rD   r      r'   r   )r   r   r   anyjoin
ValueErrorpopnode_indicesweighted_edge_listitems
isinstancegetlist	rustworkxspring_layout
draw_nodes
draw_edgesdraw_labelsdraw_edge_labelsr   )r   r   r   r   r   r   r    valid_node_kwdsvalid_edge_kwdsvalid_label_kwdsvalid_edge_label_kwds
valid_kwdskinvalid_argslabel_fnxedge_label_fnv	node_kwds	edge_kwds
label_kwdsedge_label_kwdss                         r"   r   r      s   2'OO* !25EEH]]J
.AZ.//yyT!ITj5H!T!IJ9,HIIxx$'H9>9K9K9MN9MAXeh//9MNXHH]D1M7<7O7O7Q
7Q!qT1Q4L-!--7Q
] #'**,G,$!Q!2FA,IG"&**,G,$!Q!2FA,IG)--($//g#'::<I<41a13H$!Q$<JI(,

S18Rtq!tOS
{%%e,u'Y'u6&6I6E-*-77K  9
 		P /!I
 O
 HG JSsd   I I2	I7!I7'I<,J"J2JJJ#J3JJ J
I/I**I/c                     SSK nSSKnSSKJn  U
c  UR                  5       n
Uc  U R                  5       n[        U5      S:X  a  UR                  R                  S5      $  [        R                  " U Vs/ s H  nUU   PM
     sn5      n[        U[        5      (       a  [!        XFX'X5      nSnU
R#                  USS2S4   USS2S4   UUUUUU	UUUUS9nU
R%                  SSS	S	S	S	S
9  UR'                  S5        U$ ! [         a  n[	        S5      UeSnAff = fs  snf ! [         a  n[        SU S35      UeSnAff = f)a  Draw the nodes of the graph.

This draws only the nodes of the graph.

:param graph: A rustworkx graph, either a :class:`~rustworkx.PyGraph` or a
    :class:`~rustworkx.PyDiGraph`.

:param dict pos: A dictionary with nodes as keys and positions as values.
    Positions should be sequences of length 2.

:param Axes ax: An optional Matplotlib Axes object, if specified it will
    draw the graph in the specified Matplotlib axes.

:param list node_list: If specified only draw the specified node indices.
    If not specified all nodes in the graph will be drawn.

:param float|array node_size: Size of nodes. If an array it must be the
    same length as node_list. Defaults to 300

node_color : color or array of colors (default='#1f78b4')
    Node color. Can be a single color or a sequence of colors with the same
    length as node_list. Color can be string or rgb (or rgba) tuple of
    floats from 0-1. If numeric values are specified they will be
    mapped to colors using the cmap and vmin,vmax parameters. See
    matplotlib.scatter for more details.

node_shape :  string (default='o')
    The shape of the node.  Specification is as matplotlib.scatter
    marker, one of 'so^>v<dph8'.

alpha : float or array of floats (default=None)
    The node transparency.  This can be a single alpha value,
    in which case it will be applied to all the nodes of color. Otherwise,
    if it is an array, the elements of alpha will be applied to the colors
    in order (cycling through alpha multiple times if necessary).

cmap : Matplotlib colormap (default=None)
    Colormap for mapping intensities of nodes

vmin,vmax : floats or None (default=None)
    Minimum and maximum for node colormap scaling

linewidths : [None | scalar | sequence] (default=1.0)
    Line width of symbol border

edgecolors : [None | scalar | sequence] (default = node_color)
    Colors of node borders

label : [None | string]
    Label for legend

Returns
-------
matplotlib.collections.PathCollection
    `PathCollection` of the nodes.

r   Nr	   zNode z has no position.r   )
scmarkerr$   r&   r%   r'   r,   r+   r(   bothFaxiswhichbottomleftlabelbottom	labelleftrE   )
matplotlibmatplotlib.collectionsr   r   r   r   rJ   lencollectionsPathCollectionnpasarrayKeyError
IndexErrorrM   r   apply_alphascattertick_params
set_zorder)r   r   r)   r*   r-   r.   r'   r$   r&   r%   r   r,   r+   r(   mplrq   r   r    r`   xynode_collections                        r"   rR   rR   c  sy   R	 %' 
zWWY&&(	 9~--d33>ZZ3AQ34 %"" ITP
jj
1a4
1a4

 ! O NN   q!e  9
 		$ 4 >5#456A=>sA   C> !D! 5DD! >
DDDD! !
E +D;;E c                   ^^9^:^;^<  SSK m<SSKnSSKnSSKnSSKJn  Uc+  [        U [        R                  5      (       a
  U(       a  SnOSnTc  UR                  5       mUc  U R                  5       n[        U5      S:X  a  / $ Uc  [        U R                  5       5      nUc  Sn[        5       nU H(  nSU[!        UUS      5      [!        UUS      5      4'   M*     UR#                  5       n[$        R&                  " U5      (       a  [        U5      [        U5      :X  a  [$        R(                  " U Vs/ s H  n[        U[*        5      PM     sn5      (       a  U	b(  [        U	T<R,                  R.                  5      (       d   eOUR1                  5       n	U
c  [3        U5      n
Uc  [5        U5      nT<R,                  R7                  XS9nU Vs/ s H  nU	" U" U5      5      PM     nnS	 n/ nUnT<R8                  R;                  U5      m9[$        R<                  " U5      R5                  5       m;T<R,                  R>                  RA                  XF5      n[C        U5       GH  u  n n!U!S   S   U!S   S   n#n"U!S   S   U!S   S   n%n$Sn&Sn'[$        R&                  " U5      (       aF  UU    SS
 u  n(n)UURE                  U(5         n*UURE                  U)5         n+U" U*U5      n&U" U+U5      n'OU" UU5      =n&n'U&U:  a  Un&U'U:  a  Un'[        U5      [        U5      :X  a  UU    n,O&[        U5      S:X  a  US   n,OUU [        U5      -     n,[$        R&                  " U5      (       a0  [        U5      [        U5      :X  a  UU    n-OUU [        U5      -     n-OUn-[!        [G        U!5      5      U;   a  Sn.OSn.T<R8                  RI                  U"U#4U$U%4UU&U'UU,U-U SU. 3USS9n/URK                  U/5        TRM                  U/5        GM     [$        RN                  " [!        U5      5      n[$        RP                  " [$        RR                  " USS2SS2S4   5      5      n0[$        RT                  " [$        RR                  " USS2SS2S4   5      5      n1[$        RP                  " [$        RR                  " USS2SS2S4   5      5      n2[$        RT                  " [$        RR                  " USS2SS2S4   5      5      n3U1U0-
  n4U3U2-
  m:UU9U:U;U<4S jn5SU4-  ST:-  n7n6U0U6-
  U2U7-
  4U1U6-   U3U7-   44n8TRW                  U85        TRY                  5         TR[                  SSSSSSS9  U$ ! [         a  n[        S5      UeSnAff = fs  snf s  snf )a  Draw the edges of the graph.

This draws only the edges of the graph.

Parameters
----------
graph: A rustworkx graph

pos : dictionary
    A dictionary with nodes as keys and positions as values.
    Positions should be sequences of length 2.

edge_list : collection of edge tuples (default=graph.edge_list())
    Draw only specified edges

width : float or array of floats (default=1.0)
    Line width of edges

edge_color : color or array of colors (default='k')
    Edge color. Can be a single color or a sequence of colors with the same
    length as edge_list. Color can be string or rgb (or rgba) tuple of
    floats from 0-1. If numeric values are specified they will be
    mapped to colors using the edge_cmap and edge_vmin,edge_vmax
    parameters.

style : string (default=solid line)
    Edge line style e.g.: '-', '--', '-.', ':'
    or words like 'solid' or 'dashed'.
    (See `matplotlib.patches.FancyArrowPatch`: `linestyle`)

alpha : float or None (default=None)
    The edge transparency

edge_cmap : Matplotlib colormap, optional
    Colormap for mapping intensities of edges

edge_vmin,edge_vmax : floats, optional
    Minimum and maximum for edge colormap scaling

ax : Matplotlib Axes object, optional
    Draw the graph in the specified Matplotlib axes.

arrows : bool, optional (default=True)
    For directed graphs, if True set default to drawing arrowheads.
    Otherwise set default to no arrowheads. Ignored if `arrowstyle` is set.

    Note: Arrows will be the same color as edges.

arrowstyle : str (default='-\|>' if directed else '-')
    For directed graphs and `arrows==True` defaults to '-\|>',
    otherwise defaults to '-'.

    See `matplotlib.patches.ArrowStyle` for more options.

arrow_size : int (default=10)
    For directed graphs, choose the size of the arrow head's length and
    width. See `matplotlib.patches.FancyArrowPatch` for attribute
    ``mutation_scale`` for more info.

node_size : scalar or array (default=300)
    Size of nodes. Though the nodes are not drawn with this function, the
    node size is used in determining edge positioning.

node_list : list, optional (default=graph.node_indices())
   This provides the node order for the `node_size` array (if it is an
   array).

node_shape :  string (default='o')
    The marker used for nodes, used in determining edge positioning.
    Specification is as a `matplotlib.markers` marker, e.g. one of
    'so^>v<dph8'.

label : None or string
    Label for legend

min_source_margin : int (default=0)
    The minimum margin (gap) at the beginning of the edge at the source.

min_target_margin : int (default=0)
    The minimum margin (gap) at the end of the edge at the target.

Returns
-------
list of matplotlib.patches.FancyArrowPatch
    `FancyArrowPatch` instances of the directed edges

Notes
-----
For directed graphs, arrows are drawn at the head end.  Arrows can be
turned off with keyword arrows=False or by passing an arrowstyle without
an arrow on the end.

Be sure to include `node_size` as a keyword argument; arrows are
drawn considering the size of nodes.
r   Nr	   z-|>-r[   r   )r&   r%   c                 x    US;   a  [         R                  " SU -  5      S-  $ [         R                  " U 5      S-  $ )Nzs^>v<drE   )rv   sqrt)marker_sizerh   s     r"   to_marker_edge"draw_edges.<locals>.to_marker_edge  s6    X771{?+a//77;'!++    rE         ?        z, rad = )	r6   shrinkAshrinkBmutation_scalecolor	linewidthr8   	linestylezorderc                   > [         R                  " X:H  5      (       Ga  TS:X  a  ST-  OTnT
R                  R                  5       R	                  U 5      nSU-  nUS-  nU[         R
                  " SU/5      -   U[         R
                  " Xv/5      -   U[         R
                  " US/5      -   UU[         R
                  " U* S/5      -   U[         R
                  " U* U/5      -   U[         R
                  " SU/5      -   /nTR                  R                  T
R                  R	                  U5      / SQ5      n	U	$ T" X/UQ70 UD6n	U	$ )Nr   g{Gzt?g?      ?)r      r   r   r   r   r   )rv   all	transDatainverted	transformrw   pathPath)posAposBargskwargsselfloop_htdata_locv_shifth_shiftr   retr   base_connectionstylehmax_nodesizer~   s             r"   _connectionstyle$draw_edges.<locals>._connectionstyle  s0   66$, 34q&%,.aK ||,,.88>HK'GmG 2::q'l332::w&8992::wl332::xm442::x&9::2::q'l33D ((-- 6 6t <>STC
 
 'tCDCFCC
r   g?ri   Frj   ).rq   matplotlib.colorsmatplotlib.patchesmatplotlib.pathr   r   r   rM   rP   	PyDiGraphr   r2   rs   rO   rJ   dicttuplekeysrv   iterabler   r   colorsColormapget_cmapminmax	NormalizepatchesConnectionStylearraycolorConverterto_rgba_array	enumerateindexreversedFancyArrowPatchappend	add_patchrw   aminravelamaxupdate_datalimautoscale_viewr|   )=r   r   r2   r0   r7   r/   r'   r6   r5   r1   r4   r3   r   r   r(   r*   r)   r.   r8   r9   r:   rq   r   r    edge_pos_keysedge_posrg   color_normalr   arrow_collectionr   arrow_colorsiedgex1y1x2y2shrink_sourceshrink_targetsourcetargetsource_node_sizetarget_node_sizearrow_color
line_widthradarrowmirustworkxmaxxminymaxyr
   r   padxpadycornersr   r   r   r~   s=               `                                            @@@@r"   rS   rS     s_   l  !' eY0011fJJ	zWWYOO%	
9~	++-.	 
 FM>BuS1Y's1Q4y)9:; !!#H
 	J_H-FF:>:aJq&):>?? i)<)<====IJIJIzz+++K:DE*QiQ0*
E, N;;66G 88I&**,L ::,,:::MLX&4aT!WQZBaT!WQZB;;y!!&q\"1-NFF()@A()@A*+;ZHM*+;ZHM,:9j,QQMM,,-M,,-M|H-&q/K!#&q/K&q3|+<'<=K;;u5zS]*"1X
"1s5z>2
J $ H,CC++HH!!!) ./xu= , 
 	&
Uq 't zz%/*H ''"((8Aq!G#456K77288HQ1W-./D77288HQ1W-./D77288HQ1W-./D{AtA D 4!8$DT!4$;/$+td{1KKGgNN     9
 		P ? Fs#   U 2U:U?
U7&U22U7c                     SSK Jn  Uc  UR                  5       nUc   U R	                  5        Vs0 s H  oU_M     nn0 nUR                  5        HW  u  nnX   u  nn[        U[        5      (       d  [        U5      nUR                  UUUUUUUUU	U
UR                  UUS9nUUU'   MY     UR                  SSSSSSS9  U$ ! [         a  n[        S5      UeSnAff = fs  snf )aj  Draw node labels on the graph.

Parameters
----------
graph: A rustworkx graph

pos : dictionary
    A dictionary with nodes as keys and positions as values.
    Positions should be sequences of length 2.

labels : dictionary (default={n: n for n in graph})
    Node labels in a dictionary of text labels keyed by node.
    Node-keys in labels should appear as keys in `pos`.
    If needed use: `{n:lab for n,lab in labels.items() if n in pos}`

font_size : int (default=12)
    Font size for text labels

font_color : string (default='k' black)
    Font color string

font_weight : string (default='normal')
    Font weight

font_family : string (default='sans-serif')
    Font family

alpha : float or None (default=None)
    The text transparency

bbox : Matplotlib bbox, (default is Matplotlib's ax.text default)
    Specify text box properties (e.g. shape, color etc.) for node labels.

horizontalalignment : string (default='center')
    Horizontal alignment {'center', 'right', 'left'}

verticalalignment : string (default='center')
    Vertical alignment {'center', 'top', 'bottom', 'baseline',
                        'center_baseline'}

ax : Matplotlib Axes object, optional
    Draw the graph in the specified Matplotlib axes.

clip_on : bool (default=True)
    Turn on clipping of node labels at axis boundaries

Returns
-------
dict
    `dict` of labels keyed on the nodes
r   Nr	   )
sizer   familyweightr'   rB   rA   r   r;   clip_onri   Frj   )r   r   r   r   rJ   rL   rM   strtextr   r|   )r   r   r<   r=   r>   r?   r@   r'   r;   rB   rA   r   r   r   r    n
text_itemsr(   r^   yts                        r"   rT   rT   #  s!   D' 
zWWY~ % 2 2 45 41Q$ 45JLLN5A%%%JEGG 3/ll  
 
1' #* NN   Y  9
 		 6s   C C
CCCc                 J    SSK Jn  Uc  UR                  5       nUc,  U R	                  5        VVVs0 s H  u  nnnUU4U_M     nnnnOUn0 nUR                  5        GH  u  u  nnnUU   u  nnUU   u  nnUU-  USU-
  -  -   UU-  USU-
  -  -   nnUU4UR                  5       ;   a0  [        R                  " UU-
  5      nUU:  a	  USU-  -  nOUSU-  -  nU(       a  [        R                  " UU-
  UU-
  5      S[        R                  -  -  S-  n U S:  a  U S	-  n U S
:  a  U S	-  n [        R                  " UU45      n!UR                  R                  [        R                  " U 45      U!R                  S5      5      S   n"OSn"U	c  [        SSSS9n	[!        U["        5      (       d  [#        U5      nUR%                  UUUUUUUUU
UU"UR                  U	SUS9n#U#UUU4'   GM     UR'                  SSSSSSS9  U$ ! [         a  n[        S5      UeSnAff = fs  snnnf )a  Draw edge labels.

Parameters
----------
graph: A rustworkx graph

pos : dictionary
    A dictionary with nodes as keys and positions as values.
    Positions should be sequences of length 2.

edge_labels : dictionary (default={})
    Edge labels in a dictionary of labels keyed by edge two-tuple.
    Only labels for the keys in the dictionary are drawn.

label_pos : float (default=0.5)
    Position of edge label along edge (0=head, 0.5=center, 1=tail)

font_size : int (default=10)
    Font size for text labels

font_color : string (default='k' black)
    Font color string

font_weight : string (default='normal')
    Font weight

font_family : string (default='sans-serif')
    Font family

alpha : float or None (default=None)
    The text transparency

bbox : Matplotlib bbox, optional
    Specify text box properties (e.g. shape, color etc.) for edge labels.
    Default is {boxstyle='round', ec=(1.0, 1.0, 1.0), fc=(1.0, 1.0, 1.0)}.

horizontalalignment : string (default='center')
    Horizontal alignment {'center', 'right', 'left'}

verticalalignment : string (default='center')
    Vertical alignment {'center', 'top', 'bottom', 'baseline',
                        'center_baseline'}

ax : Matplotlib Axes object, optional
    Draw the graph in the specified Matplotlib axes.

rotate : bool (default=True)
    Rotate edge labels to lie parallel to edges

clip_on : bool (default=True)
    Turn on clipping of edge labels at axis boundaries

Returns
-------
dict
    `dict` of labels keyed by edge
r   Nr	         ?r   g       @ih  Z      i)r   rE   r   round)r   r   r   )boxstyleecfcr   )r   r   r   r   r'   rB   rA   rotationr   r;   r   r   ri   Frj   )r   r   r   r   rK   rL   r   rv   absarctan2pir   r   transform_anglesreshaper   rM   r   r   r|   )$r   r   rD   	label_posr=   r>   r?   r@   r'   r;   rB   rA   r   rC   r   r   r    ur`   dr<   r   n1n2r(   r   r   r   r   r^   r   dyangler   trans_angler   s$                                       r"   rU   rU     su   T' 
zWWY+0+C+C+EF+E1a1a&!)+EFJ!<<>R%r7Rr7RNR3?33NR3?33  8v{{}$RBBwTBYTBYJJrBwR0C"%%K@3FErzs{1a&!B,,77%8JBJJW]L^_`abKK<_QD%%%JEGG 3/ ll  
"  !
B8e *h NN   W  9
 		 Gs   H  H 
H
HHc           	          SSK nSSKnSSKn[	        U 5      [	        U5      :X  aT  [        U S   [        5      (       a<  UR                  R                  US9n	U	R                  XE5        U	R                  U 5      n
O; [        R                  " UR                  R                  R                  U 5      /5      n
 [	        U5      [	        U
5      :  d  U
R                   [	        U5      :X  aF  [        R"                  " U
[	        U5      S45      n
U
S   U
SS2S4'   U
S   U
SS2S4'   U
S	   U
SS2S
4'   [%        ['        [)        U5      [	        U
5      5      5      U
SS2S4'   U
$ ! [         a  n[        S5      UeSnAff = f! [         aS    [        R                  " U  Vs/ s H'  oR                  R                  R                  U5      PM)     Os  snf sn5      n
 GN"f = f! [*         a    XSS2S4'    U
$ f = f)a  Apply an alpha (or list of alphas) to the colors provided.

Parameters
----------

colors : color string or array of floats (default='r')
    Color of element. Can be a single color format string,
    or a sequence of colors with the same length as node_list.
    If numeric values are specified they will be mapped to
    colors using the cmap and vmin,vmax parameters.  See
    matplotlib.scatter for more details.

alpha : float or array of floats
    Alpha values for elements. This can be a single alpha value, in
    which case it will be applied to all the elements of color. Otherwise,
    if it is an array, the elements of alpha will be applied to the colors
    in order (cycling through alpha multiple times if necessary).

elem_list : array of rustworkx objects
    The list of elements which are being colored. These could be nodes,
    edges or labels.

cmap : matplotlib colormap
    Color map for use if colors is a list of floats corresponding to points
    on a color mapping.

vmin, vmax : float
    Minimum and maximum values for normalizing colors if a colormap is used

Returns
-------

rgba_colors : numpy ndarray
    Array containing RGBA format values for each of the node colours.

r   Nr	   )r$   r   )r   r   r   )r   r   )r   rE   rE      )rq   r   matplotlib.cmr   rs   rM   r   cmScalarMappableset_climto_rgbarv   r   r   r   rH   r   resizerO   r   r   	TypeError)r   r'   	elem_listr$   r&   r%   r~   rq   r    mapperrgba_colorsr   s               r"   rz   rz   0  s   J	   6{c)n$F1Iv)F)F&&D&1#nnV,
	c((CJJ$=$=$E$Ef$M#NOK#
 u:K((K,<,<I,N))K#i.!1DEK!,T!2KA!,T!2KA!,T!2KA ec+6F!GHAqD G  9
 		&  	c((Z`#aZ`QVJJ$=$=$E$Ee$LZ`#abK	c  #"ArE#sH   E ;:E; 6B%G 
E8'E33E8;G.G
GGG10G1)NNTF)NTF)N,  z#1f78b4oNNNNNNNN)Nr   r[   solidNN
   NNNNTNr  Nr  arc3r   r   )N   r[   
sans-serifnormalNNcenterr  NT)Nr   r  r[   r  r  NNr  r  NTT)NNN)__doc__collections.abcr   	itertoolsr   r   numbersr   numpyrv   rP   __all__r   r   rR   rS   rT   rU   rz    r   r"   <module>r!     s  d . $ #    
[|@L 
			
J 



+{B
 
	 pl 
	 WtLr   