
    e                         d dl mZmZmZ  eed      ZddlZddlZddlZddl	Z
d dlm Z mZ d dlmZ d dlmZ dd	lmZ d
gZddZ G d d
e      Z G d de      Zy)   )QtCoreQtGui	QtWidgetsQOpenGLWidget    N)Qtdebug)	functions)getConfigOption   )GraphicsObjectPlotCurveItemc                     |.t         j                  j                  t        j                  d      }t        |       dk  r|j                  d       |S d }t        |t        j                        r t        j                  |d d t              d}}d}|s|dk(  r@t        j                  |       t        j                  |      z  }t        j                  |      }|d	k(  r|sF|    } ||   }n;|dk(  r|rd	}n1d d |d
d  z  }n%|dv r!|st        j                        }| |   } ||   }|d	k(  rct        |       d
z
  }	|j                  |	       |	r@|j                         }
| d d |
d d df<   | d
d  |
d d df<   |d d |
d d d
f<   |d
d  |
d d df<   |S |dk(  rbt        |       dz  }	|j                  |	       |	r?|j                         }
|
j!                  d      }
| d |	dz   |
d d df<   |d |	dz   |
d d d
f<   |S |vt        j"                  |      }	|j                  |	       |	rL|j                         }
| d d |   |
d d df<   | d
d  |   |
d d df<   |d d |   |
d d d
f<   |d
d  |   |
d d df<   |S d}	|j                  |	       |S )N   r   r   dtypearrayTfiniteallr   )pairsr      r   )r   r   )r   	internalsPrimitiveArrayr   QLineFlenresize
isinstancenpndarrayasarrayboolisfiniter   fn_compute_backfill_indicesreshapecount_nonzero)xyconnectfiniteCheckoutconnect_array
all_finitemaskbackfill_idxnsegsmemorys              G/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/PlotCurveItem.pyarrayToLineSegmentsr4      s   
{ll))&--; 1vz

1
M'2::&!#GCRL!EwwJg){{1~A.VVD\
%$A$A	H	G !"IQR0M	&	&77=L,A,A%A


5[[]FSb6F1a4LQR5F1a4LSb6F1a4LQR5F1a4L8 J5 
G	A!

5[[]F^^G,FZeai=F1a4LZeai=F1a4L& J# 
	"   /

5[[]FSb6-0F1a4LQR5/F1a4LSb6-0F1a4LQR5/F1a4L J 

5J    c                   N   e Zd ZdZ ej
                  e      Z ej
                  ee      Zd Z	d$dZ
d Zd$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ed        Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%e&jN                  d        Z(d  Z)d! Z*d" Z+d# Z,y)&r   ab  
    Class representing a single plot curve. Instances of this class are created
    automatically as part of :class:`PlotDataItem <pyqtgraph.PlotDataItem>`; 
    these rarely need to be instantiated directly.

    Features:

      - Fast data update
      - Fill under curve
      - Mouse interaction

    =====================  ===============================================
    **Signals:**
    sigPlotChanged(self)   Emitted when the data being plotted has changed
    sigClicked(self, ev)   Emitted when the curve is clicked
    =====================  ===============================================
    c                 |   t        j                  | |j                  dd             | j                          i | _        ddddddt        d      ddddt        d      d| _        d	|vr"t        j                  d
      | j                  d	<   | j                  |j                  dd              | j                  |i | y)a  
        Forwards all arguments to :func:`setData <pyqtgraph.PlotCurveItem.setData>`.

        Some extra arguments are accepted as well:

        ==============  =======================================================
        **Arguments:**
        parent          The parent GraphicsObject (optional)
        clickable       If `True`, the item will emit ``sigClicked`` when it is
                        clicked on. Defaults to `False`.
        ==============  =======================================================
        parentNF	antialiasr      segmentedLineMode)	shadowPen	fillLevelfillOutlinebrushstepModenamer9   r*   
mouseWidthcompositionModeskipFiniteCheckr;   penw	clickable)r   __init__getclearmetaDatar   optsr$   mkPensetClickablesetDataselfargskargss      r3   rH   zPlotCurveItem.__init__u   s     	eii$&?@


  (5#$!01D!E
	 !xx}DIIe%))K78d$e$r5   Nc                     dg}||S ||v S )NplotData )rQ   	interfaceintss      r3   
