
    -Ph#                     n    d dl Z d dlmZ d dlmZ d dlmZ dde j        dz  dfdZ G d	 d
e	          Z
dS )    N)
exceptions)
graph_objs)utilsg?g333333?	   c           
         t          j        | |||           t          j        ||           |t          | ||||||          }	nt          | |||||||          }	|	                                \  }
}|	                                \  }}t          j        d|
|z   ||z   dd|}|g}|t          j        d          }n%t          j        dt          |d          	          }t          j
        ||
          S )a
  
    Returns data for a quiver plot.

    :param (list|ndarray) x: x coordinates of the arrow locations
    :param (list|ndarray) y: y coordinates of the arrow locations
    :param (list|ndarray) u: x components of the arrow vectors
    :param (list|ndarray) v: y components of the arrow vectors
    :param (float in [0,1]) scale: scales size of the arrows(ideally to
        avoid overlap). Default = .1
    :param (float in [0,1]) arrow_scale: value multiplied to length of barb
        to get length of arrowhead. Default = .3
    :param (angle in radians) angle: angle of arrowhead. Default = pi/9
    :param (positive float) scaleratio: the ratio between the scale of the y-axis
        and the scale of the x-axis (scale_y / scale_x). Default = None, the
        scale ratio is not fixed.
    :param kwargs: kwargs passed through plotly.graph_objs.Scatter
        for more information on valid kwargs call
        help(plotly.graph_objs.Scatter)

    :rtype (dict): returns a representation of quiver figure.

    Example 1: Trivial Quiver

    >>> from plotly.figure_factory import create_quiver
    >>> import math

    >>> # 1 Arrow from (0,0) to (1,1)
    >>> fig = create_quiver(x=[0], y=[0], u=[1], v=[1], scale=1)
    >>> fig.show()


    Example 2: Quiver plot using meshgrid

    >>> from plotly.figure_factory import create_quiver

    >>> import numpy as np
    >>> import math

    >>> # Add data
    >>> x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
    >>> u = np.cos(x)*y
    >>> v = np.sin(x)*y

    >>> #Create quiver
    >>> fig = create_quiver(x, y, u, v)
    >>> fig.show()


    Example 3: Styling the quiver plot

    >>> from plotly.figure_factory import create_quiver
    >>> import numpy as np
    >>> import math

    >>> # Add data
    >>> x, y = np.meshgrid(np.arange(-np.pi, math.pi, .5),
    ...                    np.arange(-math.pi, math.pi, .5))
    >>> u = np.cos(x)*y
    >>> v = np.sin(x)*y

    >>> # Create quiver
    >>> fig = create_quiver(x, y, u, v, scale=.2, arrow_scale=.3, angle=math.pi/6,
    ...                     name='Wind Velocity', line=dict(width=1))

    >>> # Add title to layout
    >>> fig.update_layout(title='Quiver Plot') # doctest: +SKIP
    >>> fig.show()


    Example 4: Forcing a fix scale ratio to maintain the arrow length

    >>> from plotly.figure_factory import create_quiver
    >>> import numpy as np

    >>> # Add data
    >>> x,y = np.meshgrid(np.arange(0.5, 3.5, .5), np.arange(0.5, 4.5, .5))
    >>> u = x
    >>> v = y
    >>> angle = np.arctan(v / u)
    >>> norm = 0.25
    >>> u = norm * np.cos(angle)
    >>> v = norm * np.sin(angle)

    >>> # Create quiver with a fix scale ratio
    >>> fig = create_quiver(x, y, u, v, scale = 1, scaleratio = 0.5)
    >>> fig.show()
    )arrow_scalescaleNlines)xymodeclosest)	hovermoder   )
scaleratioscaleanchor)r   yaxis)datalayout )r   validate_equal_lengthvalidate_positive_scalars_Quiver	get_barbsget_quiver_arrowsr   ScatterLayoutdictFigure)r   r   uvr	   r   angler   kwargs
quiver_objbarb_xbarb_yarrow_xarrow_yquiver_plotr   r   s                    ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/figure_factory/_quiver.pycreate_quiverr*      s3   t 
1a+++	#5IIIIQ1aUCC

