o
    ˷e                     @   s  d Z ddlZddlmZ g dZdd Zedd8d	d
Zd9ddZd:ddZ		d;ddZ
ed										d<ddZeZed	d=ddZed	d=ddZ	d>dd Zd!d" Zd#d$ Zd?d%d&Zd@d'd(Zd@d)d*Zd9d+d,ZdAd/d0ZdBd2d3ZdCd4d5ZdCd6d7ZdS )Da  
******
Layout
******

Node positioning algorithms for graph drawing.

For `random_layout()` the possible resulting shape
is a square of side [0, scale] (default: [0, 1])
Changing `center` shifts the layout by that amount.

For the other layout routines, the extent is
[center - scale, center + scale] (default: [-1, 1]).

Warning: Most layout routines have only been tested in 2-dimensions.

    N)np_random_state)bipartite_layoutcircular_layoutkamada_kawai_layoutrandom_layoutrescale_layoutrescale_layout_dictshell_layoutspring_layoutspectral_layoutplanar_layoutfruchterman_reingold_layoutspiral_layoutmultipartite_layoutc                 C   sh   dd l }t| tjst }||  |} |d u r||}n||}t||kr0d}t|| |fS )Nr   z;length of center coordinates must match dimension of layout)	numpy
isinstancenxGraphadd_nodes_fromzerosasarraylen
ValueError)Gcenterdimnpempty_graphmsg r   N/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/drawing/layout.py_process_params&   s   

r!         c                 C   sJ   ddl }t| ||\} }|t| || }||j}tt| |}|S )aN  Position nodes uniformly at random in the unit square.

    For every node, a position is generated by choosing each of dim
    coordinates uniformly at random on the interval [0.0, 1.0).

    NumPy (http://scipy.org) is required for this function.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout.

    seed : int, RandomState instance or None  optional (default=None)
        Set the random state for deterministic node layouts.
        If int, `seed` is the seed used by the random number generator,
        if numpy.random.RandomState instance, `seed` is the random
        number generator,
        if None, the random number generator is the RandomState instance used
        by numpy.random.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Examples
    --------
    >>> G = nx.lollipop_graph(4, 3)
    >>> pos = nx.random_layout(G)

    r   N)r   r!   randr   astypefloat32dictzip)r   r   r   seedr   posr   r   r    r   ;   s   'r      c                 C   s   ddl }|dk rtdt| ||\} }td|d }t| dkr%i }|S t| dkr5tj| |i}|S |ddt| d dd d |j	 }|
|j}||||||t| |fg}t||d| }tt| |}|S )ab  Position nodes on a circle.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout.
        If dim>2, the remaining dimensions are set to zero
        in the returned positions.
        If dim<2, a ValueError is raised.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Raises
    ------
    ValueError
        If dim < 2

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> pos = nx.circular_layout(G)

    Notes
    -----
    This algorithm currently only works in two dimensions and does not
    try to minimize edge crossings.

    r   Nr#   zcannot handle dimensions < 2r+   scale)r   r   r!   maxr   r   utilsarbitrary_elementlinspacepir%   r&   column_stackcossinr   r   r'   r(   )r   r.   r   r   r   paddimsr*   thetar   r   r    r   l   s&   *("r   c                 C   s  ddl }|dkrtdt| ||\} }t| dkri S t| dkr*tj| |iS |du r3t| g}|t| }t|d dkrDd}n|}|du rQ|jt| }|}	i }
|D ]5}|j	dd|j t|d|j
d|	 }||||||g | }|
t|| ||7 }|	|7 }	qW|
S )	a  Position nodes in concentric circles.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    nlist : list of lists
       List of node lists for each shell.

    rotate : angle in radians (default=pi/len(nlist))
       Angle by which to rotate the starting position of each shell
       relative to the starting position of the previous shell.
       To recreate behavior before v2.5 use rotate=0.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout, currently only dim=2 is supported.
        Other dimension values result in a ValueError.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Raises
    ------
    ValueError
        If dim != 2

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> shells = [[0], [1, 2, 3]]
    >>> pos = nx.shell_layout(G, shells)

    Notes
    -----
    This algorithm currently only works in two dimensions and does not
    try to minimize edge crossings.

    r   Nr#   can only handle 2 dimensionsr+           F)endpointdtype)r   r   r!   r   r   r0   r1   listr3   r2   r&   r4   r5   r6   updater(   )r   nlistrotater.   r   r   r   radius_bumpradiusfirst_thetanposnodesr8   r*   r   r   r    r	      s8   0