implementszPlotCurveItem.implements   s    |KD  r5   c                 :    | j                   j                  dd       S )NrA   )rL   rI   rQ   s    r3   rA   zPlotCurveItem.name   s    yy}}VT**r5   c                 R    || _         ||| j                  d<   d| _        d| _        yy)zSets whether the item responds to mouse clicks.

        The `width` argument specifies the width in pixels orthogonal to the
        curve that will respond to a mouse click.
        NrB   )rG   rL   _mouseShape_boundingRect)rQ   swidths      r3   rN   zPlotCurveItem.setClickable   s4     &+DIIl##D!%D r5   c                 B    || j                   d<   | j                          y)as  
        Change the composition mode of the item. This is useful when overlaying
        multiple items.
        
        Parameters
        ----------
        mode : ``QtGui.QPainter.CompositionMode``
            Composition of the item, often used when overlaying items.  Common
            options include:

            ``QPainter.CompositionMode.CompositionMode_SourceOver`` (Default)
            Image replaces the background if it is opaque. Otherwise, it uses
            the alpha channel to blend the image with the background.

            ``QPainter.CompositionMode.CompositionMode_Overlay`` Image color is
            mixed with the background color to reflect the lightness or
            darkness of the background

            ``QPainter.CompositionMode.CompositionMode_Plus`` Both the alpha
            and color of the image and background pixels are added together.

            ``QPainter.CompositionMode.CompositionMode_Plus`` The output is the
            image color multiplied by the background.

            See ``QPainter::CompositionMode`` in the Qt Documentation for more
            options and details
        rC   N)rL   updaterQ   modes     r3   setCompositionModez PlotCurveItem.setCompositionMode   s    8 (,		#$r5   c                 2    | j                   | j                  fS N)xDatayDatar[   s    r3   getDatazPlotCurveItem.getData   s    zz4::%%r5   c                 R   | j                   |   }||d   ||fk(  r|d   S | j                         \  }}|t        |      dk(  ry|dk(  r|}|}n|dk(  r|}|}nt        d      |:||d   k\  ||d   k  z  }	| j                  j                  dd       dk(  r|	d d }	||	   }t        |      dk(  ry|dk\  rt        j                         5  t        j                  d	       t        t        j                  |            t        t        j                  |            f}
d d d        t        j                  
d         st        j                  |
d         rt        j                  |      }	||	   }t        |      dk(  ryt        |j!                               t        |j#                               f}
ni|d
k  rt%        dt'        |      z        t        j                  |      }	||	   }t        |      dk(  ryt        j(                  |dd|z
  z  dd|z   z  g      }
|dk(  r[| j                  d   dvrJt        t!        |
d   | j                  d               t        t#        |
d   | j                  d               f}
| j                  d   }| j                  d   }|w|j+                         sg|j-                         t.        j0                  j2                  j4                  k7  r2|
d   |j7                         dz  z
  |
d   |j7                         dz  z   f}
|w|j+                         sg|j-                         t.        j0                  j2                  j4                  k7  r2|
d   |j7                         dz  z
  |
d   |j7                         dz  z   f}
||f|
g| j                   |<   |
S # 1 sw Y   xY w)Nr   r   )NNzInvalid axis valuer@   centerr         ?ignore        z0Value for parameter 'frac' must be > 0. (got %s)2   r=   )NenclosedrE   r<   ea?)_boundsCacherj   r   
ValueErrorrL   rI   warningscatch_warningssimplefilterfloatr   nanminnanmaxmathisinfr#   minmax	Exceptionstr
percentile
isCosmeticstyler   r   PenStyleNoPenwidthF)rQ   axfrac
orthoRangecacher(   r)   dd2r/   brE   spens                r3   
dataBoundszPlotCurveItem.dataBounds   sb    !!"%qdJ-?!?8OA9A!7AB1WAB122 !*Q-'B*Q-,?@Dyy}}Z.(:CRy$A q6Q; 3; ((* A%%h/BIIaL)51+>@A zz!A$4::ad#3{{1~dGq6Q;'AEEGneAEEGn6S[NQTUYQZZ[[ ;;q>D$A1v{#a"D/2T?!CDA 7tyy-5GGs1Q4;!78:s1Q4;!78:A iiyy%?3>>#3		vyyGYGYG_G_8_1

