
    e[                         d dl mZmZ d dlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddgZ G d de      Z G d de      Zy)    )atan2degreesN   )	functions)Point)QtCoreQtGui   )GraphicsItem)GraphicsObject)TextItem)ViewBoxInfiniteLineInfLineLabelc                   P   e Zd ZdZ ej
                  e      Z ej
                  e      Z ej
                  e      Z	 ej
                  ee      Z
	 	 	 ddZd Zd Zd Zd Zd Zdd	Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd dZd Zd Z d Z!d Z"d Z#d Z$d Z%y)!r   a  
    **Bases:** :class:`GraphicsObject <pyqtgraph.GraphicsObject>`

    Displays a line of infinite length.
    This line may be dragged to indicate a position in data coordinates.

    =============================== ===================================================
    **Signals:**
    sigDragged(self)
    sigPositionChangeFinished(self)
    sigPositionChanged(self)
    sigClicked(self, ev)
    =============================== ===================================================
    Nc                    d| _         || _        t        j                  |        |
ddg| _        n|| _        d| _        | j                  |       d| _        ddg| _        | j                  |       |t        dd      }| j                  |       |d}| j                  |       |,| j                  d| j                  j                                n| j                  |       |	| _        | j                  | _        g | _        d| _        |
|
D ]  } | j(                  |   ddg| _        d| _        d| _        ||i n|}t1        | fd|i|| _        yy)	a8  
        =============== ==================================================================
        **Arguments:**
        pos             Position of the line. This can be a QPointF or a single value for
                        vertical/horizontal lines.
        angle           Angle of line in degrees. 0 is horizontal, 90 is vertical.
        pen             Pen to use when drawing line. Can be any arguments that are valid
                        for :func:`mkPen <pyqtgraph.mkPen>`. Default pen is transparent
                        yellow.
        hoverPen        Pen to use when the mouse cursor hovers over the line. 
                        Only used when movable=True.
        movable         If True, the line can be dragged to a new position by the user.
        bounds          Optional [min, max] bounding values. Bounds are only valid if the
                        line is vertical or horizontal.
        hoverPen        Pen to use when drawing line when hovering over it. Can be any
                        arguments that are valid for :func:`mkPen <pyqtgraph.mkPen>`.
                        Default pen is red.
        label           Text to be displayed in a label attached to the line, or
                        None to show no label (default is None). May optionally
                        include formatting strings to display the line value.
        labelOpts       A dict of keyword arguments to use when constructing the
                        text label. See :class:`InfLineLabel <pyqtgraph.graphicsItems.InfiniteLine.InfLineLabel>`.
        span            Optional tuple (min, max) giving the range over the view to draw
                        the line. For example, with a vertical line, use span=(0.5, 1)
                        to draw only on the top half of the view.
        markers         List of (marker, position, size) tuples, one per marker to display
                        on the line. See the addMarker method.
        name            Name of the item
        =============== ==================================================================
        NFr   )   r   d   )   r   r   )colorwidthr
   text)_boundingRect_namer   __init__maxRangemoving