"
r	   verticalUUUUUU?c                 C   s4  ddl }|dvrd}t|t| |dd\} }t| dkri S d}|| }	|	d |d f}
t|}t| | }t|t| }|dt|}||	t|}|d|t|}|d|t|}|||g|
 }|||g|
 }|	||g}t
||d| }|d	kr|ddddd
f }tt||}|S )a  Position nodes in two straight lines.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    nodes : list or container
        Nodes in one node set of the bipartite graph.
        This set will be placed on left or top.

    align : string (default='vertical')
        The alignment of nodes. Vertical or horizontal.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    aspect_ratio : number (default=4/3):
        The ratio of the width to the height of the layout.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node.

    Examples
    --------
    >>> G = nx.bipartite.gnmk_random_graph(3, 5, 10, seed=123)
    >>> top = nx.bipartite.sets(G)[0]
    >>> pos = nx.bipartite_layout(G, top)

    Notes
    -----
    This algorithm currently only works in two dimensions and does not
    try to minimize edge crossings.

    r   NrF   
horizontal,align must be either vertical or horizontal.r#   r   r   r+   r-   rI   r,   )r   r   r!   r   setr=   repeatr2   r4   concatenater   r'   r(   )r   rE   alignr.   r   aspect_ratior   r   heightwidthoffsettopbottomleft_xsright_xsleft_ysright_ystop_pos
bottom_posr*   r   r   r    r     s2   ,r   
   2   -C6?weightc                    s  ddl }t| ||	\} }|dur:|du rtd|D ]
}||vr$tdqdd t| D  | fdd|D }|durrtdd	 | D }|dkrOd
}|
t| |	| | }t| D ]\}}||v rp||| ||< q_nd}d
}t| dkr~i S t| d
krt	j
|  |iS z1t| dk rtt	j| |dd}|du r|dur|j\}}||| }t|||||||	|
}W n/ ty   t	j| |d}|du r|dur|j\}}||| }t|||||||	|
}Y nw |du r|durt||d| }tt| |}|S )au  Position nodes using Fruchterman-Reingold force-directed algorithm.

    The algorithm simulates a force-directed representation of the network
    treating edges as springs holding nodes close, while treating nodes
    as repelling objects, sometimes called an anti-gravity force.
    Simulation continues until the positions are close to an equilibrium.

    There are some hard-coded values: minimal distance between
    nodes (0.01) and "temperature" of 0.1 to ensure nodes don't fly away.
    During the simulation, `k` helps determine the distance between nodes,
    though `scale` and `center` determine the size and place after
    rescaling occurs at the end of the simulation.

    Fixing some nodes doesn't allow them to move in the simulation.
    It also turns off the rescaling feature at the simulation's end.
    In addition, setting `scale` to `None` turns off rescaling.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    k : float (default=None)
        Optimal distance between nodes.  If None the distance is set to
        1/sqrt(n) where n is the number of nodes.  Increase this value
        to move nodes farther apart.

    pos : dict or None  optional (default=None)
        Initial positions for nodes as a dictionary with node as keys
        and values as a coordinate list or tuple.  If None, then use
        random initial positions.

    fixed : list or None  optional (default=None)
        Nodes to keep fixed at initial position.
        Nodes not in ``G.nodes`` are ignored.
        ValueError raised if `fixed` specified and `pos` not.

    iterations : int  optional (default=50)
        Maximum number of iterations taken

    threshold: float optional (default = 1e-4)
        Threshold for relative error in node position changes.
        The iteration stops if the error is below this threshold.

    weight : string or None   optional (default='weight')
        The edge attribute that holds the numerical value used for
        the edge weight.  Larger means a stronger attractive force.
        If None, then all edge weights are 1.

    scale : number or None (default: 1)
        Scale factor for positions. Not used unless `fixed is None`.
        If scale is None, no rescaling is performed.

    center : array-like or None
        Coordinate pair around which to center the layout.
        Not used unless `fixed is None`.

    dim : int
        Dimension of layout.

    seed : int, RandomState instance or None  optional (default=None)
        Set the random state for deterministic node layouts.
        If int, `seed` is the seed used by the random number generator,
        if numpy.random.RandomState instance, `seed` is the random
        number generator,
        if None, the random number generator is the RandomState instance used
        by numpy.random.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> pos = nx.spring_layout(G)

    # The same using longer but equivalent function name
    >>> pos = nx.fruchterman_reingold_layout(G)
    r   Nz'nodes are fixed without positions givenc                 S   s   i | ]\}}||qS r   r   ).0inoder   r   r    