V++QqTCJJL4G-GHADOO$5$**,&))J\J\JbJb:b1f,,adT[[]65I.IJA"&
!3Q 7"KA As   ANN&c                    | j                   d   }| j                   d   }d}|[|j                         rK|j                         t        j                  j
                  j                  k7  r||j                         dz  z  }|b|j                         rR|j                         t        j                  j
                  j                  k7  rt        ||j                         dz        }| j                  rt        || j                   d   dz  dz         }|S )NrE   r<   r   rr   rB   r   r   )
rL   r   r   r   r   r   r   r   r~   rG   )rQ   rE   r   rF   s       r3   pixelPaddingzPlotCurveItem.pixelPadding  s    iiyy%O 0SYY[FIIDVDVD\D\5\f$$A 1djjlfiiFXFXF^F^6^At{{}V+,A>>Atyy.1A56Ar5   c                 T   | j                   | j                  d      \  }}||t        j                         S | j                  d      \  }}||t        j                         S dx}}| j	                         }|dkD  rG| j                         \  }}	 |dn|j                         }	 |dn|j                         }||z  }||z  }t        j                  ||z
  ||z
  d|z  |z   |z
  d|z  |z   |z
        | _         | j                   S # t        $ r d}Y mw xY w# t        $ r d}Y iw xY w)Nr   )r   r   ro   r   )r^   r   r   QRectFr   pixelVectorslengthOverflowError)rQ   xmnxmxymnymxpxpypxPads           r3   boundingRectzPlotCurveItem.boundingRect)  sE   %A.JS#{ck}}&A.JS#{ck}}&MB%%'Eqy**,B jbiikB jbiikB
 ee "(s2vs2v"cz#~PQRTPTVYzZ]~!^D!!! % B % Bs$   D )D DDD'&D'c                 D    | j                          | j                          y rg   )invalidateBoundsprepareGeometryChanger[   s    r3   viewTransformChangedz"PlotCurveItem.viewTransformChangedI  s    ""$r5   c                 $    d | _         d d g| _        y rg   )r^   rs   r[   s    r3   r   zPlotCurveItem.invalidateBoundsp  s    !!4Lr5   c                     |r|d   d| j                   d<   n"t        j                  |i || j                   d<   | j                          | j	                          y)z#Set the pen used to draw the curve.r   NrE   rL   r$   rM   r   rb   rP   s      r3   setPenzPlotCurveItem.setPent  sL    DGO#DIIe!xx77DIIer5   c                     |r|d   d| j                   d<   n"t        j                  |i || j                   d<   | j                          | j	                          y)z
        Set the shadow pen used to draw behind the primary pen.
        This pen must have a larger width than the primary
        pen to be visible. Arguments are passed to 
        :func:`mkPen <pyqtgraph.mkPen>`
        r   Nr<   r   rP   s      r3   setShadowPenzPlotCurveItem.setShadowPen}  sN     DGO%)DIIk"%'XXt%=u%=DIIk"r5   c                     |r|d   d| j                   d<   n"t        j                  |i || j                   d<   | j                          | j	                          y)z
        Sets the brush used when filling the area under the curve. All 
        arguments are passed to :func:`mkBrush <pyqtgraph.mkBrush>`.
        r   Nr?   )rL   r$   mkBrushr   rb   rP   s      r3   setBrushzPlotCurveItem.setBrush  sN    
 DGO!%DIIg!#T!;U!;DIIgr5   c                 ~    || j                   d<   d| _        d| _        | j                          | j	                          y)z5Sets the level filled to when filling under the curver=   N)rL   fillPath_fillPathListr   rb   )rQ   levels     r3   setFillLevelzPlotCurveItem.setFillLevel  s4    !&		+!r5   c                 4    t        |      | j                  d<   y)a  
        When it is known that the plot data passed to ``PlotCurveItem`` contains only finite numerical values,
        the `skipFiniteCheck` property can help speed up plotting. If this flag is set and the data contains 
        any non-finite values (such as `NaN` or `Inf`), unpredictable behavior will occur. The data might not
        be plotted, or there migth be significant performance impact.
        rD   N)r"   rL   )rQ   rD   s     r3   setSkipFiniteCheckz PlotCurveItem.setSkipFiniteCheck  s     )-_(=		#$r5   c                 (     | j                   |i | y)aP  
        =============== =================================================================
        **Arguments:**
        x, y            (numpy arrays) Data to display
        pen             Pen to use when drawing. Any single argument accepted by
                        :func:`mkPen <pyqtgraph.mkPen>` is allowed.
        shadowPen       Pen for drawing behind the primary pen. Usually this
                        is used to emphasize the curve by providing a
                        high-contrast border. Any single argument accepted by
                        :func:`mkPen <pyqtgraph.mkPen>` is allowed.
        fillLevel       (float or None) Fill the area under the curve to
                        the specified value.
        fillOutline     (bool) If True, an outline surrounding the `fillLevel`
                        area is drawn.
        brush           Brush to use when filling. Any single argument accepted
                        by :func:`mkBrush <pyqtgraph.mkBrush>` is allowed.
        antialias       (bool) Whether to use antialiasing when drawing. This
                        is disabled by default because it decreases performance.
        stepMode        (str or None) If 'center', a step is drawn using the `x`
                        values as boundaries and the given `y` values are
                        associated to the mid-points between the boundaries of
                        each step. This is commonly used when drawing
                        histograms. Note that in this case, ``len(x) == len(y) + 1``
                        
                        If 'left' or 'right', the step is drawn assuming that
                        the `y` value is associated to the left or right boundary,
                        respectively. In this case ``len(x) == len(y)``
                        If not passed or an empty string or `None` is passed, the
                        step mode is not enabled.
        connect         Argument specifying how vertexes should be connected
                        by line segments. 
                        
                            | 'all' (default) indicates full connection. 
                            | 'pairs' draws one separate line segment for each two points given.
                            | 'finite' omits segments attached to `NaN` or `Inf` values. 
                            | For any other connectivity, specify an array of boolean values.
        compositionMode See :func:`setCompositionMode
                        <pyqtgraph.PlotCurveItem.setCompositionMode>`.
        skipFiniteCheck (bool, defaults to `False`) Optimization flag that can
                        speed up plotting by not checking and compensating for
                        `NaN` values.  If set to `True`, and `NaN` values exist, the
                        data may not be displayed or the plot may take a
                        significant performance hit.
        =============== =================================================================

        If non-keyword arguments are used, they will be interpreted as
        ``setData(y)`` for a single argument and ``setData(x, y)`` for two
        arguments.
        
        **Notes on performance:**
        
        Line widths greater than 1 pixel affect the performance as discussed in 
        the documentation of :class:`PlotDataItem <pyqtgraph.PlotDataItem>`.
        N)
