
    -e                    n    d dl mZ d dlZ ej        e          ZddlmZ ddlm	Z	 ddl
mZ dZd Zd	 ZdS )
    )annotationsN   )StaticLayoutProvider)GraphRenderer)warnfrom_networkxc                   t                      }d t          |                     d                    D             }t          t          |                    }|D ]8fd|                     d          D             }t	          |          }||<   9d|v rt          d           t          |                                           |d<   t                      }d |                     d          D             }t          t          |                    }|D ]8fd|                     d          D             }t	          |          }||<   9d	|v sd
|v rt          d           d |                                 D             |d	<   d |                                 D             |d
<   t                      }||j        j	        _
        ||j        j	        _
        t          |          r
 || fi |}	nZ|}	|j        j	        j
        d         }
t          |
          t          |                                          k    rt          d           t          |	          |_        |S )a*  
        Generate a ``GraphRenderer`` from a ``networkx.Graph`` object and networkx
        layout function. Any keyword arguments will be passed to the
        layout function.

        Only two dimensional layouts are supported.

        Args:
            graph (networkx.Graph) : a networkx graph to render
            layout_function (function or dict) : a networkx layout function or mapping of node keys to positions.
            The position is a two element sequence containing the x and y coordinate.

        Returns:
            instance (GraphRenderer)

        .. note::
            Node and edge attributes may be lists or tuples. However, a given
            attribute must either have *all* lists or tuple values, or *all*
            scalar values, for nodes or edges it is defined on.

        .. warning::
            Node attributes labeled 'index' and edge attributes labeled 'start' or 'end' are ignored.
            If you want to convert these attributes, please re-label them to other names.

        Raises:
            ValueError

        c                L    g | ]!}|d                                           D ]}|"S    keys).0nodeattr_keys      4lib/python3.11/site-packages/bokeh/plotting/graph.py
<listcomp>z!from_networkx.<locals>.<listcomp>F   H     : : :t*.q',,..: :& # : : : :    T)datac                V    g | ]%\  }}|                                 v r|         nd &S Nr   )r   _	node_attrr   s      r   r   z!from_networkx.<locals>.<listcomp>K   sQ     B B B&!Y .69I9I-I-Ii))t B B Br   indexzConverting node attributes labeled 'index' are skipped. If you want to convert these attributes, please re-label with other names.c                L    g | ]!}|d                                           D ]}|"S )r   r   )r   edger   s      r   r   z!from_networkx.<locals>.<listcomp>Z   r   r   c                X    g | ]&\  }}}|                                 v r|         nd 'S r   r   )r   r   	edge_attrr   s      r   r   z!from_networkx.<locals>.<listcomp>_   sS     E E E)!Q	 .69I9I-I-Ii))t E E Er   startendzConverting edge attributes labeled 'start' or 'end' are skipped. If you want to convert these attributes, please re-label them with other names.c                    g | ]
}|d          S )r    r   xs     r   r   z!from_networkx.<locals>.<listcomp>j   s    :::qad:::r   c                    g | ]
}|d          S r   r#   r$   s     r   r   z!from_networkx.<locals>.<listcomp>k   s    888QAaD888r   znNode keys in 'layout_function' don't match node keys in the graph. These nodes may not be displayed correctly.)graph_layout)dictlistnodesset_handle_sublistsr   edgesr   node_rendererdata_sourcer   edge_renderercallabler   r   layout_provider)graphlayout_functionkwargs	node_dictnode_attr_keysvalues	edge_dictedge_attr_keysgraph_rendererr'   	node_keysr   s              @r   r   r   %   s   @ FF	: :tEKKTK4J4J/K/K : : :c.1122& 	) 	)HB B B B*/++4+*@*@B B BF &f--F"(Ihn$$ ^ _ _ _ "%++--00	' FF	: :u{{{/E/E : : :c.1122& 	) 	)HE E E E-2[[d[-C-CE E EF &f--F"(Ihn$$(?(? c d d d ;:EKKMM:::	'88%++--888	%&8A$058A$05O$$ 	D*?5;;F;;LL*L&4@EgNI9~~_%9%9%;%;!<!<<< C D D D *><)X)X)X&r   c                    t          d | D                       r4t          d | D                       st          d          d | D             S | S )Nc              3  N   K   | ] }t          |t          t          f          V  !d S r   
isinstancer)   tupler$   s     r   	<genexpr>z#_handle_sublists.<locals>.<genexpr>   s0      
8
8A:a$''
8
8
8
8
8
8r   c              3  R   K   | ]"}|t          |t          t          f          V  #d S r   r?   r$   s     r   rB   z#_handle_sublists.<locals>.<genexpr>   s0      QQA1=:a$//====QQr   z;Can't mix scalar and non-scalar values for graph attributesc                4    g | ]}|g nt          |          S r   )r)   r$   s     r   r   z$_handle_sublists.<locals>.<listcomp>   s&    ===aiT!WW===r   )anyall
ValueError)r8   s    r   r,   r,      si    

8
8
8
8
888 >QQQQQQQ 	\Z[[[==f====Mr   )
__future__r   logging	getLogger__name__logmodels.graphsr   models.renderersr   util.warningsr   __all__r   r,   r#   r   r   <module>rQ      s    # " " " " " g!! 1 0 0 0 0 0 , , , , , ,              X X XD    r   