<dictcomp>      z!spring_layout.<locals>.<dictcomp>c                    s   g | ]
}| v r | qS r   r   )r`   rb   nfixedr   r    
<listcomp>  s    z!spring_layout.<locals>.<listcomp>c                 s   s    | ]
}|D ]}|V  qqd S )Nr   )r`   pos_tupcoordr   r   r    	<genexpr>  s    z spring_layout.<locals>.<genexpr>r+     fr_   r<   r_   r-   )r   r!   r   	enumerater   r/   valuesr$   r   r   r0   r1   rE   to_scipy_sparse_arrayshapesqrt_sparse_fruchterman_reingoldto_numpy_array_fruchterman_reingoldr   r'   r(   )r   kr*   fixed
iterations	thresholdr_   r.   r   r   r)   r   rb   dom_sizepos_arrra   nAnnodes_r   re   r    r
   Y  sd   _

	r
      c              
   C   s  dd l }z| j\}	}
W n ty } zd}t||d }~ww |d u r1|j||	|| jd}n|| j}|d u rB|	d|	 }t
t
|jd t|jd  t
|jd t|jd  d }||d  }|j|jd |jd |jd f| jd}t|D ]u}|d d |jd d f ||jd d d d f  }|jj|dd}|j|d	d |d
 |d||| |d  | | |  }|jj|dd}||d	k d|}|d||| }|d urd||< ||7 }||8 }|j||	 |k r |S q|S )Nr   9fruchterman_reingold() takes an adjacency matrix as inputr<         ?r+   皙?r,   axis{Gz?)outz
ijk,ij->ikr#   zij,i->ijr:   )r   rr   AttributeErrorr   NetworkXErrorr   r$   r<   r%   rs   r/   Tminr   rangenewaxislinalgnormclipeinsumwhere)r~   rw   r*   rx   ry   rz   r   r)   r   r   r   errr   tdtdelta	iterationdistancedisplacementlength	delta_posr   r   r    rv     sF   >(0rv   c              
   C   sB  dd l }dd l}	dd l}