updateDatarP   s      r3   rO   zPlotCurveItem.setData  s    n 	''r5   c                 H   t        j                         }d|v r| j                  |d          t        |      dk(  r	|d   |d<   nt        |      dk(  r|d   |d<   |d   |d<   d|vs|d   t	        j
                  g       |d<   d|vs|d   $t	        j                  t        |d               |d<   dD ]  }||   }t        |t              rt	        j
                  |      }|||<   t        |t        j                        r|j                  dkD  rt        d      |j                  j                  d	k(  st        d
        |d       |d   j                  t        j                        | _        |d   j                  t        j                        | _        | j#                          | j%                          | j'                           |d       d|v r|d   | j(                  d<   | j(                  d   dv r| j(                  d   du rt+        j,                  dt.        d       t        | j                         t        | j                        dz   k7  rt        d| j                   j0                  d| j                  j0                  d      | j                   j0                  | j                  j0                  k7  r:t        d| j                   j0                  d| j                  j0                  d      d | _        d | _        d | _        d | _        d| _        d|v r|d   | j(                  d<   d|v r|d   | j(                  d<   d|v r| j=                  |d          d|v r| j?                  |d          d|v r| jA                  |d          d|v r|d   | j(                  d<   d|v r| jC                  |d          d |v r|d    | j(                  d <   d!|v r|d!   | j(                  d!<    |d"       | jE                           |d#       | jF                  jI                  |         |d$       y )%NrC   r   r   r)   r   r(   )r(   r)   zPlot data must be 1D ndarray.cz Can not plot complex data types.zdata checkscopyr@   rl   TTzjstepMode=True is deprecated and will result in an error after October 2022. Use stepMode="center" instead.r   )
stacklevelz1len(X) must be len(Y)+1 since stepMode=True (got z and )z+X and Y arrays must be the same shape--got .FrA   r*   rE   r<   r=   r>   r?   r9   rD   setrb   emit)%r	   Profilerre   r   r   r   aranger   listr    ndimr   r   kindviewri   rh   r   r   informViewBoundsChangedrL   ru   warnDeprecationWarningshapepathr   r   r]   _lineSegmentsRenderedr   r   r   r   rb   sigPlotChangedr   )rQ   rR   rS   profilerkdatas         r3   r   zPlotCurveItem.updateData  s   >>#%##E*;$<=t9>aE#JY!^aE#JaE#JeuSz1"E#JeuSz13uSz?3E#J 	DA8D$%xx~adBJJ/499q= ?@@zz#% BCC	D 	 3Z__RZZ0
3Z__RZZ0
""$$$&$)*$5DIIj!99Z $44yy$, A&1 4::#djj/!"33aeakakaqaqsws}s}  tD  tD  !E  F  Fzz4::#3#33[_[e[e[k[kmqmwmwm}m} ~	!%*"U? %fDIIf#(#3DIIi E>KKe%%eK01%eK01E!',]';DIIm$eMM%.)%%*;%7DIIk"%+01B+CDII'(  &r5   c                 4   | dk(  rRt        j                  t        |      dz   df|j                        }|d d t         j                  f   |d d |d   |d<   n| dk(  rRt        j                  t        |      dz   df|j                        }|d d t         j                  f   |dd  |d   |d<   nY| d	v rGt        j                  t        |      df|j                        }|d d t         j                  f   |d d  nt        d
| z        ||j                  |j                        dd }t        j                  t        |      df|j                        }|d d t         j                  f   |d d  |j                  |j                        }||fS |j                  |j                        }t        j                  t        |      dz   df|j                        }|d d t         j                  f   |dd |j                  |j                        dd }||ddg<   ||fS )Nrightr   r   r   r   leftr   r   zUnsupported stepMode %s)r   emptyr   r   newaxisrt   r&   size)r@   r(   r)   baselinex2y2s         r3   _generateStepModeDataz#PlotCurveItem._generateStepModeData8  s    w3q6A:q/9B2::&BsGVBrF3q6A:q/9Bq"**}%BqrFqEBqE))3q6!*AGG4Bam$BqE6ABB

