ó
 ,µ[c           @   sb   d  Z  d d l Z d d l Z d d l m Z d d g Z d d  Z e d  d d   Z	 d S(	   s  
Read and write NetworkX graphs as JavaScript InfoVis Toolkit (JIT) format JSON.

See the `JIT documentation`_ for more examples.

Format
------
var json = [
  {
    "id": "aUniqueIdentifier",
    "name": "usually a nodes name",
    "data": {
      "some key": "some value",
      "some other key": "some other value"
     },
    "adjacencies": [
    {
      nodeTo:"aNodeId",
      data: {} //put whatever you want here
    },
    'other adjacencies go here...'
  },

  'other nodes go here...'
];
.. _JIT documentation: http://thejit.org
i’’’’N(   t   not_implemented_fort	   jit_grapht   jit_datac         C   s¤   | d k r t j   } n | } | j   xr |  D]j } | j | d | d  | j d  d k	 r2 x4 | d D]% } | j | d | d | d  qp Wq2 q2 W| S(   s;  Read a graph from JIT JSON.

    Parameters
    ----------
    data : JSON Graph Object

    create_using : Networkx Graph, optional (default: Graph())
        Return graph of this type. The provided instance will be cleared.

    Returns
    -------
    G : NetworkX Graph built from create_using if provided.
    t   idt   datat   adjacenciest   nodeToN(   t   Nonet   nxt   Grapht   cleart   add_nodet   gett   add_edge(   R   t   create_usingt   Gt   nodet   adj(    (    s@   lib/python2.7/site-packages/networkx/readwrite/json_graph/jit.pyR   +   s    
*t
   multigraphc         C   sĆ   g  } x§ |  j    D] } i | d 6| d 6} |  j  | | d <|  | r g  | d <xJ |  | D]; } i | d 6} |  j | | f | d <| d j |  q] Wn  | j |  q Wt j | d | S(   sĖ  Return data in JIT JSON format.

    Parameters
    ----------
    G : NetworkX Graph

    indent: optional, default=None
        If indent is a non-negative integer, then JSON array elements and object
        members will be pretty-printed with that indent level. An indent level
        of 0, or negative, will only insert newlines. None (the default) selects
        the most compact representation.

    Returns
    -------
    data: JIT JSON string
    R   t   nameR   R   R   t   indent(   t   nodest   edgest   appendt   jsont   dumps(   R   R   t
   json_graphR   t	   json_nodet	   neighbourt	   adjacency(    (    s@   lib/python2.7/site-packages/networkx/readwrite/json_graph/jit.pyR   G   s    



(
   t   __doc__R   t   networkxR   t   networkx.utils.decoratorsR    t   __all__R   R   R   (    (    (    s@   lib/python2.7/site-packages/networkx/readwrite/json_graph/jit.pyt   <module>"   s   	