setMovablemouseHoveringpsetAngler   setPossetPensetHoverPenpenr   span
currentPenmarkers_maxMarkerSize	addMarker
_endPoints_bounds_lastViewSizer   label)selfposangler%   movableboundshoverPenr.   	labelOptsr&   r(   namems                F/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/InfiniteLine.pyr   zInfiniteLine.__init__%   s\   B "
%>!4LDM"DM "Qe;!*CC;!CC9DHHNN4DEX&	(( #"# a&!'/YI%dDD)DDJ     c                 4    || _         | j                  |       y)z,Set whether the line is movable by the user.Nr2   setAcceptHoverEventsr/   r7   s     r8   r   zInfiniteLine.setMovableu   s    !!!$r9   c                 P    || _         | j                  | j                                y)z:Set the (minimum, maximum) allowable values when dragging.N)r   setValuevalue)r/   r3   s     r8   	setBoundszInfiniteLine.setBoundsz   s    djjl#r9   c                      | j                   dd S )zDReturn the (minimum, maximum) values allowed when dragging.
        N)r   r/   s    r8   r3   zInfiniteLine.bounds   s     }}Qr9   c                     t        j                  |i || _        | j                  s"| j                  | _        | j                          yy)zySet the pen for drawing the line. Allowable arguments are any that are valid
        for :func:`mkPen <pyqtgraph.mkPen>`.N)fnmkPenr%   r   r'   update)r/   argskwargss      r8   r#   zInfiniteLine.setPen   s;     88T,V,!!"hhDOKKM "r9   c                    t        |      dk(  xr; t        |d   t        j                        xs t        |d   t              xr d|d   v xs d|v }t        j                  |i || _        |s3| j                  j                  | j                  j                                | j                  r"| j                  | _        | j                          yy)a  Set the pen for drawing the line while the mouse hovers over it.
        Allowable arguments are any that are valid
        for :func:`mkPen <pyqtgraph.mkPen>`.

        If the line is not movable, then hovering is also disabled.

        Added in version 0.9.9.r
   r   r   N)len
isinstancer	   QPendictrE   rF   r4   setWidthr%   r   r   r'   rG   )r/   rH   rI   widthSpecifieds       r8   r$   zInfiniteLine.setHoverPen   s     t9> O&tAw

; N&tAw5L'T!W:L1  '&0 	 $1&1MM""488>>#34"mmDOKKM r9   c                    t        j                         }|dk(  r'|j                  t        j                  dddd             d|v rWt        j
                  t        dd      t        dd      t        dd      g      }|j                  |       |j                          d|v rWt        j
                  t        dd      t        dd      t        dd      g      }|j                  |       |j                          d|v rWt        j
                  t        dd      t        dd      t        dd      g      }|j                  |       |j                          d	|v rWt        j
                  t        dd      t        dd      t        dd      g      }|j                  |       |j                          d
|v rWt        j
                  t        dd      t        dd      t        dd      g      }|j                  |       |j                          d|v rWt        j
                  t        dd      t        dd      t        dd      g      }|j                  |       |j                          | j                  j                  |||f       t        | j                  D cg c]
  }|d   dz   c}      | _        | j                          yc c}w )a  Add a marker to be displayed on the line. 
        
        ============= =========================================================
        **Arguments**
        marker        String indicating the style of marker to add:
                      ``'<|'``, ``'|>'``, ``'>|'``, ``'|<'``, ``'<|>'``,
                      ``'>|<'``, ``'^'``, ``'v'``, ``'o'``
        position      Position (0.0-1.0) along the visible extent of the line
                      to place the marker. Default is 0.5.
        size          Size of the marker in pixels. Default is 10.0.
        ============= =========================================================
        og      r
   z<|      ?r   z|>z>|z|<^vr   g       @N)r	   QPainterPath
addEllipser   QRectF	QPolygonFr   
addPolygoncloseSubpathr(   appendmaxr)   rG   )r/   markerpositionsizepathr    r7   s          r8   r*   zInfiniteLine.addMarker   s'    !!#S=OOFMM$a;<6>sAadA OPAOOA6>sAauT1~ NOAOOA6>sD!15A;dD@Q RSAOOA6>sC%1+uT3?O PQAOOA&=q$sAa NOAOOA&=q$tQq# OPAOOAT8T23!dll"C1Q4"9"CD #Ds   K c                 @    g | _         d| _        | j                          y)z, Remove all markers from this line.
        r   N)r(   r)   rG   rC   s    r8   clearMarkerszInfiniteLine.clearMarkers   s     r9   c                     || _         | j                          | j                  | j                          | j                          y)z
        Takes angle argument in degrees.
        0 is horizontal; 90 is vertical.

        Note that the use of value() and setValue() changes if the line is
        not vertical or horizontal.
        N)r1   resetTransformsetRotationrG   )r/   r1   s     r8   r!   zInfiniteLine.setAngle   s2     