277#Ab)A3q6!*AGG4Ba

lOBqE

277#A !t 

277#A3q6!8A,agg6B2::BqH

277#Ab)A!Aq"gJ!tr5   c                     | j                   d   r2| j                  | j                   d   ||| j                   d         \  }}t        j                  ||| j                   d   | j                   d          S )Nr@   r=   r   r*   rD   )r*   r+   )rL   r   r$   arrayToQPathrQ   r(   r)   s      r3   generatePathzPlotCurveItem.generatePathV  sz    99Z --		*%;/	 . DAq IIi( II&788	
 	
r5   c                 :   | j                   | j                         \  }}|t        |      dk(  s|t        |      dk(  rt        j                         | _         n" | j
                  | j                          | _         d | _        d | _        d | _        | j                   S )Nr   )	r   rj   r   r   QPainterPathr   r   r   r]   r   s      r3   getPathzPlotCurveItem.getPathf  s    99,,.CAayCFaK19A!!..0	-D--t||~>	 DM!%D#Dyyr5   c                     |dvrt        d| d      || j                  d<   | j                          | j                          y)a  
        Sets the mode that decides whether or not lines are drawn as segmented lines. Drawing lines
        as segmented lines is more performant than the standard drawing method with continuous
        lines.

        Parameters
        ----------
        mode : str
               ``'auto'`` (default) segmented lines are drawn if the pen's width > 1, pen style is a
               solid line, the pen color is opaque and anti-aliasing is not enabled.

               ``'on'`` lines are always drawn as segmented lines

               ``'off'`` lines are never drawn as segmented lines, i.e. the drawing
               method with continuous lines is used
        )autoonoffz5segmentedLineMode must be "auto", "on" or "off", got z insteadr;   N)rt   rL   r   rb   rc   s     r3   setSegmentedLineModez"PlotCurveItem.setSegmentedLineModes  sI    " ,,TUYTZZbcdd)-		%&r5   c                 V   | j                   d   }|dv ry|dv ry|j                         dkD  xr| |j                         t        j                  j
                  j                  k(  xrE |j                         xr3 |j                         j                         dk(  xr | j                   d    S )Nr;   )r   T)r   Frm   r9   )
