B
    nc                 @   s   d dl Z G dd deZdS )    Nc               @   s   e Zd ZdZdd Zdd ZG dd deZG dd	 d	eZG d
d deZ	G dd deZ
G dd deZdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )PhysicsFc             C   s
   | j | S )N)__dict__)selfitem r   ,lib/python3.7/site-packages/pyvis/physics.py__getitem__   s    zPhysics.__getitem__c             C   s
   t | jS )N)strr   )r   r   r   r   __repr__   s    zPhysics.__repr__c               @   s   e Zd ZdZdd ZdS )zPhysics.barnesHutzt
        BarnesHut is a quadtree based gravity model.
        This is the fastest, default and recommended.
        c             C   s@   |d | _ |d | _|d | _|d | _|d | _|d | _d S )Ngravitycentral_gravityspring_lengthspring_strengthdampingoverlap)gravitationalConstantcentralGravityspringLengthspringConstantr   avoidOverlap)r   paramsr   r   r   __init__   s    




zPhysics.barnesHut.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   	barnesHut   s   r   c               @   s   e Zd ZdZdd ZdS )zPhysics.forceAtlas2Baseda
  
        Force Atlas 2 has been develoved by Jacomi et all (2014)
        for use with Gephi. The force Atlas based solver makes use
        of some of the equations provided by them and makes use of
        some of the barnesHut implementation in vis. The Main differences
        are the central gravity model, which is here distance independent,
        and repulsion being linear instead of quadratic. Finally, all node
        masses have a multiplier based on the amount of connected edges
        plus one.
        c             C   s@   |d | _ |d | _|d | _|d | _|d | _|d | _d S )Nr   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   (   s    




z!Physics.forceAtlas2Based.__init__N)r   r   r   r   r   r   r   r   r   forceAtlas2Based   s   
r   c               @   s   e Zd ZdZdd ZdS )zPhysics.Repulsionz
        The repulsion model assumes nodes have a simplified field
        around them. Its force lineraly decreases from 1
        (at 0.5*nodeDistace and smaller) to 0 (at 2*nodeDistance)
        c             C   s6   |d | _ |d | _|d | _|d | _|d | _d S )Nnode_distancer   r   r   r   )nodeDistancer   r   r   r   )r   r   r   r   r   r   6   s
    



zPhysics.Repulsion.__init__N)r   r   r   r   r   r   r   r   r   	Repulsion0   s   r    c               @   s   e Zd ZdZdd ZdS )zPhysics.hierarchicalRepulsionz
        This model is based on the repulsion solver but the levels
        are taken into accound and the forces
        are normalized.
        c             C   s6   |d | _ |d | _|d | _|d | _|d | _d S )Nr   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   C   s
    



z&Physics.hierarchicalRepulsion.__init__N)r   r   r   r   r   r   r   r   r   hierarchicalRepulsion=   s   r!   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	zPhysics.StabilizationzS
        This makes the network stabilized on load using default settings.
        c             C   s
   | j | S )N)r   )r   r   r   r   r   r   N   s    z!Physics.Stabilization.__getitem__c             C   s"   d| _ d| _d| _d| _d| _d S )NTi  2   F)enabledZ
iterationsZupdateIntervalZonlyDynamicEdgesZfit)r   r   r   r   r   Q   s
    zPhysics.Stabilization.__init__c             C   s
   || _ d S )N)r#   )r   statusr   r   r   toggle_stabilizationX   s    z*Physics.Stabilization.toggle_stabilizationN)r   r   r   r   r   r   r%   r   r   r   r   StabilizationJ   s   r&   c             C   s   d| _ |  | _d S )NT)r#   r&   stabilization)r   r   r   r   r   [   s    zPhysics.__init__c             C   s   |  || _ d S )N)r   )r   r   r   r   r   use_barnes_hut_   s    zPhysics.use_barnes_hutc             C   s   |  || _ d| _d S )Nr   )r   solver)r   r   r   r   r   use_force_atlas_2basedb   s    zPhysics.use_force_atlas_2basedc             C   s   |  || _d| _d S )N	repulsion)r    r+   r)   )r   r   r   r   r   use_repulsionf   s    zPhysics.use_repulsionc             C   s   |  || _ d| _d S )Nr!   )r!   r)   )r   r   r   r   r   use_hrepulsionj   s    zPhysics.use_hrepulsionc             C   s   | j | d S )N)r'   r%   )r   r$   r   r   r   r%   n   s    zPhysics.toggle_stabilizationc             C   s   t j| dd dddS )Nc             S   s   | j S )N)r   )or   r   r   <lambda>s       z!Physics.to_json.<locals>.<lambda>T   )defaultZ	sort_keysindent)jsondumps)r   r   r   r   to_jsonq   s    zPhysics.to_jsonN)r   r   r   Zengine_chosenr   r
   objectr   r   r    r!   r&   r   r(   r*   r,   r-   r%   r6   r   r   r   r   r      s   r   )r4   r7   r   r   r   r   r   <module>   s   