B
    @\4                 @   s   d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZ dZeG dd de
ZG dd	 d	eZd
d ZeG dd de
ZG dd deZG dd deZG dd deZdS )   )abstract)AnyDictEitherIntSeqString)Model)ColumnDataSource)EdgesAndLinkedNodesGraphHitTestPolicyLayoutProviderNodesAndLinkedEdges	NodesOnlyStaticLayoutProviderc               @   s   e Zd ZdZdS )r   z

    N)__name__
__module____qualname____doc__ r   r   2lib/python3.7/site-packages/bokeh/models/graphs.pyr   +   s   r   c               @   s*   e Zd ZdZeeeeee	i ddZ
dS )r   z

    aV  
    The coordinates of the graph nodes in cartesian space. The dictionary
    keys correspond to a node index and the values are a two element sequence
    containing the x and y coordinates of the node.

    .. code-block:: python

        {
            0 : [0.5, 0.5],
            1 : [1.0, 0.86],
            2 : [0.86, 1],
        }
    )defaulthelpN)r   r   r   r   r   r   r   r   r   r   graph_layoutr   r   r   r   r   4   s   r   c                s  ddl m} ddlm} t }dd t| jddD }tt|}x*|D ]"  fdd| jddD | < qJW d	|krd
dlm	} |d t|  |d	< t }dd | j
ddD }	tt|	}	x*|	D ]"  fdd| j
ddD | < qW d|	ksd|	krd
dlm	} |d dd | 
 D |d< dd | 
 D |d< t|d}
t|d}| }|
j|jj_|j|jj_t|r|| f|}n<|}|jjjd	 }t|t| krd
dlm	} |d ||d|_|S )a7  
        Generate a ``GraphRenderer`` from a ``networkx.Graph`` object and networkx
        layout function. Any keyword arguments will be passed to the
        layout function.

        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)

        .. warning::
            Only two dimensional layouts are currently supported.

        .. 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.

        r   )GraphRenderer)r   c             S   s"   g | ]}|d    D ]}|qqS )   )keys).0Znodeattr_keyr   r   r   
<listcomp>e   s    z!from_networkx.<locals>.<listcomp>T)datac                s(   g | ] \}} |  kr |  nd qS )N)r   )r   _Z	node_attr)r   r   r   r   j   s   index    )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   w   s    c                s*   g | ]"\}}} |  kr"|  nd qS )N)r   )r   r!   Z	edge_attr)r   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      s    c             S   s   g | ]}|d  qS )r   r   )r   r'   r   r   r   r      s    znNode keys in 'layout_function' don't match node keys in the graph. These nodes may not be displayed correctly.)r   )Zmodels.renderersr   Zmodels.graphsr   dictlistZnodessetwarningsr$   Zedgesr
   r    Znode_rendererZdata_sourceZedge_renderercallabler   Zlayout_provider)ZgraphZlayout_functionkwargsr   r   Z	node_dictZnode_attr_keysr$   Z	edge_dictZedge_attr_keysZnode_sourceZedge_sourceZgraph_rendererr   Z	node_keysr   )r   r   from_networkxG   sJ    






r.   c               @   s   e Zd ZdZdS )r   z

    N)r   r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )r   z
    With the ``NodesOnly`` policy, only graph nodes are able to be selected and
    inspected. There is no selection or inspection of graph edges.

    N)r   r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )r   z
    With the ``NodesAndLinkedEdges`` policy, inspection or selection of graph
    nodes will result in the inspection or selection of the node and of the
    linked graph edges. There is no direct selection or inspection of graph
    edges.

    N)r   r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )r   z
    With the ``EdgesAndLinkedNodes`` policy, inspection or selection of graph
    edges will result in the inspection or selection of the edge and of the
    linked graph nodes. There is no direct selection or inspection of graph
    nodes.

    N)r   r   r   r   r   r   r   r   r      s   r   N)Zcore.has_propsr   Zcore.propertiesr   r   r   r   r   r   Zmodelr	   Zmodels.sourcesr
   __all__r   r   r.   r   r   r   r   r   r   r   r   <module>   s    X	