rL   r   r   r   r   r   	SolidLineisSolidcoloralphaF)rQ   rE   rd   s      r3   _shouldUseDrawLineSegmentsz(PlotCurveItem._shouldUseDrawLineSegments  s    yy,-7?8JJL3 
+		vyy11;;;
+
 
+ 		""$+
+ IIk**	
r5   c                 x   | j                   s| j                         \  }}| j                  d   r2| j                  | j                  d   ||| j                  d         \  }}t	        ||| j                  d   | j                  d    | j
                        | _        d| _         | j
                  j                         S )Nr@   r=   r   r*   rD   )r*   r+   r,   T)r   rj   rL   r   r4   _lineSegmentsdrawargsr   s      r3   _getLineSegmentszPlotCurveItem._getLineSegments  s    ))<<>DAqyy$11IIj)!YY{3	 2 1 "5		), $		*; <<&&"D *.D&!!**,,r5   c                    g }| j                   d   dk(  r|S | j                   d   }| j                         \  }}|ddg   \  }}|ddg   \  }}||k7  r'|j                  t        j                  ||||             |j                  t        j                  ||||             ||k7  r'|j                  t        j                  ||||             |S Nr=   rq   r   r   )rL   rj   appendr   r   )	rQ   segmentsr   r(   r)   lxrxlyrys	            r3   _getClosingSegmentsz!PlotCurveItem._getClosingSegments  s     99[!Z/O99[)||~1Ar7BAr7B>OOFMM"b"h?@b(BAB>OOFMM"hB?@r5   c                    | j                   | j                   S t        j                  | j                               }|| _         | j                  d   dk(  r|S | j                  d   }| j                         \  }}|ddg   \  }}|ddg   \  }}||k7  r|j                  ||       |j                  ||       ||k7  r|j                  ||       |S r   )r   r   r   r   rL   rj   lineTo)	rQ   r   r   r(   r)   r   r   r   r   s	            r3   _getFillPathzPlotCurveItem._getFillPath  s    ==$== !!$,,.199[!Z/K99[)||~1Ar7BAr7B>KKH%B!>KKBr5   c                     | j                   d   }t        |t              xr* |dk(  xr# t        | j                   d   t        t        f      S )Nr*   r   r=   )rL   r   r   intrx   )rQ   r*   s     r3   _shouldUseFillPathListz$PlotCurveItem._shouldUseFillPathList  sK    ))I& w$ AE)9 A499[1C<@		
r5   c                    | j                   | j                   S | j                         \  }}| j                  d   r%| j                  | j                  d   ||d       \  }}| j                  d   sEt	        j
                  |      t	        j
                  |      z  }|j                         s
||   }||   }t        |      dk  rg S t        |t        j                        sdnd}g x}| _         d}t	        j                  |dz   df      }| j                  d	   }	|t        |      d
z
  k  r||||z    }
||||z    }t        |
      }|d |dz    }|
|d ddf<   ||d dd
f<   |
g d   |dd df<   |	|	|d   g|dd d
f<   ||d
z
  z  }t        j                  |d d df   |d d d
f   d      }|j                  |       |t        |      d
z
  k  r|S )Nr@   r   rD   r   rp   i  r   r   r=   r   )r   r   r   F)r+   )r   rj   rL   r   r   r#   r   r   r   r   r   r   r$   _arrayToQPath_allr   )rQ   widgetr(   r)   r/   	chunksizepathsoffsetxybufr   subxsubyr   xyviewr   s                  r3   _getFillPathListzPlotCurveItem._getFillPathList  s   )%%%||~199Z --		*% . DAq yy*+;;q>BKKN2D88: dGdGq6A:I )1H1HIBt	%''")A+q)*99[)s1vz!VFY./DVFY./Dt9D7DF^F!F3B36N!F3B36N!*-F236N&$q':F236NdQhF''q!tfQTlPUVDLL s1vz! r5   c                    t        j                         }| j                  t        | j                        dk(  ry t	        d      r4t
        r.t        |t        j                        r| j                  |||       y | j                  dur| j                  j                  dd      }n| j                  d   }|j                  |j                  j                  |       | j                  d   }||j!                  |       | j                  d   d uxr | j                  d   d u}|xr | j                  d	   }|ri| j#                         r| j%                  |      }	n| j'                         g}	 |d
       |	D ]!  }
