U
    /e!                     @  sN   d dl mZ d dlZeeZddlmZ ddlm	Z	 dZ
dd Zdd	 ZdS )
    )annotationsN   )StaticLayoutProvider)GraphRendererfrom_networkxc                   s  t  }dd t| jddD }tt|}|D ].  fdd| jddD }t|}|| < q0d|kr|ddlm} |d	 t|  |d< t  }d
d | jddD }tt|}|D ].  fdd| jddD }t|}|| < qd|ksd|krddlm} |d dd |  D |d< dd |  D |d< t }	||	j	j
_||	jj
_t|rl|| f|}
n<|}
|	j	j
jd }t|t| krddlm} |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   8/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/plotting/graph.py
<listcomp>E   s     z!from_networkx.<locals>.<listcomp>T)datac                   s(   g | ] \}} |  kr |  nd qS Nr	   )r   _Z	node_attrr   r   r   r   J   s   indexr   )warnzConverting 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   Z   s     c                   s*   g | ]"\}}} |  kr"|  nd qS r   r	   )r   r   Z	edge_attrr   r   r   r   _   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   k   s     c                 S  s   g | ]}|d  qS r   r   r   r   r   r   r   l   s     znNode keys in 'layout_function' don't match node keys in the graph. These nodes may not be displayed correctly.)graph_layout)dictlistZnodesset_handle_sublistswarningsr   edgesr   Znode_rendererZdata_sourcer   Zedge_renderercallabler
   r   Zlayout_provider)graphZlayout_functionkwargsZ	node_dictZnode_attr_keysvaluesr   Z	edge_dictZedge_attr_keysZgraph_rendererr   Z	node_keysr   r   r   r   $   sN     








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>   s     z#_handle_sublists.<locals>.<genexpr>c                 s  s$   | ]}|d k	rt |ttfV  qd S r   r&   r   r   r   r   r)      s      z;Can't mix scalar and non-scalar values for graph attributesc                 S  s    g | ]}|d krg nt |qS r   )r   r   r   r   r   r      s     z$_handle_sublists.<locals>.<listcomp>)anyall
ValueError)r%   r   r   r   r      s
    r   )
__future__r   logging	getLogger__name__logZmodels.graphsr   Zmodels.renderersr   __all__r   r   r   r   r   r   <module>   s   
e