z| j\}}W n ty' } zd}t||d }~ww z|  } W n ty?   |	j	|  } Y nw |d u rQ|j
|||| jd}n|| j}|d u r]g }|d u rh|d| }tt|jd t|jd  t|jd t|jd  d }||d  }|||f}t|D ]}|d9 }t| jd D ]G}||v rq|| | j}||d jdd}||d	k d	|}| | }|d d |f  ||| |d  || |   jdd7  < q||d jdd}||d	k d|}|| | j}||7 }||8 }|j|| |k r |S q|S )
Nr   r   r   r   r+   r   r#   r   r   )r   scipyscipy.sparserr   r   r   r   tolilsparse	coo_arrayr   r$   r<   r%   rs   r/   r   r   r   r   sumr   
getrowviewtoarrayr   r   )r~   rw   r*   rx   ry   rz   r   r)   r   spr   r   r   r   r   r   r   r   r   ra   r   r   Air   r   r   r   r    rt   4  s`   >rt   c              	      s@  ddl }t| ||\} }t| }|dkri S |du r#ttj| |d}d|||f }	t| D ]#\}
}||vr9q0|| }t| D ]\}}||vrJqA|| |	|
 |< qAq0 du r|dkrct| |d n|dkrnt	| |d ndd	 t
| |dd
t| D  | fdd| D }t|	|| t |d|  tt
|  S )a  Position nodes using Kamada-Kawai path-length cost-function.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    dist : dict (default=None)
        A two-level dictionary of optimal distances between nodes,
        indexed by source and destination node.
        If None, the distance is computed using shortest_path_length().

    pos : dict or None  optional (default=None)
        Initial positions for nodes as a dictionary with node as keys
        and values as a coordinate list or tuple.  If None, then use
        circular_layout() for dim >= 2 and a linear layout for dim == 1.

    weight : string or None   optional (default='weight')
        The edge attribute that holds the numerical value used for
        the edge weight.  If None, then all edge weights are 1.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> pos = nx.kamada_kawai_layout(G)
    r   Nrn   g    .Ar"   )r   r#   c                 S   s   i | ]\}}||qS r   r   )r`   r}   ptr   r   r    rc     rd   z'kamada_kawai_layout.<locals>.<dictcomp>r+   c                       g | ]} | qS r   r   )r`   r}   r*   r   r    rg         z'kamada_kawai_layout.<locals>.<listcomp>r-   )r   r!   r   r'   r   shortest_path_lengthonesro   r   r   r(   r2   array_kamada_kawai_solver   )r   distr*   r_   r.   r   r   r   nNodesdist_mtxrownrrdistcolncr|   r   r   r    r   ~  s6   +"r   c           	      C   sj   dd l }dd l}dd l}d}|d| || jd d   ||f}|jjt| d|dd}|j	
d|fS )Nr   MbP?r+   zL-BFGS-BT)methodargsjacr,   )r   r   scipy.optimizeeyerr   optimizeminimize_kamada_kawai_costfnravelxreshape)	r   r|   r   r   r   r   meanwtcostargs	optresultr   r   r    r     s   $r   c              	   C   s  |j d }| ||f}|d d |jd d f ||jd d d d f  }|jj|dd}|d|d|||d   }	|| d }
d|
||< d||
d	  }|d
||
|	|d||
|	 }|j|dd}|d| ||d	  7 }||| 7 }||	 fS )Nr   r,   r   zijk,ij->ijkr+   r   r         ?r#   zij,ij,ijk->ikzij,ij,ijk->jk)
rr   r   r   r   r   r   r   diag_indicesr   r   )pos_vecr   invdist
meanweightr   r   r|   r   nodesep	directionrS   costgradsumposr   r   r    r     s   
0 r   c              	   C   s*  ddl }t| ||\} }t| dkrAt| dkr|g }nt| dkr+||g}n|||||d g}tt| |S z"t| dk rJttj	| |dd}| 
 r]||| }t||}W n  ttfy   tj| |d	}| 
 r|||j7 }t||}Y nw t||d
| }tt| |}|S )a  Position nodes using the eigenvectors of the graph Laplacian.

    Using the unnormalized Laplacian, the layout shows possible clusters of
    nodes which are an approximation of the ratio cut. If dim is the number of
    dimensions then the positions are the entries of the dim eigenvectors
    corresponding to the ascending eigenvalues starting from the second one.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    weight : string or None   optional (default='weight')
        The edge attribute that holds the numerical value used for
        the edge weight.  If None, then all edge weights are 1.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> pos = nx.spectral_layout(G)

    Notes
    -----
    Directed graphs will be considered as undirected graphs when
    positioning the nodes.

    For larger graphs (>500 nodes) this will use the SciPy sparse
    eigenvalue solver (ARPACK).
    r   Nr#   r+   g       @rk   drm   rn   r-   )r   r!   r   r   r   r'   r(   r   r   rq   is_directed	transpose_sparse_spectralImportErrorru   r   	_spectralr   )r   r_   r.   r   r   r   r*   r~   r   r   r    r     s2   -