|j)                  |
| j                  d          #  |d       | j                  j                  d      <t        | j                  j                  d      t*        j,                        r| j                  d   }n"t/        j0                  | j                  d         }|j3                         t4        j6                  j8                  j:                  k7  r|j=                  |       | j?                  |      r? |j@                  | jC                           |ra|jA                  | jE                                nA|r |jG                  | j'                                n|jG                  | jI                                | j                  d   }t        |t*        j,                        st/        j0                  |      }|j=                  |       | j?                  |      r? |j@                  | jC                           |ra|jA                  | jE                                nA|r |jG                  | j'                                n|jG                  | jI                                 |d       y )Nr   enableExperimentalFr9   TrC   r?   r=   r>   zgenerate fill pathzdraw fill pathr<   rE   drawPath)%r	   r   rh   r   r   HAVE_OPENGLr   r   r   paintGL_exportOptsrI   rL   setRenderHint
RenderHintAntialiasingre   r   r
  r   r   r   QPenr$   rM   r   r   r   r   r   r   r   	drawLinesr   r   r  r   )rQ   poptr  r   aacmodedo_filldo_fill_outliner  r   spcps                r3   paintzPlotCurveItem.paint  s   >>#::TZZA!5/0z&)2I2IJQV,5(!!%%k48B;'B	1126		+,  '))G$D0WTYY{5KSW5W!>dii&>**,--f5**,-)* 5