$r9   c                    t        |t        t        t        j                  f      r$t        j
                  |      dk(  st        |      }nnt        |t        j                        r!|j                         |j                         g}n3| j                  dk(  r|dg}n| j                  dk(  rd|g}nt        d      | j                  dk(  r]| j                  d   t        |d   | j                  d         |d<   | j                  d   t        |d   | j                  d         |d<   nk| j                  dk(  r\| j                  d   t        |d   | j                  d         |d<   | j                  d   t        |d   | j                  d         |d<   | j                  |k7  r\|| _        | j!                          t#        j$                  | t'        | j                               | j(                  j+                  |        y y )Nr   Z   z4Must specify 2D coordinate for non-orthogonal lines.r
   )rL   listtuplenpndarrayndimr   QPointFxyr1   	Exceptionr   r]   minr    viewTransformChangedr   r"   r   sigPositionChangedemit)r/   r0   newPoss      r8   r"   zInfiniteLine.setPos   s   cD%45bggcla>O#YFV^^,eegsuuw'FzzRqqS VWW ::}}Q+q	4==+;<q	}}Q+q	4==+;<q	ZZ1_}}Q+q	4==+;<q	}}Q+q	4==+;<q	66VDF%%'!!$dff6##((.	 r9   c                      | j                   d   S Nr   r    rC   s    r8   getXPoszInfiniteLine.getXPos      vvayr9   c                      | j                   d   S )Nr
   ry   rC   s    r8   getYPoszInfiniteLine.getYPos  r{   r9   c                     | j                   S Nry   rC   s    r8   getPoszInfiniteLine.getPos  s    vvr9   c                     | j                   dz  dk(  r| j                         S | j                   dz  dk(  r| j                         S | j                         S )zReturn the value of the line. Will be a single number for horizontal and
        vertical lines, and a list of [x,y] values for diagonal lines.   r   rh   )r1   r}   rz   r   rC   s    r8   r@   zInfiniteLine.value  sH     ::c>Q<<>!ZZ^r!<<>!;;= r9   c                 &    | j                  |       y)zSet the position of the line. If line is horizontal or vertical, v can be
        a single value. Otherwise, a 2D coordinate must be specified (list, tuple and
        QPointF are all acceptable).N)r"   r/   rU   s     r8   r?   zInfiniteLine.setValue  s     	Ar9   c                 Z    | j                   ||fk7  r||f| _         | j                          y y r   )r&   rG   )r/   mnmxs      r8   setSpanzInfiniteLine.setSpan%  s+    99R RDIKKM !r9   c                    | j                         }|t        j                         S | j                  t	        dd            \  }}|dn|j                         }t        | j                  j                         dz  | j                  j                         dz        }| j                  |z   dz   |z  }t        j                  |      }|j                  |        |j                  |       |j                         }|j                         || j                  d   z  z   }	|j                         || j                  d   z  z   }
|j                  |	       |j!                  |
       |j#                         }| j%                         j'                         }| j(                  |k7  s| j*                  |k7  r|| _        || _        | j-                          |	|
f| _        || _        | j(                  S )Nr
   r   )	directionr   )viewRectr   rX   pixelVectorsr   rp   r]   r%   r   r4   r)   	setBottomsetTopleftr&   setLeftsetRight