r   c              
   C   s   dd l }z| j\}}W n ty } zd}t||d }~ww |j|| jd|j| dd }||  }|j	|\}	}
|
|	d|d  }||
d d |f S )Nr   z-spectral() takes an adjacency matrix as inputr   r+   r   )r   rr   r   r   r   identityr<   r   r   eigargsortreal)r~   r   r   r   r   r   r   DLeigenvalueseigenvectorsindexr   r   r    r   J  s   r   c              
   C   s   dd l }dd l}dd l}dd l}z| j\}}W n ty+ } zd}t||d }~ww |j	|j
| jddd||}	|	|  }
|d }td| d t||}|jjj|
|d|d\}}||d| }||d d |f S )Nr   z4sparse_spectral() takes an adjacency matrix as inputr+   r   r#   SM)whichncv)r   r   r   scipy.sparse.linalgrr   r   r   r   r   	csr_arrayspdiagsr   r/   intrs   r   eigshr   r   )r~   r   r   r   r   r   r   r   r   r   r   rw   r   r   r   r   r   r   r    r   _  s$   "r   c                    s   ddl }|dkrtdt| ||\} }t| dkri S t| tjr%| }nt| \}}|s3tdt	| t
|}| fdd|D   |j t |d|  tt| S )	a  Position nodes without edge intersections.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G. If G is of type
        nx.PlanarEmbedding, the positions are selected accordingly.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    dim : int
        Dimension of layout.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Raises
    ------
    NetworkXException
        If G is not planar

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> pos = nx.planar_layout(G)
    r   Nr#   r9   zG is not planar.c                    r   r   r   )r`   r   r   r   r    rg     r   z!planar_layout.<locals>.<listcomp>r-   )r   r   r!   r   r   r   PlanarEmbeddingcheck_planarityNetworkXExceptioncombinatorial_embedding_to_posr=   	row_stackr%   float64r   r'   r(   )r   r.   r   r   r   	embedding	is_planar	node_listr   r   r    r   |  s"   !

r   ffffff?Fc              	   C   s(  ddl }|dkrtdt| ||\} }t| dkri S t| dkr*tj| |iS g }|rad}d}	|}
|
||	|
  7 }
tt| D ]}|	|
 }|
|| 7 }
||	|
| |
|
| g qBn|jt| td}|| }||||	||
|g }t|||d| }tt| |}|S )	a  Position nodes in a spiral layout.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.
    scale : number (default: 1)
        Scale factor for positions.
    center : array-like or None
        Coordinate pair around which to center the layout.
    dim : int, default=2
        Dimension of layout, currently only dim=2 is supported.
        Other dimension values result in a ValueError.
    resolution : float, default=0.35
        The compactness of the spiral layout returned.
        Lower values result in more compressed spiral layouts.
    equidistant : bool, default=False
        If True, nodes will be positioned equidistant from each other
        by decreasing angle further from center.
        If False, nodes will be positioned at equal angles
        from each other by increasing separation further from center.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node

    Raises
    ------
    ValueError
        If dim != 2

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> pos = nx.spiral_layout(G)
    >>> nx.draw(G, pos=pos)

    Notes
    -----
    This algorithm currently only works in two dimensions.

    r   Nr#   r9   r+   r   r   r-   )r   r   r!   r   r   r0   r1   r   appendr5   r6   arangefloatr   r   r   r'   r(   )r   r.   r   r   
