o
    ßË·eÎ  ã                   @   s(   d dl ZddgZddd„Zddd„ZdS )	é    NÚcytoscape_dataÚcytoscape_graphÚnameÚidc                 C   sØ  |durddl }d}|j|tdd |d }|d }||kr#t d¡‚d	t| j ¡ ƒi}|  ¡ |d
< |  	¡ |d< g g dœ|d< |d d }|d d }| j
 ¡ D ]/\}	}
d	|
 ¡ i}|
 |¡pbt|	ƒ|d	 d< |	|d	 d< |
 |¡put|	ƒ|d	 d< | |¡ qP|  	¡ r¿| jddD ]2}d	| j|d  |d  |d   ¡ i}|d |d	 d< |d |d	 d< |d |d	 d< | |¡ qŠ|S |  ¡ D ]&}d	| j|d  |d   ¡ i}|d |d	 d< |d |d	 d< | |¡ qÃ|S )at  Returns data in Cytoscape JSON format (cyjs).

    Parameters
    ----------
    G : NetworkX Graph
        The graph to convert to cytoscape format
    attrs : dict or None (default=None)
        A dictionary containing the keys 'name' and 'ident' which are mapped to
        the 'name' and 'id' node elements in cyjs format. All other keys are
        ignored. Default is `None` which results in the default mapping
        ``dict(name="name", ident="id")``.

        .. deprecated:: 2.6

           The `attrs` keyword argument will be replaced with `name` and
           `ident` in networkx 3.0

    name : string
        A string which is mapped to the 'name' node element in cyjs format.
        Must not have the same value as `ident`.
    ident : string
        A string which is mapped to the 'id' node element in cyjs format.
        Must not have the same value as `name`.

    Returns
    -------
    data: dict
        A dictionary with cyjs formatted data.

    Raises
    ------
    NetworkXError
        If the values for `name` and `ident` are identical.

    See Also
    --------
    cytoscape_graph: convert a dictionary in cyjs format to a graph

    References
    ----------
    .. [1] Cytoscape user's manual:
       http://manual.cytoscape.org/en/stable/index.html

    Examples
    --------
    >>> G = nx.path_graph(2)
    >>> nx.cytoscape_data(G)  # doctest: +SKIP
    {'data': [],
     'directed': False,
     'multigraph': False,
     'elements': {'nodes': [{'data': {'id': '0', 'value': 0, 'name': '0'}},
       {'data': {'id': '1', 'value': 1, 'name': '1'}}],
      'edges': [{'data': {'source': 0, 'target': 1}}]}}
    Nr   aû  
The `attrs` keyword argument of cytoscape_data is deprecated
and will be removed in networkx 3.0.
It is replaced with explicit `name` and `ident` keyword
arguments.
To make this warning go away and ensure usage is forward
compatible, replace `attrs` with `name` and `ident`,
for example:

   >>> cytoscape_data(G, attrs={'name': 'foo', 'ident': 'bar'})

should instead be written as

   >>> cytoscape_data(G, name='foo', ident='bar')

in networkx 3.0.
The default values of 'name' and 'id' will not change.é   ©Ú
stacklevelr   Úidentú!name and ident must be different.ÚdataÚdirectedÚ
multigraph)ÚnodesÚedgesÚelementsr   r   r   ÚvalueT)Úkeysé   ÚsourceÚtargetÚkey)ÚwarningsÚwarnÚDeprecationWarningÚnxÚNetworkXErrorÚlistÚgraphÚitemsÚis_directedÚis_multigraphr   ÚcopyÚgetÚstrÚappendr   Úadj)ÚGÚattrsr   r	   r   ÚmsgÚjsondatar   r   ÚiÚjÚnÚe© r.   ú^/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/readwrite/json_graph/cytoscape.pyr      sF   8ÿ
&ûc                 C   s¦  |durddl }d}|j|tdd |d }|d }||kr#t d¡‚|  d	¡}|  d
¡}|r4t ¡ }nt ¡ }|r>| ¡ }t	|  d¡ƒ|_
| d d D ];}	|	d  ¡ }
|	d d }|	d  |¡rj|	d  |¡|
|< |	d  |¡rz|	d  |¡|
|< | |¡ |j|  |
¡ qL| d d D ]B}	|	d  ¡ }|	d d }|	d d }|rÀ|	d  dd¡}|j|||d |j|||f  |¡ qŽ| ||¡ |j||f  |¡ qŽ|S )a  
    Create a NetworkX graph from a dictionary in cytoscape JSON format.

    Parameters
    ----------
    data : dict
        A dictionary of data conforming to cytoscape JSON format.
    attrs : dict or None (default=None)
        A dictionary containing the keys 'name' and 'ident' which are mapped to
        the 'name' and 'id' node elements in cyjs format. All other keys are
        ignored. Default is `None` which results in the default mapping
        ``dict(name="name", ident="id")``.

        .. deprecated:: 2.6

           The `attrs` keyword argument will be replaced with `name` and
           `ident` in networkx 3.0

    name : string
        A string which is mapped to the 'name' node element in cyjs format.
        Must not have the same value as `ident`.
    ident : string
        A string which is mapped to the 'id' node element in cyjs format.
        Must not have the same value as `name`.

    Returns
    -------
    graph : a NetworkX graph instance
        The `graph` can be an instance of `Graph`, `DiGraph`, `MultiGraph`, or
        `MultiDiGraph` depending on the input data.

    Raises
    ------
    NetworkXError
        If the `name` and `ident` attributes are identical.

    See Also
    --------
    cytoscape_data: convert a NetworkX graph to a dict in cyjs format

    References
    ----------
    .. [1] Cytoscape user's manual:
       http://manual.cytoscape.org/en/stable/index.html

    Examples
    --------
    >>> data_dict = {
    ...     'data': [],
    ...     'directed': False,
    ...     'multigraph': False,
    ...     'elements': {'nodes': [{'data': {'id': '0', 'value': 0, 'name': '0'}},
    ...       {'data': {'id': '1', 'value': 1, 'name': '1'}}],
    ...      'edges': [{'data': {'source': 0, 'target': 1}}]}
    ... }
    >>> G = nx.cytoscape_graph(data_dict)
    >>> G.name
    ''
    >>> G.nodes()
    NodeView((0, 1))
    >>> G.nodes(data=True)[0]
    {'id': '0', 'value': 0, 'name': '0'}
    >>> G.edges(data=True)
    EdgeDataView([(0, 1, {'source': 0, 'target': 1})])
    Nr   aê  
The `attrs` keyword argument of cytoscape_data is deprecated
and will be removed in networkx 3.0.
It is replaced with explicit `name` and `ident` keyword
arguments.
To make this warning go away and ensure usage is forward
compatible, replace `attrs` with `name` and `ident`,
for example:

   >>> cytoscape_data(G, attrs={'name': 'foo', 'ident': 'bar'})

should instead be written as

   >>> cytoscape_data(G, name='foo', ident='bar')

The default values of 'name' and 'id' will not change.r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   )r   )r   r   r   r   r   r"   Ú
MultiGraphÚGraphÚto_directedÚdictr   r!   Úadd_noder   ÚupdateÚadd_edger   )r   r'   r   r	   r   r(   r   r   r   ÚdÚ	node_dataÚnodeÚ	edge_dataÚsourÚtargr   r.   r.   r/   r   v   sJ   Cÿ




)Nr   r   )Únetworkxr   Ú__all__r   r   r.   r.   r.   r/   Ú<module>   s    
p