a
    IDf                     @  s   d dl mZ d dlZeeZd dlmZmZm	Z	 ddl
mZ ddlmZ ddlmZ erbd dlZdZd	d
dddddZdd ZdS )    )annotationsN)TYPE_CHECKINGAnySequence   )StaticLayoutProvider)GraphRenderer)warn)from_networkxznx.Graphz dict[int | str, Sequence[float]]r   r   )graphlayout_functionkwargsreturnc                   s  t  }dd t| jddD }tt|}|D ].  fdd| jddD }t|}|| < q0d|v rptd t|  |d< t  }dd | jddD }tt|}|D ].  fd	d| jddD }t|}|| < qd
|v sd|v rtd dd |  D |d
< dd |  D |d< t }||jj	_
||jj	_
t|rV|| fi |}	n0|}	|jj	j
d }
t|
t| krtd t|	d|_|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                 S  s"   g | ]}|d    D ]}|qqS    keys).0nodeattr_key r   a/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/bokeh/plotting/graph.py
<listcomp>L   s   z!from_networkx.<locals>.<listcomp>T)datac                   s(   g | ] \}} |  v r |  nd qS Nr   )r   _Z	node_attrr   r   r   r   Q   s   indexzConverting node attributes labeled 'index' are skipped. If you want to convert these attributes, please re-label with other names.c                 S  s"   g | ]}|d    D ]}|qqS )r   r   )r   Zedger   r   r   r   r   `   s   c                   s*   g | ]"\}}} |  v r"|  nd qS r   r   )r   r   Z	edge_attrr   r   r   r   e   s   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                 S  s   g | ]}|d  qS )r   r   r   xr   r   r   r   p       c                 S  s   g | ]}|d  qS r   r   r    r   r   r   r   q   r"   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   Znode_rendererZdata_sourcer   Zedge_renderercallabler   r   Zlayout_provider)r   r   r   Z	node_dictZnode_attr_keysvaluesZ	edge_dictZedge_attr_keysZgraph_rendererr#   Z	node_keysr   r   r   r
   +   sH     








r
   c                 C  s>   t dd | D r:tdd | D s,tddd | D S | S )Nc                 s  s   | ]}t |ttfV  qd S r   
isinstancer%   tupler    r   r   r   	<genexpr>   r"   z#_handle_sublists.<locals>.<genexpr>c                 s  s$   | ]}|d urt |ttfV  qd S r   r,   r    r   r   r   r/      r"   z;Can't mix scalar and non-scalar values for graph attributesc                 S  s    g | ]}|d u rg nt |qS r   )r%   r    r   r   r   r      r"   z$_handle_sublists.<locals>.<listcomp>)anyall
ValueError)r+   r   r   r   r(      s
    r(   )
__future__r   logging	getLogger__name__logtypingr   r   r   Zmodels.graphsr   Zmodels.renderersr   Zutil.warningsr	   ZnetworkxZnx__all__r
   r(   r   r   r   r   <module>   s   
b