normalized
getViewBoxr`   r,   r-   prepareGeometryChanger+   _lastViewRect)r/   vr_orthopxpwwbrlengthr   rightvss               r8   _computeBoundingRectz!InfiniteLine._computeBoundingRect*  s   ]]_:==?" $$uQ{$;5-QUWWY!A%t}}':':'<q'@A  2%)R/]]2
aR
		!wwy6DIIaL00	FTYYq\11


4
E]]___##%<<2!3!3r!9DL!#D&&(-||r9   c                 \    | j                   | j                         | _         | j                   S r   )r   r   rC   s    r8   boundingRectzInfiniteLine.boundingRectN  s+    %!%!:!:!<D!!!r9   c                    | j                   dz  dvr%|j                  |j                  j                         | j                  \  }}| j
                  }|j                  t        j                  j                  j                         |j                  |       |j                  t        |d      t        |d             t        | j                        dk(  ry |j!                         }|j#                          |j%                  t        |d            }|j%                  t        |d            }|j%                  t        |d            }	||z
  }
t        |
      j'                         }t)        t+        |
j-                         |
j/                                     }|j1                  |       |j3                  |       |	|z
  }	|	j/                         |
j-                         z  |
j/                         |	j-                         z  z
  }|j5                  d|dkD  rdnd       |j7                  t9        j:                  | j
                  j=                                      |j!                         }| j                  D ]Q  \  }}}|j?                  |       ||z  }|j1                  |d       |j5                  ||       |jA                  |       S y )Nr   )r   rh   r   r
   )!r1   setRenderHint
RenderHintAntialiasingr+   r'   setJoinStyler   QtPenJoinStyle	MiterJoinr#   drawLiner   rK   r(   	transformre   mapr   r   r   rp   ro   	translaterotatescalesetBrushrE   mkBrushr   setTransformdrawPath)r/   r    rH   r   r   r%   trstartendupdifr   r1   detra   r0   r`   ro   s                     r8   paintzInfiniteLine.paintS  s
   ::7*OOALL556ooeoo//99:		

5q>5?3 t||! [[]	uT1~&ffU5!_%VVE$N#Eks""$ceegsuuw/0	E	%Zddfsuuw2446!11	a1R(	

2::doo33567[[]#|| 	OD#tNN2AKK1GGD$JJt	r9   c                     |dk(  ry y)Nr   )r   r    )r/   axisfrac
orthoRanges       r8   
dataBoundszInfiniteLine.dataBounds}  s    19r9   c                    | j                   r?|j                         t        j                  j                  j
                  k(  r|j                         rQd| _        | j                         | j                  |j                               z
  | _        | j                         | _        |j                          | j                  sy | j                  | j                  | j                  |j                               z          | j                  j!                  |        |j#                         r#d| _        | j$                  j!                  |        y y y y NTF)r2   buttonr   r   MouseButton
LeftButtonisStartr   r0   mapToParentbuttonDownPoscursorOffsetstartPositionacceptr"   
sigDraggedru   isFinishsigPositionChangeFinishedr/   evs     r8   mouseDragEventzInfiniteLine.mouseDragEvent  s    <<BIIK699+@+@+K+KKzz|"$(HHJ1A1A"BRBRBT1U$U!%)XXZ"IIK;;KK))D,<,<RVVX,FFGOO  &{{}#..33D9  L<r9   c                    | j                   j                  | |       | j                  r|j                         t        j
                  j                  j                  k(  ri|j                          | j                  | j                         d| _        | j                  j                  |        | j                  j                  |        y y y NF)
sigClickedru   r   r   r   r   r   RightButtonr   r"   r   r   r   r   s     r8   mouseClickEventzInfiniteLine.mouseClickEvent  s    T2&;;299;&))*?*?*K*KKIIKKK**+DKOO  &**//5 L;r9   c                     |j                         sQ| j                  rE|j                  t        j                  j
                  j                        r| j                  d       y | j                  d       y r   )isExitr2   acceptDragsr   r   r   r   setMouseHoverr   s     r8   
hoverEventzInfiniteLine.hoverEvent  sH    		"..AVAVAaAa2bt$u%r9   c                     | j                   |k(  ry || _         |r| j                  | _        n| j                  | _        | j	                          y r   )r   r4   r'   r%   rG   )r/   hovers     r8   r   zInfiniteLine.setMouseHover  s=    &""mmDO"hhDOr9   c                 <    d| _         t        j                  |        y)z
        Called whenever the transformation matrix of the view has changed.
        (eg, the view range has changed or the view was resized)
        N)r   r   rs   rC   s    r8   rs   z!InfiniteLine.viewTransformChanged  s    
 "))$/r9   c                     || _         y r   r   )r/   r6   s     r8   setNamezInfiniteLine.setName  s	    
