
    \Mh                     V    d dl ZddgZd
dZ ej        dd          d
d	            ZdS )    Ncytoscape_datacytoscape_graphnameidc                    ||k    rt          j        d          dt          | j                                                  i}|                                 |d<   |                                 |d<   g g d|d<   |d         d         }|d         d         }| j                                        D ]\  }}d|                                i}|	                    |          pt          |          |d         d	<   ||d         d
<   |	                    |          pt          |          |d         d<   |                    |           |                                 r|                     d          D ]}	d| j        |	d                  |	d                  |	d                                                  i}|	d         |d         d<   |	d         |d         d<   |	d         |d         d<   |                    |           n|                                 D ]l}	d| j        |	d                  |	d                                                  i}|	d         |d         d<   |	d         |d         d<   |                    |           m|S )a  Returns data in Cytoscape JSON format (cyjs).

    Parameters
    ----------
    G : NetworkX Graph
        The graph to convert to cytoscape format
    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
    --------
    >>> from pprint import pprint
    >>> G = nx.path_graph(2)
    >>> cyto_data = nx.cytoscape_data(G)
    >>> pprint(cyto_data, sort_dicts=False)
    {'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}}]}}

    The :mod:`json` package can be used to serialize the resulting data

    >>> import io, json
    >>> with io.StringIO() as fh:  # replace io with `open(...)` to write to disk
    ...     json.dump(cyto_data, fh)
    ...     fh.seek(0)  # doctest: +SKIP
    ...     print(fh.getvalue()[:64])  # View the first 64 characters
    {"data": [], "directed": false, "multigraph": false, "elements":

    !name and ident must be different.datadirected
multigraph)nodesedgeselementsr   r   r   valuer   T)keysr         sourcetargetkey)nxNetworkXErrorlistgraphitemsis_directedis_multigraphr   copygetstrappendr   adj)
Gr   identjsondatar   r   ijnes
             g/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/readwrite/json_graph/cytoscape.pyr   r      sN   p u}}BCCCQW]]__--.H==??HZ__..H\%'"55HZZ )EZ )E  1QVVXX%%,,0#a&&&	$&	'EE$KK13q66&	&Q d## 	 	AqtQqT*1Q4055778A"#A$AfIh"#A$AfIh tAfIeLLOOOO	  	 	AqtQqT*//112A"#A$AfIh"#A$AfIhLLOOOOO    T)graphsreturns_graphc                    ||k    rt          j        d          |                     d          }|                     d          }|rt          j                    }nt          j                    }|r|                                }t          |                     d                    |_        | d         d         D ]}|d                                         }|d         d         }|d                             |          r|d                             |          ||<   |d                             |          r|d                             |          ||<   |	                    |           |j
        |                             |           | d         d         D ]}|d                                         }	|d         d	         }
|d         d
         }|rX|d                             dd          }|                    |
||           |j        |
||f                             |	           |                    |
|           |j        |
|f                             |	           |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.
    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})])
    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   d	node_datanode	edge_datasourtargr   s                r)   r   r   _   sA   x u}}BCCC,''Jxx
##H 

 $!!##txx''((EK*g& 
, 
,fINN$$	y!V9== 	2immD11IdOV9== 	4 y}}U33IetD  ++++*g& 
6 
6fINN$$	y"y" 	6F)--q))CNN43N///KdC(//	::::NN4&&&Kd
#**95555Lr*   )r   r   )networkxr   __all__r   _dispatchabler    r*   r)   <module>r?      sx       .
/V V V Vr T222^ ^ ^ 32^ ^ ^r*   