resolutionequidistantr   r*   chordstepr8   r   rr   angler   r   r    r     s2   ,$$r   subsetc              	   C   s  ddl }|dvrd}t|t| |dd\} }t| dkri S i }| jddD ]#\}}	z|	| }
W n ty>   d	}t|w |g||
g  ||
< q'zt| }W n t	yb   t
| }Y nw d}g }t|}t|D ]@\}\}}
t|
}|||}|jd|td
}|d d |d d f}|||g| }|du r|}n|||g}||
 qot||d| }|dkr|dddddf }tt||}|S )a  Position nodes in layers of straight lines.

    Parameters
    ----------
    G : NetworkX graph or list of nodes
        A position will be assigned to every node in G.

    subset_key : string (default='subset')
        Key of node data to be used as layer subset.

    align : string (default='vertical')
        The alignment of nodes. Vertical or horizontal.

    scale : number (default: 1)
        Scale factor for positions.

    center : array-like or None
        Coordinate pair around which to center the layout.

    Returns
    -------
    pos : dict
        A dictionary of positions keyed by node.

    Examples
    --------
    >>> G = nx.complete_multipartite_graph(28, 16, 10)
    >>> pos = nx.multipartite_layout(G)

    Notes
    -----
    This algorithm currently only works in two dimensions and does not
    try to minimize edge crossings.

    Network does not need to be a complete multipartite graph. As long as nodes
    have subset_key data, they will be placed in the corresponding layers.

    r   NrH   rJ   r#   rK   T)dataz9all nodes must have subset_key (default='subset') as datar   r+   r-   rI   r,   )r   r   r!   r   rE   KeyErrorgetsorteditems	TypeErrorr=   ro   rM   r   r   r4   rN   extendr   r'   r(   )r   
subset_keyrO   r.   r   r   r   layersvr   layerr*   rE   rR   ra   r   rQ   xsysrS   	layer_posr   r   r    r     sN   'r   c                 C   s   d}t | jd D ]%}| dd|f  | dd|f  8  < tt| dd|f  |}q	|dkrKt | jd D ]}| dd|f  || 9  < q:| S )a  Returns scaled position array to (-scale, scale) in all axes.

    The function acts on NumPy arrays which hold position information.
    Each position is one row of the array. The dimension of the space
    equals the number of columns. Each coordinate in one column.

    To rescale, the mean (center) is subtracted from each axis separately.
    Then all values are scaled so that the largest magnitude value
    from all axes equals `scale` (thus, the aspect ratio is preserved).
    The resulting NumPy Array is returned (order of rows unchanged).

    Parameters
    ----------
    pos : numpy array
        positions to be scaled. Each row is a position.

    scale : number (default: 1)
        The size of the resulting extent in all directions.

    Returns
    -------
    pos : numpy array
        scaled positions. Each row is a position.

    See Also
    --------
    rescale_layout_dict
    r   r+   N)r   rr   meanr/   abs)r*   r.   limra   r   r   r    r   Y  s   ( r   c                 C   s<   ddl }| si S |t|  }t||d}tt| |S )a  Return a dictionary of scaled positions keyed by node

    Parameters
    ----------
    pos : A dictionary of positions keyed by node

    scale : number (default: 1)
        The size of the resulting extent in all directions.

    Returns
    -------
    pos : A dictionary of positions keyed by node

    Examples
    --------
    >>> import numpy as np
    >>> pos = {0: np.array((0, 0)), 1: np.array((1, 1)), 2: np.array((0.5, 0.5))}
    >>> nx.rescale_layout_dict(pos)
    {0: array([-1., -1.]), 1: array([1., 1.]), 2: array([0., 0.])}

    >>> pos = {0: np.array((0, 0)), 1: np.array((-1, 1)), 2: np.array((-0.5, 0.5))}
    >>> nx.rescale_layout_dict(pos, scale=2)
    {0: array([ 2., -2.]), 1: array([-2.,  2.]), 2: array([0., 0.])}

    See Also
    --------
    rescale_layout
    r   Nr-   )r   r   r=   rp   r   r'   r(   )r*   r.   r   pos_vr   r   r    r     s   r   )Nr#   N)r+   Nr#   )NNr+   Nr#   )rF   r+   NrG   )
NNNr]   r^   r_   r+   Nr#   N)NNNr]   r^   r#   N)NNr_   r+   Nr#   )r_   r+   Nr#   )r#   )r+   Nr#   r   F)r   rF   r+   N)r+   )__doc__networkxr   networkx.utilsr   __all__r!   r   r   r	   r   r
   r   rv   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    <module>   sV    
0
D\
N =J
M

O


9
O
U)