
    6Dh#                     r    S SK r S SKJr  S SKJr  S SKJr  SS\ R                  S-  S4S jr " S	 S
\	5      r
g)    N)
exceptions)
graph_objs)utilsg?g333333?	   c           
         [         R                  " XX#5        [         R                  " XTS9  Uc  [        XX#XEU5      n	O[        XX#XEXg5      n	U	R	                  5       u  pU	R                  5       u  p[        R                  " S
X-   X-   SS.UD6nU/nUc  [        R                  " SS9nO[        R                  " S[        USS9S9n[        R                  " UUS	9$ )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scale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                    O/var/www/html/env/lib/python3.13/site-packages/plotly/figure_factory/_quiver.pycreate_quiverr*      s    t 
a+	##IQ1UC
Q1UO
))+NF!335G$$ 

f.W@FK =D""Y7""tzs'S
 $v66    c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
r   }   z6
Refer to FigureFactory.create_quiver() for docstring
c	                 p    [         R                  " U5      n [         R                  " U5      n [         R                  " U5      n [         R                  " U5      nXl        X l        X0l        X@l        XPl        Xl	        X`l
        Xpl        / U l        / U l        U R                  5         U R                  5       u  pU R!                  5       u  pg ! [        R                   a     Nf = f! [        R                   a     Nf = f! [        R                   a     Nf = f! [        R                   a     Nf = f)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___Quiver.__init__   s   	a A	a A	a A	a A 
$&


)113= %% 		
 %% 		
 %% 		
 %% 		sE   C C* D D C'&C'*D DDDD54D5c                     U R                    Vs/ s H  oU R                  -  U R                  -  PM      snU l         U R                   Vs/ s H  oU R                  -  PM     snU l        gs  snf s  snf )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.
N)r   r	   r   r    )r4   is     r)   r3   _Quiver.scale_uv   sW     =AFFCFqdjj.4??2FC*.&&1&Qdjj.&1 D1s   %A+
A0c                    [        U R                  U R                  5       VVs/ s H	  u  pX-   PM     snnU l        [        U R                  U R
                  5       VVs/ s H	  u  pX-   PM     snnU l        S/[        U R                  5      -  n[        R                  " [        U R                  U R                  U5      5      n[        R                  " [        U R                  U R                  U5      5      nXE4$ s  snnf s  snnf )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.
N)
zipr   r   r1   r   r    r2   lenr   r/   )r4   r8   jemptyr$   r%   s         r)   r   _Quiver.get_barbs   s     ),DFFDFF(;<(;ae(;<
(+DFFDFF(;<(;ae(;<
TVV$s4664::u=>s4664::u=>~ =<s   C? Dc                 	   [        U R                  U R                  5       VVs/ s H	  u  pX-
  PM     nnn[        U R                  U R                  5       VVs/ s H	  u  pX-
  PM     nnnS/[        U R                  5      -  n[        [        U5      5       H-  n[        R                  " X6   U R                  -  XF   5      XV'   M/     S/[        U R                  5      -  nU Vs/ s H  oU R                  -  PM     nnS/[        U R                  5      -  n[        [        U5      5       H-  n[        R                  " XF   X6   U R                  -  5      X'   M/     U Vs/ s H  oU R                  -   PM     n	nU Vs/ s H  oU R                  -
  PM     n
nS/[        U	5      -  n[        [        U	5      5       H  n[        R                  " X   5      X'   M     [        X{5       VVs/ s H	  u  pX-  PM     nnnS/[        U	5      -  n[        [        U	5      5       H  n[        R                  " X   5      X'   M     [        X}5       VVs/ s H	  u  pX-  PM     nnnS/[        U
5      -  n[        [        U
5      5       H  n[        R                  " X   5      X'   M     [        X5       VVs/ s H	  u  pX-  PM     nnnS/[        U
5      -  n[        [        U
5      5       H  n[        R                  " X   5      UU'   M      [        UU5       VVs/ s H	  u  pX-  PM     nnn[        [        U R                  5      5       H  n[        U R                  U5       VVs/ s H  u  pXU R                  -  -
  PM     nnn[        U R                  U5       VVs/ s H	  u  pX-
  PM     nnn[        U R                  U5       VVs/ s H  u  pXU R                  -  -
  PM     nnn[        U R                  U5       VVs/ s H	  u  pX-
  PM     nnnM     S/[        U R                  5      -  n[        R                   " [        WU R                  WU5      5      n[        R                   " [        WU R                  WU5      5      nUU4$ s  snnf s  snnf s  snf s  snf s  snf s  snnf s  snnf s  snnf s  snnf s  snnf s  snnf s  snnf s  snnf )a  
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.
N)r;   r1   r   r2   r   r<   rangemathhypotr   r   atan2r!   cossinr   r/   )r4   r8   r=   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_yr>   r&   r'   s                             r)   r   _Quiver.get_quiver_arrows   s   " $'tzz466#:;#:41#:;#&tzz466#:;#:41#:; 6CK'3x=)E"jj)GVHO * FS[(	3;<8a)))8	< 6CK'3x=)E"jju|doo7UVHO * )111DJJ1(011DJJ16CI%3t9%E"hht{3HO &$'	$<=$<DA!%$<=6CI%3t9%E"hht{3HO &$'	$<=$<DA!%$<=6CI%3t9%E"hht{3HO &$'	$<=$<DA!%$<=6CI%3t9%E"hht{3HUO &$'	8$<=$<DA!%$<= 3tzz?+E<?

F<ST<SDA//<SHT*-djj&*AB*A$!*AHB<?

F<ST<SDA//<SHT*-djj&*AB*A$!*AHBH	 , TZZ(--Hdjj(E JK--Hdjj(E JKi <; = 21
 >
 >
 >
 > UBTBsM   RR(R"$R'R,.R1R78R=S,S	%SS
S)
r!   r   r1   r2   r	   r   r   r    r   r   N)   )
__name__
__module____qualname____firstlineno____doc__r5   r3   r   r   __static_attributes__r   r+   r)   r   r   }   s    !4F	2(E r+   r   )rB   plotlyr   plotly.graph_objsr   plotly.figure_factoryr   pir*   objectr   r   r+   r)   <module>rh      s9      ( ' s$''A+$r7jL f L r+   