Q1aUJOO
))++NFF!3355GW$ 
7
fw.W @F K =D"Y777"tzs'S'S'S
 
 
 $v6666    c                   ,    e Zd ZdZddZd Zd Zd ZdS )	r   z>
    Refer to FigureFactory.create_quiver() for docstring
       c	                 n   	 t          j        |          }n# t          j        $ r Y nw xY w	 t          j        |          }n# t          j        $ r Y nw xY w	 t          j        |          }n# t          j        $ r Y nw xY w	 t          j        |          }n# t          j        $ r Y nw xY w|| _        || _        || _        || _        || _        || _	        || _
        || _        g | _        g | _        |                                  |                                 \  }
}|                                 \  }}d S )N)r   flattenr   PlotlyErrorr   r   r   r    r	   r   r   r!   end_xend_yscale_uvr   r   )selfr   r   r   r    r	   r   r!   r   r"   r$   r%   r&   r'   s                 r)   __init__z_Quiver.__init__   si   	a  AA% 	 	 	D		a  AA% 	 	 	D		a  AA% 	 	 	D		a  AA% 	 	 	D	 
$&


))1133sA    ))A AAA- -A?>A?B B*)B*c                 h      fd j         D              _          fd j        D              _        dS )z
        Scales u and v to avoid overlap of the arrows.

        u and v are added to x and y to get the
        endpoints of the arrows so a smaller scale value will
        result in less overlap of arrows.
        c                 4    g | ]}|j         z  j        z  S r   )r	   r   .0ir4   s     r)   
