a
    J5db                     @   s   d Z dgZdddZdS )z-
Text-based visual representations of graphs

forest_strTNFc                     sz  ddl }g }|du r|j}n|}|rNd}d}	d}
d}d}d}d}d	}d
}d}n(d}d}	d}
d}d}d}d}d}d}d}t jdkr|| n| s|d  }|r jn j}|du r|rއ fdd jD }n fdd|	 D }t|d fddt
|D ddd }t |rb| \}}}|v rJq(| |s|rr||	 }|| }n||
 }|| }nX|r|r|| }|| }n|| }|| }n(|r|| }|| }n|| }|| }|r j| d|}n|}||t|  fdd|| D }t
|ddd ddD ]&\}}|dk}|||f}|| q6q(|du rvd|S dS ) u  
    Creates a nice utf8 representation of a directed forest

    Parameters
    ----------
    graph : nx.DiGraph | nx.Graph
        Graph to represent (must be a tree, forest, or the empty graph)

    with_labels : bool
        If True will use the "label" attribute of a node to display if it
        exists otherwise it will use the node value itself. Defaults to True.

    sources : List
        Mainly relevant for undirected forests, specifies which nodes to list
        first. If unspecified the root nodes of each tree will be used for
        directed forests; for undirected forests this defaults to the nodes
        with the smallest degree.

    write : callable
        Function to use to write to, if None new lines are appended to
        a list and returned. If set to the `print` function, lines will
        be written to stdout as they are generated. If specified,
        this function will return None. Defaults to None.

    ascii_only : Boolean
        If True only ASCII characters are used to construct the visualization

    Returns
    -------
    str | None :
        utf8 representation of the tree / forest

    Example
    -------
    >>> graph = nx.balanced_tree(r=2, h=3, create_using=nx.DiGraph)
    >>> print(nx.forest_str(graph))
    ╙── 0
        ├─╼ 1
        │   ├─╼ 3
        │   │   ├─╼ 7
        │   │   └─╼ 8
        │   └─╼ 4
        │       ├─╼ 9
        │       └─╼ 10
        └─╼ 2
            ├─╼ 5
            │   ├─╼ 11
            │   └─╼ 12
            └─╼ 6
                ├─╼ 13
                └─╼ 14


    >>> graph = nx.balanced_tree(r=1, h=2, create_using=nx.Graph)
    >>> print(nx.forest_str(graph))
    ╙── 0
        └── 1
            └── 2

    >>> print(nx.forest_str(graph, ascii_only=True))
    +-- 0
        L-- 1
            L-- 2
        N+z+-- z    u   :   u   |   zL-> z|-> zL-- z|-- u   ╙u
   ╙── u
   ╟── u   ╎   u   │   u
   └─╼ u
   ├─╼ u
   └── u
   ├── z)input must be a forest or the empty graphc                    s   g | ]} j | d kr|qS )r   )Z	in_degree).0ngraph S/var/www/html/django/DPS/env/lib/python3.9/site-packages/networkx/readwrite/text.py
<listcomp>|       zforest_str.<locals>.<listcomp>c                    s    g | ]}t | fd ddqS )c                    s
    j |  S )N)Zdegree)r   r   r   r	   <lambda>   r   z'forest_str.<locals>.<listcomp>.<lambda>)key)min)r   ccr   r   r	   r
      s      c                    s   g | ]\}}|d | kfqS ) r   )r   idxnode)last_idxr   r	   r
      r   labelc                    s   g | ]}| vr|qS r   r   )r   child)seenr   r	   r
      r   )start
)ZnetworkxappendlennodesZ	is_forestZNetworkXNotImplementedis_directedsuccZadjZconnected_components	enumeratesetpopaddgetstrjoin) r   Zwith_labelssourceswrite
ascii_onlynxZprintbuf_writeZglyph_emptyZglyph_newtree_lastZglyph_newtree_midZglyph_endof_forestZglyph_within_forestZglyph_within_treeZglyph_directed_lastZglyph_directed_midZglyph_undirected_lastZglyph_undirected_midr   r   stackr   indentZislastZthis_prefixZnext_prefixr   childrenr   r   Zislast_nextZ	try_framer   )r   r   r   r	   r      s    A











)TNNF)__doc____all__r   r   r   r   r	   <module>   s   