r9   c                     | j                   S r   r   rC   s    r8   r6   zInfiniteLine.name  s    zzr9   )Nrh   NFNNNN)r   r
   NN)rS   g      $@)      ?N)&__name__
__module____qualname____doc__r   Signalobjectr   r   rt   r   r   r   rA   r3   r#   r$   r*   rc   r!   r"   rz   r}   r   r@   r?   r   r   r   r   r   r   r   r   r   rs   r   r6   r   r9   r8   r   r      s     v&J -f 5&v.vv.JKOQUNE`%
$
 
*+Z/@! 
"H"
(T:"6&	0r9   c                   `    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zy)r   a  
    A TextItem that attaches itself to an InfiniteLine.
    
    This class extends TextItem with the following features:
    
      * Automatically positions adjacent to the line at a fixed position along
        the line and within the view box.
      * Automatically reformats text when the line value has changed.
      * Can optionally be dragged to change its location along the line.
      * Optionally aligns to its parent line.

    =============== ==================================================================
    **Arguments:**
    line            The InfiniteLine to which this label will be attached.
    text            String to display in the label. May contain a {value} formatting
                    string to display the current value of the line.
    movable         Bool; if True, then the label can be dragged along the line.
    position        Relative position (0.0-1.0) within the view to position the label
                    along the line.
    anchors         List of (x,y) pairs giving the text anchor positions that should
                    be used when the line is moved to one side of the view or the
                    other. This allows text to switch to the opposite side of the line
                    as it approaches the edge of the view. These are automatically
                    selected for some common cases, but may be specified if the 
                    default values give unexpected results.
    =============== ==================================================================
    
    All extra keyword arguments are passed to TextItem. A particularly useful
    option here is to use `rotateAxis=(1, 0)`, which will cause the text to
    be automatically rotated parallel to the line.
    Nc                    || _         || _        d| _        || _        || _        | j                   j
                  j                  | j                         d| _        |G|j                  dd       }|t        |      dk(  rddg}n ddg}n|j                  d	z  d
k(  rddg}nddg}|| _        t        j                  | fi | | j                  |       | j                          y )NFNN
rotateAxis)r
   r   )rS   r   )rS   r
   )r   rS   )r
   rS   r   r   )liner2   r   orthoPosformatrt   connectvalueChanged
_endpointsgetrj   r1   anchorsr   r   setParentItem)r/   r   r   r2   r_   r   kwdsraxs           r8   r   zInfLineLabel.__init__  s    	 		$$,,T->->?&?((<.C:&'2G'2G::#q('2G'2G$'$'4 r9   c                     | j                         sy | j                  j                         }| j                  | j                  j	                  |             | j                          y )N)r@   )	isVisibler   r@   setTextr   updatePosition)r/   r@   s     r8   r   zInfLineLabel.valueChanged  sI    ~~		!T[[''e'45r9   c                    | j                   d   | j                  j                         }t        |j	                         d      }t        |j                         d      }| j                  j                  dz  dk7  rS| j                         }| j                         rt        |t              syt        j                         }|j                  |       |j                  |       | j                  j                  |      d   j!                  |      }t        j                         }|j#                  |j                                |j%                  |      j'                  t        j(                               }t+        |      dkD  rLt-        |d         }| j                  j/                  ||d         }| j                  j/                  ||d         }||f| _         | j                   S )Nr   rh   r   r
   )r   r   r   r   r   r   r1   r   r   rL   r   r	   rV   moveTolineToitemTransformr   addRectintersectedtoSubpathPolygons
QTransformrK   ri   mapFromItem)	r/   lrpt1pt2viewr    r   pathsls	            r8   getEndpointszInfLineLabel.getEndpoints  sn    ??1%'')B	1%C
A&Cyy#q((~~'z$/H'&&(II++D1!488;'')