<listcomp>z$_Quiver.scale_uv.<locals>.<listcomp>   s&    CCCq!dj.4?2CCCr+   c                 $    g | ]}|j         z  S r   )r	   r8   s     r)   r;   z$_Quiver.scale_uv.<locals>.<listcomp>   s    111Q!dj.111r+   N)r   r    )r4   s   `r)   r3   z_Quiver.scale_uv   sD     DCCCDFCCC1111$&111r+   c                    d t          | j        | j                  D             | _        d t          | j        | j                  D             | _        dgt          | j                  z  }t          j	        t          | j        | j        |                    }t          j	        t          | j        | j        |                    }||fS )a  
        Creates x and y startpoint and endpoint pairs

        After finding the endpoint of each barb this zips startpoint and
        endpoint pairs to create 2 lists: x_values for barbs and y values
        for barbs

        :rtype: (list, list) barb_x, barb_y: list of startpoint and endpoint
            x_value pairs separated by a None to create the barb of the arrow,
            and list of startpoint and endpoint y_value pairs separated by a
            None to create the barb of the arrow.
        c                     g | ]
\  }}||z   S r   r   r9   r:   js      r)   r;   z%_Quiver.get_barbs.<locals>.<listcomp>        <<<1a!e<<<r+   c                     g | ]
\  }}||z   S r   r   r?   s      r)   r;   z%_Quiver.get_barbs.<locals>.<listcomp>   rA   r+   N)
zipr   r   r1   r   r    r2   lenr   r/   )r4   emptyr$   r%   s       r)   r   z_Quiver.get_barbs   s     =<DFDF(;(;<<<
<<DFDF(;(;<<<
TV$s464:u==>>s464:u==>>v~r+   c                     d t           j         j                  D             }d t           j         j                  D             }dgt           j                  z  }t          t          |                    D ].}t          j        ||          j	        z  ||                   ||<   /dgt           j                  z  } fd|D             }dgt           j                  z  }t          t          |                    D ].}t          j
        ||         ||          j	        z            ||<   / fd|D             } fd|D             }dgt          |          z  }	t          t          |                    D ]}t          j        ||                   |	|<    d t          ||	          D             }
dgt          |          z  }t          t          |                    D ]}t          j        ||                   ||<    d t          ||          D             }dgt          |          z  }t          t          |                    D ]}t          j        ||                   ||<    d	 t          ||          D             }dgt          |          z  }t          t          |                    D ]}t          j        ||                   ||<    d
 t          ||          D             }t          t           j                            D ]} fdt           j        |
          D             }d t           j        |          D             } fdt           j        |          D             }d t           j        |          D             }dgt           j                  z  }t          j        t          | j        ||                    }t          j        t          | j        ||                    }||fS )a0  
        Creates lists of x and y values to plot the arrows

        Gets length of each barb then calculates the length of each side of
        the arrow. Gets angle of barb and applies angle to each side of the
        arrowhead. Next uses arrow_scale to scale the length of arrowhead and
        creates x and y values for arrowhead point1 and point2. Finally x and y
        values for point1, endpoint and point2s for each arrowhead are
        separated by a None and zipped to create lists of x and y values for
        the arrows.

        :rtype: (list, list) arrow_x, arrow_y: list of point1, endpoint, point2
            x_values separated by a None to create the arrowhead and list of
            point1, endpoint, point2 y_values separated by a None to create
            the barb of the arrow.
        c                     g | ]
\  }}||z
  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>        ;;;41aQ;;;r+   c                     g | ]
\  }}||z
  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   rH   r+   Nc                 $    g | ]}|j         z  S r   )r   r8   s     r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   s!    <<<aQ))<<<r+   c                 $    g | ]}|j         z   S r   r!   r8   s     r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>       1111DJ111r+   c                 $    g | ]}|j         z
  S r   rL   r8   s     r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   rM   r+   c                     g | ]
\  }}||z  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>        ===DAq!a%===r+   c                     g | ]
\  }}||z  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   rP   r+   c                     g | ]
\  }}||z  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   rP   r+   c                     g | ]
\  }}||z  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   rP   r+   c                 0    g | ]\  }}||j         z  z
  S r   r   r9   r:   r@   r4   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>   )    TTTDAqA//TTTr+   c                     g | ]
\  }}||z
  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>       BBB$!QABBBr+   c                 0    g | ]\  }}||j         z  z
  S r   rU   rV   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>  rW   r+   c                     g | ]
\  }}||z
  S r   r   r?   s      r)   r;   z-_Quiver.get_quiver_arrows.<locals>.<listcomp>  rY   r+   )rC   r1   r   r2   r   rD   rangemathhypotr   atan2cossinr   r/   )r4   dif_xdif_ybarb_lenindex	arrow_lenbarb_angang1ang2cos_ang1seg1_xsin_ang1seg1_ycos_ang2seg2_xsin_ang2seg2_ypoint1_xpoint1_ypoint2_xpoint2_yrE   r&   r'   s   `                       r)   r   z_Quiver.get_quiver_arrows   s    " <;3tz46#:#:;;;;;3tz46#:#:;;; 6CKK'3x==)) 	W 	WE"ju)GuVVHUOO FS[[(	<<<<8<<<	 6CKK'3x==)) 	W 	WE"juuU|do7UVVHUOO 211111111111116CII%3t99%% 	4 	4E"htE{33HUOO==C	8$<$<===6CII%3t99%% 	4 	4E"htE{33HUOO==C	8$<$<===6CII%3t99%% 	4 	4E"htE{33HUOO==C	8$<$<===6CII%3t99%% 	4 	4E"htE{33HUOO==C	8$<$<=== 3tz??++ 	C 	CETTTTC
F<S<STTTHBB#dj&*A*ABBBHTTTTC
F<S<STTTHBB#dj&*A*ABBBHH TZ(-Hdj(E J JKK-Hdj(E J JKKr+   N)r-   )__name__
__module____qualname____doc__r5   r3   r   r   r   r+   r)   r   r   }   se         !4 !4 !4 !4F	2 	2 	2  (E  E  E  E  E r+   r   )r]   plotlyr   plotly.graph_objsr   plotly.figure_factoryr   pir*   objectr   r   r+   r)   <module>r      s           ( ( ( ( ( ( ' ' ' ' ' ' s$'A+$r7 r7 r7 r7jL  L  L  L  L f L  L  L  L  L r+   