47!345%& 99==%1$))--4ejjAYY{+XXdii45xxzVYY//5552226AKK!6!6!89&D$<$<$>?&

4#4#4#67

4<<>2YYu"ejj)"B	**2.AKK..01D4467

4,,./

4<<>*r5   c                    |j                          dd lm} t        j                  dk(  r|j                  |j                         |j                          |j                  d|j                         |j                         ddd       |j                  |j                         t        j                  | j                               }|j                  t!        j"                  |j%                         t         j&                               | j)                         }|6|j+                  | |j-                               }|j/                  |j0                         |j3                  |j4                  |j4                  |j4                  |j4                         |j7                  |j4                         |j9                  |j:                  dd       |j=                  |j>                  |j@                  |j@                         |jC                  d       |jE                  |jF                         |jI                  |jJ                         |jM                  |jO                         |jQ                                |jM                  |jO                         |j                         z   |jQ                                |jM                  |jO                         |jQ                         |j                         z          |jM                  |jO                         |j                         z   |jQ                         |j                         z          |jM                  |jO                         |j                         z   |jQ                                |jM                  |jO                         |jQ                         |j                         z          |jS                          |j3                  |jT                  |jT                  |jT                  |jT                         |j7                  |jT                         |jC                  d       |j9                  |jV                  dd       	 | jY                         \  }}	t!        jZ                  t]        |      dft         j&                        }
||
d d df<   |	|
d d df<   |j_                  |j`                         	 |jc                  |
       te        jf                  | jh                  d	         } |jj                  |jm                         jo                           |j                         }|jq                         r|dk  rd}|js                  |       |ju                  |       | jv                  d
ur| jv                  jy                  dd      }n| jh                  d   }|r|j/                  |jz                         |j/                  |j|                         |j                  |j                  |j                         |j                  |j                  |j                         n|j                  |jz                         |j                  |j                  d|
j                  d          |j                  |j`                         	 |j                          y # |j                  |j`                         w xY w# |j                          w xY w)Nr   win32ii?B r   r      r   rE   Fr9   T)KbeginNativePainting	OpenGL.GLGLsysplatformglMatrixModeGL_PROJECTIONglLoadIdentityglOrthor`   heightGL_MODELVIEWr   
QMatrix4x4sceneTransformglLoadMatrixfr   r   r   float32
getViewBoxmapRectToItemr   glEnableGL_STENCIL_TESTglColorMaskGL_FALSEglDepthMaskglStencilFuncGL_NEVERglStencilOp
GL_REPLACEGL_KEEPglStencilMaskglClearGL_STENCIL_BUFFER_BITglBeginGL_TRIANGLES
glVertex2fr(   r)   glEndGL_TRUEGL_EQUALrj   r   r   glEnableClientStateGL_VERTEX_ARRAYglVertexPointerfr$   rM   rL   	glColor4fr   getRgbFr   glPointSizeglLineWidthr  rI   GL_LINE_SMOOTHGL_BLENDglBlendFuncGL_SRC_ALPHAGL_ONE_MINUS_SRC_ALPHAglHintGL_LINE_SMOOTH_HINT	GL_NICEST	glDisableglDrawArraysGL_LINE_STRIPr   glDisableClientStateendNativePainting)rQ   r  r  r  glmatr   rectr(   r)   posrE   r`   r  s                 r3   r  zPlotCurveItem.paintGLe  s   	<<7" OOB,,-JJq&,,.&--/1gvNOOBOO,""4#6#6#89CRXXchhj

CD  %%dD,=,=,?@D
 KK**+NN2;;R[["++NNN2;;'R[[!T2NN2=="**bjjA T"JJr//0JJr'MM$&&(DFFH-MM$&&(4::</:MM$&&(DFFHT[[]$:;MM$&&(4::</$++-1GHMM$&&(4::</:MM$&&(DFFHT[[]$:;HHJNN2::rzz2::rzzJNN2::&T"R[[!T2!	"<<>DAq((CFA;bjj9CC!HC!H""2#5#56<##C(hhtyy/0ciik1134		>>#	Eu%u% ##50))--k4@B;/BKK 1 12KK,NN2??B4M4MNIIb44bllCLL!2!23 0 0!SYYq\B''(:(:;! ''(:(:;!s&   A0Z: F+Z -Z: Z77Z: :[c                     d | _         d | _        d | _        d| _        d | _        d | _        d | _        d | _        d | _        d d g| _	        y )NF)
rh   ri   r   r   r   r   r   r]   _mouseBoundsrs   r[   s    r3   rJ   zPlotCurveItem.clear  sR    

!%*"	! !4Lr5   c                 v   | j                   | j                         }|t        j                         S t        j                         }| j                         }| j                  ||      }|j                  | j                  d          |j                  |      }| j                  ||      | _         | j                   S )zV
        Return a QPainterPath representing the clickable shape of the curve

        rB   )r]   r1  r   r   QPainterPathStrokerr   	mapToItemsetWidthrL   createStrokemapFromItem)rQ   r   strokerr   	mousePaths        r3   
mouseShapezPlotCurveItem.mouseShape  s    
 #??$D|))++//1G<<>D>>$-DTYY|45,,T2I#//i@Dr5   c                 <   | j                   r5|j                         t        j                  j                  j
                  k7  ry | j                         j                  |j                               r-|j                          | j                  j                  | |       y y rg   )rG   buttonr   r   MouseButton
LeftButtonrh  containsr]  accept
sigClickedr   )rQ   evs     r3   mouseClickEventzPlotCurveItem.mouseClickEvent  sf    ~~		0E0E0P0P!P??%%bffh/IIKOO  r* 0r5   rg   )rm   N)-__name__
__module____qualname____doc__r   Signalobjectr   ro  rH   rY   rA   rN   re   rj   r   r   r   r   r   r   r   r   r   r   rO   r   staticmethodr   r   r   r   r   r   r   r   r   r
  r	   warnOnExceptionr  r  rJ   rh  rq  rV   r5   r3   r   r   _   s   $ #V]]6*Nvv.J%%N!+
&>&HT
"@%N)
>7(rUn  :
 .
(-.(,
4l D DLR"h
) "+r5   c                   $    e Zd ZdZddZd Zd Zy)ROIPlotItemzNPlot curve that monitors an ROI and image for changes to automatically replot.Nc                     || _         || _        || _        || _        || _        t
        j                  | | j                         | j                  |       |j                  j                  | j                         y )N)r(   r   )roiroiDataroiImgaxesxValsr   rH   
getRoiDatasigRegionChangedr*   roiChangedEvent)rQ   r}  r   imgr  r  r   s          r3   rH   zROIPlotItem.__init__  sa    	
tT__%6$**ER$$T%9%9:r5   c                     | j                   j                  | j                  | j                  | j                        }|y |j
                  dkD  r"|j                  d      }|j
                  dkD  r"|S )N)r  r   )axis)r}  getArrayRegionr~  r  r  r   meanrQ   r   s     r3   r  zROIPlotItem.getRoiData  s]    HH##DLL$++DII#N9ffqjAA ffqjr5   c                 \    | j                         }| j                  || j                         y rg   )r  r   r  r  s     r3   r  zROIPlotItem.roiChangedEvent  s     OO4::&r5   ))r   r   NN)rr  rs  rt  ru  rH   r  r  rV   r5   r3   r{  r{    s    X;'r5   r{  rg   )r   r   r   r   hasattrr  r{   r%  ru   numpyr    r	   r
   r$   r   r   __all__r4   r   r{  rV   r5   r3   <module>r     sY    ) )i1  
      *
KZ}+N }+B'- 'r5   