4,,./q);;E<L<L<NOu:>U1XA))//ad;C))//ad;C"CjDOr9   c                 `   d| _         | j                         \  }}|y || j                  z  |d| j                  z
  z  z   }| j                  |       | j                  j                         }|B| j                  | j                  |j                         j                         dk  rdnd          y y )Nr   r
   r   )
r   r  r   r"   r   r   	setAnchorr   centerrp   )r/   r	  r
  ptr   s        r8   r   zInfLineLabel.updatePosition  s    &$$&S;4== 3!DMM/#::B YY!>NN4<<RYY[]]_q-@aHI r9   c                 V    t        j                  | |       |r| j                          y y r   )r   
setVisibler   r   s     r8   r  zInfLineLabel.setVisible)  s&    D!$ r9   c                 4    || _         | j                  |       y)zFSet whether this label is movable by dragging along the line.
        Nr;   r=   s     r8   r   zInfLineLabel.setMovable.  s     !!!$r9   c                 2    || _         | j                          y)a  Set the relative position (0.0-1.0) of this label within the view box
        and along the line. 
        
        For horizontal (angle=0) and vertical (angle=90) lines, a value of 0.0
        places the text at the bottom or left of the view, respectively. 
        N)r   r   )r/   r    s     r8   setPositionzInfLineLabel.setPosition4  s     r9   c                 2    || _         | j                          y)zSet the text format string for this label.
        
        May optionally contain "{value}" to include the lines current value
        (the text will be reformatted whenever the line is moved).
        N)r   r   )r/   r   s     r8   	setFormatzInfLineLabel.setFormat>  s     r9   c                 X   | j                   r|j                         t        j                  j                  j
                  k(  r|j                         r<d| _        | j                  |j                               | _
        | j                  | _        |j                          | j                  sy | j                  |j                               }t        j                   | j                  |z   | j                  z
  dd      | _        | j#                          |j%                         rd| _        y y y y )NTg        r   F)r2   r   r   r   r   r   r   _moving	_posToRelr   _cursorOffsetr   _startPositionr   r0   rE   clip_scalarr   r   )r/   r   rels      r8   r   zInfLineLabel.mouseDragEventG  s    <<BIIK699+@+@+K+KKzz|#%)^^B4D4D4F%G"&*mm#IIK<<..*CNN4+>+>+DtGYGY+Y[]_abDM!{{}$  L<r9   c                     | j                   r_|j                         t        j                  j                  j
                  k(  r)|j                          | j                  | _        d| _         y y y r   )	r   r   r   r   r   r   r   r  r   r   s     r8   r   zInfLineLabel.mouseClickEventX  sK    ;;299;&))*?*?*K*KKIIK //DMDK L;r9   c                     |j                         sA| j                  r4|j                  t        j                  j
                  j                         y y y r   )r   r2   r   r   r   r   r   r   s     r8   r   zInfLineLabel.hoverEvent^  s4    yy{t||NN69900;;<  ,{r9   c                 x    t        j                  |        | j                          t        j                  |        y r   )r   rs   r   r   rC   s    r8   rs   z!InfLineLabel.viewTransformChangedb  s*    ))$/%%d+r9   c                     | j                         \  }}|y| j                  |      }|j                         |j                         z
  |j                         |j                         z
  z  S rx   )r  r   ro   )r/   r0   r	  r
  s       r8   r  zInfLineLabel._posToRelg  sX    $$&S;s##%%'!ceegceego66r9   ) FrS   N)r   r   r   r   r   r   r  r   r  r   r  r  r   r   r   rs   r  r   r9   r8   r   r     sI    >68J 
%%" =,
7r9   )mathr   r   numpyrk   r%  r   rE   r   r   r   r	   r   r   r   r   __all__r   r   r   r9   r8   <module>r)     sG         & *  >
*j> jZp78 p7r9   