
    e                     0   d dl Z d dlZd dlZd dlm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dlmZmZ d	d
lmZ ddgZg dZ eeD  cg c]  } |  ej&                         f c}       Zed   j+                   ej,                  ddd	d	             ed   j/                   ej,                  ddd	d	             d0dZ e       ed<   g dg dg dg dg dg dg dg dg dg dd
Zej5                         D ]O  \  ZZ ee   j:                  ed      ed	d D ]  \  ZZee   jA                  ee        ee   jC                          Q  ejD                         Z#e#jI                  d       e#jK                  ed         ed <   e#jI                  d       e#jK                  ed!         ed"<   e#jK                  ed"         ed#<   e#jK                  ed#         ed$<   dd%ddd&d'Z&d( Z'd1d)Z(d* Z)d+ Z* G d, d-e+      Z, G d. de      Z- G d/ de+      Z.yc c} w )2    N)OrderedDict   )Qtdebug)	functions)getConfigOption)Point)QtCoreQtGui   )GraphicsObjectScatterPlotItemSpotItem)ostt1t2t3d+xphstararrow_uparrow_right
arrow_down
arrow_left	crosshairr         r   c                 $   t        j                         }t        j                  |  |  | dz  | dz        }|j	                  |       |j                  | d       |j                  |d       |j                  d|        |j                  d|       |S )Nr   r   )r   QPainterPathr
   QRectF
addEllipsemoveTolineTo)rwr   pathrects        I/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/ScatterPlotItem.pymakeCrosshairr-      s}    D==!aRQA.DOODKKAKK1KKA2KK1K    r    )r!   r!   r         ?r1   r!   )r!   r1   r   r!   r1   r1   )r/   r3   )r1   r   )r5   r2   )r!   r   ))        r!   )gٿr6   r0   )g?r   ))r!   皙)r!   皙?)r7   r8   )r7   r1   )r8   r1   )r8   r8   )r1   r8   )r1   r7   )r8   r7   )r8   r!   )r7   r!   )r7   r7   )r4   g;On޿-ÿgsAҿS?gsA?r<   g;On?r:   ))ʡE?      ?)r6   r1   )ʡEۿr@   )rA         пr4   )r?   rB   )
r4   )g>W[r:   r9   )gz6>ǿh|?5?r;   )r   g r?r=   )gz6>?rC   r>   )g>W[?r:   ))g            ?r   r   )rD   rD   )皙?rD   )rF   r1   )皙r1   )rG   rD   )
r   r   r   r   r   r   r   r   r   r   -   r   r   r   r   r   r   T)symbolsizepenbrushvisiblec                 P   |y | j                  ||       | j                  |       | j                  |       t        |t              r	t
        |   }t        j                  |      r0t        t
        j                               |t        t
              z     }| j                  |       y N)scalesetPensetBrush
isinstancestrSymbolsnpisscalarlistvalueslendrawPath)painterrJ   rK   rL   rM   s        r,   
drawSymbolr^   K   s~    ~MM$NN3U&#	{{6gnn&'W(=>Vr.   c                    t        t        j                  |j                               d      }|t	        t        j                  |||z   z              }t        j                  ||t
        j                  j                  j                        }|j                  |       |j                  t        j                  j                  j                         t        j                  |      }	 |j!                  |j"                  j$                         |j'                  |j)                         |z  dz  |j+                         |z  dz         t-        || |||       |j/                          |S # |j/                          w xY w)a7  
    Render a symbol specification to QImage.
    Symbol may be either a QPainterPath or one of the keys in the Symbols dict.
    If *device* is None, a new QPixmap will be returned. Otherwise,
    the symbol will be rendered into the device specified (See QPainter documentation
    for more information).
    r   r1   )maxmathceilwidthFintr   QImageFormatFormat_ARGB32_PremultipliedsetDevicePixelRatiofillr
   r   GlobalColortransparentQPaintersetRenderHint
RenderHintAntialiasing	translatewidthheightr^   end)	rJ   rK   rL   rM   devicedpr
penPxWidthsider   s	            r,   renderSymbolrx   X   s    TYYszz|,a0J~499S$z/234dD%,,*=*=*Y*YZ""3'FII))556vA	112	FLLN3&s*FMMOC,?,CD1fdC/	M 	
s   'A.E' 'E9c                      t        |       dk(  r"t        | d   t        j                        r| d   S t	        j
                  | i |S )z
    Wrapper for fn.mkPen which avoids creating a new QPen object if passed one as its
    sole argument. This is used to avoid unnecessary cache misses in SymbolAtlas which
    uses the QPen object id in its key.
    r   r   )r[   rT   r   QPenfnmkPenargskwargss     r,   _mkPenr   q   s=     4yA~*T!Wejj9Awxx(((r.   c                      t        |       dk(  r"t        | d   t        j                        r| d   S t	        j
                  | i |S )z
    Wrapper for fn.mkBrush which avoids creating a new QBrush object if passed one as its
    sole argument. This is used to avoid unnecessary cache misses in SymbolAtlas which
    uses the QBrush object id in its key.
    r   r   )r[   rT   r   QBrushr{   mkBrushr}   s     r,   _mkBrushr   }   s=     4yA~*T!Well;Awzz4*6**r.   c                       e Zd ZdZ ej
                         Zd Zd Zd Z	d Z
d Zed        Zed        Zdd
Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy	)SymbolAtlasaT  
    Used to efficiently construct a single QPixmap containing all rendered symbols
    for a ScatterPlotItem. This is required for fragment rendering.

    Use example:
        atlas = SymbolAtlas()
        sc1 = atlas[[('o', 5, QPen(..), QBrush(..))]]
        sc2 = atlas[[('t', 10, QPen(..), QBrush(..))]]
        pm = atlas.pixmap

    c                 2    d| _         | j                          y N      ?)_dprclearselfs    r,   __init__zSymbolAtlas.__init__   s    	

r.   c                    | j                  |      }t        ||      D ci c]  \  }}|| j                  vs|| }}}|r| j                  |       t	        t        | j                  j                  |            S c c}}w )z
        Given a list of tuples, (symbol, size, pen, brush), return a list of coordinates of
        corresponding symbols within the atlas. Note that these coordinates may change if the atlas is rebuilt.
        )_keyszip_coords_extendrY   map__getitem__)r   styleskeyskeystylenews         r,   r   zSymbolAtlas.__getitem__   sp    
 zz&!,/f,=Yjc5DLLAXsEzYYLLC00$788 Zs
   A<A<c                 ,    t        | j                        S rP   )r[   r   r   s    r,   __len__zSymbolAtlas.__len__   s    4<<  r.   c                     | j                   S rP   r   r   s    r,   devicePixelRatiozSymbolAtlas.devicePixelRatio   s    yyr.   c                     || _         y rP   r   )r   ru   s     r,   rh   zSymbolAtlas.setDevicePixelRatio   s	    	r.   c                 \    | j                   | j                         | _         | j                   S rP   )_pixmap_createPixmapr   s    r,   pixmapzSymbolAtlas.pixmap   s&    <<--/DL||r.   c                 4    | j                   | j                  z  S rP   )	_maxWidthr   r   s    r,   maxWidthzSymbolAtlas.maxWidth   s     ~~		))r.   Nc                     t        j                         }|g }n4t        | j                  |            }t	        | j                  |            }| j                          |r| j                  |       y y rP   )r   Profilersetr   rY   	_itemDatar   _extendFromData)r   r   profilerdatar   s        r,   rebuildzSymbolAtlas.rebuild   s]    >>#>Dtzz&)*Dt,-D

  & r.   c                     t        j                  dt         j                        | _        i | _        d | _        d| _        d| _        d| _        d| _	        d| _
        y )N)r   r      dtyper   rE   )rW   zerosubyte_datar   r   r   _totalWidth
_totalArea_pos	_rowShaper   s    r,   r   zSymbolAtlas.clear   sJ    XXirxx8
	r.   c                     t        |       }| j                  j                  \  }}}| j                  }t	        |||||z  |dk(  rdn|||z  z  |dk(  rd      S d|z  |z  |dz  |dz  z   z        S )Nr   r   r   )countrq   rr   area	area_used
squareness)r[   r   shaper   dict)r   nr)   r   _as         r,   diagnosticszSymbolAtlas.diagnostics   s    I**""1aOO!Q%&!Vca!e&'1fsM 	M
 34a%!)q!tad{2KM 	Mr.   c                     d }|D cg c]7  \  }}}}t        |t        t        f      r|n ||      | ||       ||      f9 c}}}}S c c}}}}w )Nc                     	 | j                   S # t        $ r- t        t        j                        | _         | j                   cY S w xY wrP   )_idAttributeErrornextr   _idGenerator)objs    r,   getIdz SymbolAtlas._keys.<locals>.getId   s:    ww! {778wws    3AA)rT   rU   rd   )r   r   r   rJ   rK   rL   rM   s          r,   r   zSymbolAtlas._keys   s`    	 -3
 
(c5 "&3*5V5=$PUVYPZ\abg\hi
 	
 
s   <A
c              #      K   |D ]5  }| j                   |   \  }}}}|| j                  |||z   |||z   f   f 7 y wrP   )r   r   )r   r   r   yr   r   r)   s          r,   r   zSymbolAtlas._itemData   sT      	4Cc*JAq!Qtzz!AE'1QU7"2333	4s   <>c                 B   t        j                         }g }g }|j                         D ]S  \  }}t        |d| j                  i}t        j                  |      }|j                  |       |j                  ||f       U  |d       | j                  |        |d       y )Nru   renderinsert)	r   r   itemsrx   r   r{   ndarray_from_qimageappendr   )	r   r   r   imagesr   r   r   imgarrs	            r,   r   zSymbolAtlas._extend   s    >># ,,. 	$JC54995C((-CMM#KKc
#		$ 	T"r.   c                    | j                  |       | j                         \  }}| j                  j                  \  }}}||kD  s||kD  rDt	        j
                  ||dft        j                        }| j                  |d |d |f<   || _        |D ]4  \  }}| j                  |   \  }	}
}}|| j                  |
|
|z   |	|	|z   f<   6 d | _        y )Nr   r   )	_pack_minDataShaper   r   rW   r   r   r   r   )r   r   wNewhNewwOldhOldr   r   r   r   r   r   r)   s                r,   r   zSymbolAtlas._extendFromData   s    

4 '')
d

((dA4KTD[((D$?"((;C $

CuuDJ  	+HCc*JAq!Q'*DJJq1ua!e|$	+ r.   c                 r   t        |       }| j                  }| j                  }| j                  }| j                  \  }}| j
                  \  }}	|D ].  \  }
}|j                  \  }}}
t        ||      }||z  }|||z  z  }0 |t        |      z  }t        ||dz  z        }|d|z  kD  r|}t        ||      }t        |d       D ]J  \  }}|j                  \  }}}
||z   |kD  r	d}||	z  }|}	t        ||	      }	||||f| j                  |<   ||z  }L || _        || _        || _        ||f| _        ||	f| _        y )Nr1   r   c                 &    | d   j                   d   S )Nr   )r   r   s    r,   <lambda>z#SymbolAtlas._pack.<locals>.<lambda>)  s    d1gmmA6F r.   )r   r   )r[   r   r   r   r   r   r   r`   rd   sortedr   )r   r   r   wMaxwSumaSumr   r   wRowhRowr   r   r)   r   wRowEstr   s                   r,   r   zSymbolAtlas._pack  si   I~~yy1^^
d  	FAsiiGAq!q$<DAIDAEMD		
 	
SY da3h'(QXD4 t)FG 		HCiiGAq!1ut|T	q$<D!"Aq!DLLFA		 F	r.   c                 p    | j                   \  }}| j                  \  }}t        |      t        ||z         fS rP   )r   r   rd   )r   r   r   r)   r   s        r,   r   zSymbolAtlas._minDataShape:  s3    yy1~~11vs1q5z!!r.   c                 >   t        j                         }| j                  j                  dk(  rt	        j
                  dd      }|S t        j                  | j                  t        j                  j                  j                        }t	        j
                  |      }|S Nr   )r   r   r   rK   r   QPixmapr{   ndarray_to_qimagere   rf   rg   )r   r   pmr   s       r,   r   zSymbolAtlas._createPixmap?  st    >>#::??aq!$B
 	 &&tzz##??ACs#B	r.   rP   )__name__
__module____qualname____doc__	itertoolsr   r   r   r   r   r   rh   propertyr   r   r   r   r   r   r   r   r   r   r   r    r.   r,   r   r      s    
 #9??$L9!  
 * *
' 	M
4
$(&T"
r.   r   c                   t   e Zd ZdZ ej
                  eee      Z ej
                  eee      Z ej
                  e      Z	d Z
d Zd Zd Zd Zd#dZd	 Zd
 Zd Zd$dZd$dZd$dZd%dZd Zd#dZd&dZd'dZd Zd Zd Zd(dZd Zd Z d Z!d Z"e#jH                  d        Z%d Z&d Z'd Z(d  Z)d! Z*d" Z+y))r   aV  
    Displays a set of x/y points. Instances of this class are created
    automatically as part of PlotDataItem; these rarely need to be instantiated
    directly.

    The size, shape, pen, and fill brush may be set for each point individually
    or for all points.


    ============================  ===============================================
    **Signals:**
    sigPlotChanged(self)          Emitted when the data being plotted has changed
    sigClicked(self, points, ev)  Emitted when points are clicked. Sends a list
                                  of all the points under the mouse pointer.
    sigHovered(self, points, ev)  Emitted when the item is hovered. Sends a list
                                  of all the points under the mouse pointer.
    ============================  ===============================================

    c                    t        j                         }t        j                  |        d| _        t               | _        dt        fdt        fdt        fdt        fdt        fdt        fdt        fd	t        fd
t        fdt        fddt        fdt        fdt        fdt        fgfg}t        j                  d|      | _        ddg| _        d| _        d| _        t"        j$                  j'                  t(        j*                  j,                  d      | _        ddt1        d      ddddt3        j4                  t1        d            t3        j6                  ddd      ddj8                  d| _        | j:                  j=                  dD ci c]  }d|j?                         z   t@        |    c}        |         | jB                  |i |  |d       d| _"        yc c}w )z9
        Accepts the same arguments as setData()
        Nr   r   rK   rJ   rL   rM   rN   r   hovereditem
sourceRectr)   r   r   r   
   T	antialiasr      
foregroundd      Fz!x: {x:.3g}
y: {y:.3g}
data={data})pxModeuseCacher   compositionModenamerJ   rK   rL   rM   	hoverabletiprJ   rK   rL   rM   hoversetData)#r   r   r   r   picturer   fragmentAtlasfloatobjectboolrd   rW   emptyr   bounds_maxSpotWidth_maxSpotPxWidthr   	internalsPrimitiveArrayr   rl   PixmapFragment_pixmapFragmentsr   r{   r|   r   formatoptsupdatetitle_DEFAULT_STYLEr  _toolTipCleared)r   r~   kargsr   r   opts         r,   r   zScatterPlotItem.__init__c  s    >>#%(] %L%LUOvFOfVVc
c
c
c
	 
& HHQe,	Tl  " ; ;ENN<Y<Y[] ^(5#88OL9:ZZS#.8??
	 			CefCWsyy{"N3$77f	
 	
d$e$  $ gs   "Gc                 `    | j                   }| j                           | j                  |i | y)a  
        **Ordered Arguments:**

        * If there is only one unnamed argument, it will be interpreted like the 'spots' argument.
        * If there are two unnamed arguments, they will be interpreted as sequences of x and y values.

        ====================== ===============================================================================================
        **Keyword Arguments:**
        *spots*                Optional list of dicts. Each dict specifies parameters for a single spot:
                               {'pos': (x,y), 'size', 'pen', 'brush', 'symbol'}. This is just an alternate method
                               of passing in data for the corresponding arguments.
        *x*,*y*                1D arrays of x,y values.
        *pos*                  2D structure of x,y pairs (such as Nx2 array or list of tuples)
        *pxMode*               If True, spots are always the same size regardless of scaling, and size is given in px.
                               Otherwise, size is in scene coordinates and the spots scale with the view. To ensure
                               effective caching, QPen and QBrush objects should be reused as much as possible.
                               Default is True
        *symbol*               can be one (or a list) of symbols. For a list of supported symbols, see 
                               :func:`~ScatterPlotItem.setSymbol`. QPainterPath is also supported to specify custom symbol
                               shapes. To properly obey the position and size, custom symbols should be centered at (0,0) and
                               width and height of 1.0. Note that it is also possible to 'install' custom shapes by setting 
                               ScatterPlotItem.Symbols[key] = shape.
        *pen*                  The pen (or list of pens) to use for drawing spot outlines.
        *brush*                The brush (or list of brushes) to use for filling spots.
        *size*                 The size (or list of sizes) of spots. If *pxMode* is True, this value is in pixels. Otherwise,
                               it is in the item's local coordinate system.
        *data*                 a list of python objects used to uniquely identify each spot.
        *hoverable*            If True, sigHovered is emitted with a list of hovered points, a tool tip is shown containing
                               information about them, and an optional separate style for them is used. Default is False.
        *tip*                  A string-valued function of a spot's (x, y, data) values. Set to None to prevent a tool tip
                               from being shown.
        *hoverSymbol*          A single symbol to use for hovered spots. Set to None to keep symbol unchanged. Default is None.
        *hoverSize*            A single size to use for hovered spots. Set to -1 to keep size unchanged. Default is -1.
        *hoverPen*             A single pen to use for hovered spots. Set to None to keep pen unchanged. Default is None.
        *hoverBrush*           A single brush to use for hovered spots. Set to None to keep brush unchanged. Default is None.
        *useCache*             (bool) By default, generated point graphics items are cached to
                               improve performance. Setting this to False can improve image quality
                               in certain situations.
        *antialias*            Whether to draw symbols with antialiasing. Note that if pxMode is True, symbols are
                               always rendered with antialiasing (since the rendered symbols can be cached, this
                               incurs very little performance cost)
        *compositionMode*      If specified, this sets the composition mode used when drawing the
                               scatter plot (see QPainter::CompositionMode in the Qt documentation).
        *name*                 The name of this item. Names are used for automatically
                               generating LegendItem entries and by some exporters.
        ====================== ===============================================================================================
        N)r   r   	addPoints)r   r~   r  oldDatas       r,   r  zScatterPlotItem.setData  s*    ` ))

&&r.   c           
      	   t        |      dk(  r	|d   |d<   n8t        |      dk(  r|d   |d<   |d   |d<   nt        |      dkD  rt        d      d|v r|d   }t        |t        j                        r|d	d	df   |d<   |d	d	df   |d<   ng }g }|D ]  }t        |t
        j                        r?|j                  |j                                |j                  |j                                \|j                  |d          |j                  |d           ||d<   ||d<   d|v rt        |d         }n$d|v r|d   t        |d         }ng |d<   g |d<   d}d	| j                  d
   d<   | j                  }t        j                  t        |      |z   | j                  j                        | _
        || j                  d	t        |       | j                  t        |      d	 }	d|	d<   d|	d<   d|v r|d   }
t        t        |
            D ]  }|
|   }|D ]  }|dk(  r[||   }t        |t
        j                        r!|j                         |j                         }}n
|d   |d   }}||	|   d<   ||	|   d<   c|dk(  rt        ||         |	|   |<   }|dk(  rt        ||         |	|   |<   |dv r||   |	|   |<   t        d|z          nd|v r|d   |	d<   |d   |	d<   d|v r|d   | j                   d<   d|v r| j#                  |d          d|v r|d   | j                   d<   d|v rt%        |d         | j                   d<   d|v r|d   | j                   d<   d|v r|d   | j                   d<   dD ]  }||v rEt'        | d|d   j)                         z   |dd	 z         } |||   d|	|j+                  dd	             d |j-                         z   }||v sd||   }|dk(  rt        |      }n|dk(  rt        |      }|| j                   |<    d!|v r| j/                  |d!   |	"       | j1                          | j3                          d	d	g| _        | j7                          | j9                  |	       | j:                  j=                  |        y	)#za
        Add new points to the scatter plot.
        Arguments are the same as setData()
        r   r   spotsr   r   r   z-Only accepts up to two non-keyword arguments.posNr   .r   rI   rK   TrN   rL   rM   )r   r   rK   rJ   r   zUnknown spot parameter: %sr  r  r   r  r  r  )rL   rM   rJ   rK   r   Fmask)r  dataSetr'  r
  r   )r(  )r[   	ExceptionrT   rW   ndarrayr
   QPointFr   r   r   r   r  r   ranger   r   r  	setPxModer  getattruppergetr  setPointDataprepareGeometryChangeinformViewBoundsChangedr  
invalidateupdateSpotssigPlotChangedemit)r   r~   r  r&  r   r   r   numPtsr#  newDatar%  ispotk	setMethodkhvhs                    r,   r"  zScatterPlotItem.addPoints  s    t9>!!WE'NY!^aE#JaE#JY]KLL E>,C#rzz* 1Xc
 1Xc
 'A!!V^^411' c
c
 ew(FE\eCj4s_FE#JE#JF "&		&# ))HHS\&0		H	 $+		-3w<  ))CLM*!	e'NE3u:& JQx JAEz"1g%c6>>:"%%%'3557aA"%a&#a&aA*+
3*+
3e(.tAw
1g(0a(9
1BB(,Q
1'(Dq(HII!JJ& E\ :GCL :GCLU? %fDIIfuNN5?+%%*;%7DIIk"%%)%*<%=DIIk"E>$U|DIIe$)*$5DIIj! 4 	#AEz#D%!A$**,*>12*FG	%(5'		RXZ^H_`1779$BU{2Y:B'\!"B "		"	# U?eFmW=""$$$&Tl!  &r.   c                 2    d | _         | j                          y rP   )r  r  r   s    r,   r4  zScatterPlotItem.invalidateL  s    r.   c                 >    | j                   d   | j                   d   fS Nr   r   r   r   s    r,   getDatazScatterPlotItem.getDataQ  s    yy~tyy~--r.   Nc                     dg}||S ||v S )NplotDatar   )r   	interfaceintss      r,   
implementszScatterPlotItem.implementsT  s    |KD  r.   c                 :    | j                   j                  dd       S )Nr  )r  r0  r   s    r,   r  zScatterPlotItem.nameZ  s    yy}}VT**r.   c                    |j                  dd      }|j                  d| j                        }t        |      dk(  rt        |d   t        j
                        st        |d   t              rl|d   }d|v r|d   ||d      }t        |      t        |      k7  r"t        dt        |      t        |      fz        t        t        t        |            |d	<   nt        |i || j                  d	<   d|d
<   |r| j                  |       yy)a&  Set the pen(s) used to draw the outline around each spot.
        If a list or array is provided, then the pen for each spot will be set separately.
        Otherwise, the arguments are passed to pg.mkPen and used as the default pen for
        all spots which do not have a pen explicitly set.r  Tr(  r   r   r'  Nz9Number of pens does not match number of points (%d != %d)rL   r   )popr   r[   rT   rW   r*  rY   r)  r   r   r  r5  )r   r~   r  r  r(  penss         r,   rR   zScatterPlotItem.setPen]  s    
 8T*))Ityy1t9>z$q'2::>*TRSWVZB[7D5=#<E&M*4yCL( [_bcg_hjmnujv^w wxx!#fd"34GEN%t5u5DIIe !W% r.   c                    |j                  dd      }|j                  d| j                        }t        |      dk(  rt        |d   t        j
                        st        |d   t              rl|d   }d|v r|d   ||d      }t        |      t        |      k7  r"t        dt        |      t        |      fz        t        t        t        |            |d	<   nt        |i || j                  d	<   d|d
<   |r| j                  |       yy)a.  Set the brush(es) used to fill the interior of each spot.
        If a list or array is provided, then the brush for each spot will be set separately.
        Otherwise, the arguments are passed to pg.mkBrush and used as the default brush for
        all spots which do not have a brush explicitly set.r  Tr(  r   r   r'  Nz<Number of brushes does not match number of points (%d != %d)rM   r   )rK  r   r[   rT   rW   r*  rY   r)  r   r   r  r5  )r   r~   r  r  r(  brushess         r,   rS   zScatterPlotItem.setBrushs  s    
 8T*))Ityy1t9>z$q'2::>*TRSWVZB[1gG5=#<!%-07|s7|+ ^befmbnpst{p|a} }~~#C'$:;GG!)4!95!9DIIg !W% r.   c                 b   || j                   }t        |t        j                        st        |t              rH|}|||   }t        |      t        |      k7  r"t        dt        |      t        |      fz        ||d<   n|| j                  d<   d| _        d|d<   |r| j                  |       yy)a3  Set the symbol(s) used to draw each spot.
        If a list or array is provided, then the symbol for each spot will be set separately.
        Otherwise, the argument will be used as the default symbol for
        all spots which do not have a symbol explicitly set.

        **Supported symbols:**

        * 'o'  circle (default)
        * 's'  square
        * 't'  triangle
        * 'd'  diamond
        * '+'  plus
        * 't1' triangle pointing upwards
        * 't2'  triangle pointing right side
        * 't3'  triangle pointing left side
        * 'p'  pentagon
        * 'h'  hexagon
        * 'star'
        * 'x'  cross
        * 'arrow_up'
        * 'arrow_right'
        * 'arrow_down'
        * 'arrow_left'
        * 'crosshair'
        * any QPainterPath to specify custom symbol shapes.

        Nz<Number of symbols does not match number of points (%d != %d)rJ   r   r   
r   rT   rW   r*  rY   r[   r)  r  _spotPixmapr5  )r   rJ   r  r(  r'  symbolss         r,   	setSymbolzScatterPlotItem.setSymbol  s    8 ?iiGfbjj)Z-EG!$-7|s7|+ ^befmbnpst{p|a} }~~ 'GH"(DIIh#D !W% r.   c                 b   || j                   }t        |t        j                        st        |t              rH|}|||   }t        |      t        |      k7  r"t        dt        |      t        |      fz        ||d<   n|| j                  d<   d| _        d|d<   |r| j                  |       yy)a  Set the size(s) used to draw each spot.
        If a list or array is provided, then the size for each spot will be set separately.
        Otherwise, the argument will be used as the default size for
        all spots which do not have a size explicitly set.Nz:Number of sizes does not match number of points (%d != %d)rK   r   r   rP  )r   rK   r  r(  r'  sizess         r,   setSizezScatterPlotItem.setSize  s    
 ?iiGdBJJ':dD+AEd5zS\) \`cdi`jlopwlx_y yzz#GFO $DIIf#D !W% r.   c                 @   || j                   }t        |t        j                        st        |t              rH|}|||   }t        |      t        |      k7  r"t        dt        |      t        |      fz        ||d<   n||d<   d|d<   |r| j                  |       yy)zSet whether or not each spot is visible.
        If a list or array is provided, then the visibility for each spot will be set separately.
        Otherwise, the argument will be used for all spots.NzANumber of visibilities does not match number of points (%d != %d)rN   r   r   )r   rT   rW   r*  rY   r[   r)  r5  )r   rN   r  r(  r'  visibilitiess         r,   setPointsVisiblez ScatterPlotItem.setPointsVisible  s     ?iiGgrzz*j$.G"L+D1< CL0 cgjkwgxz}  F  {G  gH  !H  I  I!-GI!(GI !W% r.   c                    || j                   }t        |t        j                        st        |t              r@|||   }t        |      t        |      k7  r"t        dt        |      t        |      fz        t        |t        j                        rT|j                  j                  >t        |j                  j                        dkD  rt        |      D ]  \  }}||d   |<    y ||d<   y )Nz>Length of meta data does not match number of points (%d != %d)r   r   )
r   rT   rW   r*  rY   r[   r)  r   fields	enumerate)r   r   r(  r'  r:  recs         r,   r1  zScatterPlotItem.setPointData  s    ?iiGdBJJ':dD+ADz4yCL( `dghldmorszo{c| |}} dBJJ'TZZ->->-JsSWS]S]SdSdOehiOi#D/ )3%(") #GFOr.   c                 h    | j                   d   |k(  ry || j                   d<   | j                          y )Nr  )r  r4  )r   modes     r,   r-  zScatterPlotItem.setPxMode  s.    99X$&"		(r.   c           
         t        j                         }|| j                  }d}| j                  d   r|| j                  d   rm|d   d   dk(  }t	        j
                  |      r<d}| j                  t        t        | j                  g d||	                }||d   |<   | j                          nd}| j                  |
       |r| j                          y y )NFr  r  r   r)   r   Tr	  )r   idxr   )r   r   r   r  rW   anyr  rY   r   _style_maybeRebuildAtlas_updateMaxSpotSizesr4  )r   r(  r   r4  r'  coordss         r,   r5  zScatterPlotItem.updateSpots  s    >>#?iiG
99X499Z#8<(-2Dvvd|!
++dkk*LSZ`dkefg /5%d+##%J  g .OO r.   c           
      &   t        | j                        }||kD  rw||t        | j                        z  kD  r[| j                  j                  t	        t        | j                  g d                    d| j                  d<   | j                          y y y )Nr	  r   r   )r[   r  r   r   rY   r   rc  r5  )r   	thresholdminlenr   s       r,   rd  z"ScatterPlotItem._maybeRebuildAtlas  s{    ""#JQS^!;;&&S$++&HIJK '(DIIl# <Jr.   c              #     K   || j                   }|t        j                  d d  }|D ]  }||   |   }|j                  |j	                         }| j
                  d   r7| j
                  d|j                         z      }|t        |   k7  r|||d   |   <   | j
                  |   |t        j                  |t        |         <   |dk(  r|||z  }|  y w)Nr  r
  r   rK   )	r   rW   s_basecopyr  r  r  equal)r   r  r   ra  rQ   r   colvals           r,   rc  zScatterPlotItem._style  s     <99D;%%(C 	Cs)C.Cxx#hhjyy%ii#))+ 56.--03CY,-6:iinCnS123f}!2uI	s   CCc           
      2   | j                   d   r(| j                   d   rd| j                  j                  }}nIt        t	        j
                  | j                  | j                  fg | j                  di |            \  }}|| _        || _        d d g| _	        y )Nr  r  r   r   )
r  r  r   r`   r   chainr  r  _measureSpotSizesr  )r   r   r)   pws       r,   re  z#ScatterPlotItem._updateMaxSpotSizes6  s    99X499Z#8t))22rA	$*<*<d>R>R)S(T4d44>v>@ AEAr!Tlr.   c              +   0  K   t         | j                  ddgfi | }| j                  d   r"|D ]  \  }}d||j                         z   f  y|D ]A  \  }}|j	                         r||j                         f +||j                         z   df C yw)z1Generate pairs (width, pxWidth) for spots in datarK   rL   r  r   N)r   rc  r  rc   
isCosmetic)r   r   r   rK   rL   s        r,   rs  z!ScatterPlotItem._measureSpotSizes@  s     kdkk65/<V<=99X# -	c

,,,- $ 1	c>>#

,,-q00	1s   BBc                     d| _         d| _        t        j                  d| j                  j
                        | _        ddg| _        | j                          y)z&Remove all spots from the scatter plotr   r   N)r  r  rW   r  r   r   r  r4  r   s    r,   r   zScatterPlotItem.clearN  sC      HHQdiioo6	Tlr.   c                    |dk\  r || j                   |   | j                   |   S | j                  t        | j                        dk(  ry|dk(  r| j                  d   }| j                  d   }n/|dk(  r| j                  d   }| j                  d   }nt        d      |&||d   k\  ||d   k  z  }||   }|j                  dk(  ry|dk\  rft        j                  |      | j                  dz  z
  t        j                  |      | j                  dz  z   f| j                   |<   | j                   |   S |d	k  rt        d
t        |      z        t        j                  |      }||   }t        j                  |dd|z
  z  dd|z   z  g      S )Nr   r   NNr   r   r   zInvalid axis valueea?r6   z0Value for parameter 'frac' must be > 0. (got %s)2   )r  r   r[   
ValueErrorrK   rW   nanminr  nanmaxr)  rU   isfinite
percentile)r   axfrac
orthoRanger   d2r'  s          r,   
dataBoundszScatterPlotItem.dataBoundsW  s   3;:-$++b/2M;;r?" 99DII! 37		#A3B1W		#A3B122!*Q-'B*Q-,?@D$Avv{#3;!yy|d.@.@.GGSTX\XjXjkqXqIqrDKKO;;r?"S[NQTUYQZZ[[;;q>D$A==R1t8_bAHo$FGGr.   c                      | j                   dz  S )Nrz  )r  r   s    r,   pixelPaddingzScatterPlotItem.pixelPaddingy  s    ##F**r.   c                    | j                  d      \  }}| j                  d      \  }}||d}d}||d}d}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
        S # t        $ r d}Y \w xY w# t        $ r d}Y Xw xY w)Nr   )r  r   r6   r   )r  r  pixelVectorslengthOverflowErrorr
   r$   )r   xmnxmxymnymxpxpypxPads           r,   boundingRectzScatterPlotItem.boundingRect|  s    ___*
c___*
c;#+CC;#+CCR!!#19&&(FB*Q"))+*Q"))+
 %KB%KB}}SVSVadCZ^adCZ^LL !  ! s$   (C =C CCC*)C*c                 `    | j                          t        j                  |        d d g| _        y rP   )r2  r   viewTransformChangedr  r   s    r,   r  z$ScatterPlotItem.viewTransformChanged  s'    ""$++D1Tlr.   c                 V    t        j                  | g|i | | j                          y rP   )r   setExportModer4  )r   r~   kwdss      r,   r  zScatterPlotItem.setExportMode  s$    $$T9D9D9r.   c           
      .	   t        j                         }| j                  j                  dd       }||j	                  |       | j
                  dur9| j
                  j                  dd      }| j
                  j                  dd      }n| j                  d   }d}| j                  d   du r| j                  | j                               }t        j                  | j                  d   | j                  d	   g      }	t        j                  |j                         |	      }	t        j                  |	d
d      }	|j                          | j                  d   r| j
                  du r| j                   j#                         }
|k|j%                         x}|
k7  rV|}
| j                   j'                  |
       | j                   j)                          d| j                  d<   | j+                          |	d d |f   j,                  }| j                  d   |   }| j.                  j1                  |j2                         | j.                  j5                         }||d d ddf<   t        j6                  |t8              j;                  d      |d d ddf<   d|
z  d|
z  ddg|d d ddf<    |d       | j.                  j=                         } |j>                  g || j                   j@                     |d       y |jC                  |jD                  jF                  |       tI        |	d d |f   j,                  tI        | jK                  g d||             D ]0  \  }}|j                           |jL                  |  tO        |g|  2 y | jP                  tS        jT                         | _(        tS        jV                  | jP                        }tI        | j                  d   | j                  d	   tI        | jK                  g d|             D ]4  \  }}}|j                          |jM                  ||       tO        |g|  6 |jY                          |jC                  |jD                  jF                  |       | jP                  j[                  |       y )Nr  Fr   TresolutionScaler   r  r   r   i   i   @r  r   r   r   r   )rI   r      r   r6   r   prepdrawr	  )ra  rQ   )rQ   ).r   r   r  r0  setCompositionMode_exportOpts_maskAtviewRectrW   vstackr   r{   transformCoordinates	transform
clip_arrayresetTransformr  r   devicePixelRatioFrh   r   r5  Tr  resizerK   r*  
frombufferrd   reshapedrawargsdrawPixmapFragmentsr   rm   rn   ro   r   rc  rp   r^   r  r   QPicturerl   rs   play)r   r   optionwidgetr   cmodeaarQ   viewMaskptsru   dpr_newxysrfragsr  ptr   p2r   r   s                        r,   paintzScatterPlotItem.paint  s   >>#		/6  ' 5(!!%%k48B$$(():C@E;'BE99X$&||DMMO4H ))TYYs^TYYs^<=C))!++-=C--Xw7Cyy$)9)9U)B ((99;%f6N6N6P+P7UX*X!C&&::3?&&,,../DIIl+$$& H%''YY|,X6%%,,RWW5--557 "a1f "b < D DW Ma1f"#C%3S!9a2g 0099;%%%KxK1C1C1J1JK   9 92>!$AxK(**dkk*LRZbgkhj" *IB $$&AKK$q)5)* ||#$~~/^^DLL1#&		#		#T[[)KSX[YZ$ +KAq%
 %%'LLA&r*E*+ OOALL55r:LLa r.   c                     t        j                  | j                  d   d       }t        j                  |      d d df   D ]'  }| j                  |   }|d   t	        || |      |d<   ) | j                  d   S )Nr   r   )rW   rn  r   argwherer   )r   mr:  r]  s       r,   pointszScatterPlotItem.points  su    HHTYYv&-Q1% 	5A))A,C6{"&sD!4F	5 yy  r.   c                 R    | j                         | j                  |         d d d   S )NrI   )r  r  )r   r&  s     r,   pointsAtzScatterPlotItem.pointsAt  s%    {{}T\\#./"55r.   c                    t        |t        j                        r%|j                         x}}|j	                         x}}nat        |t        j
                        rA|j                         }|j                         }|j                         }|j                         }nt        | j                  d   r4| j                  d   r%| j                  d   d   }| j                  d   d   }n| j                  dg      \  }|x}}|dz  }|dz  }| j                  d   rG| j                         \  }	}
	 |	dn|	j                         }		 |
dn|
j                         }
||	z  }||
z  }| j                  d	   | j                  d
   |z   |kD  z  | j                  d
   |z
  |k  z  | j                  d   |z   |kD  z  | j                  d   |z
  |k  z  S # t         $ r d}	Y w xY w# t         $ r d}
Y w xY w)zd
        Return a boolean mask indicating all points that overlap obj, a QPointF or QRectF.
        r  r  r   r)   r   rK   r   r   rN   r   r   )rT   r
   r+  r   r   r$   leftrighttopbottom	TypeErrorr  r   rc  r  r  r  )r   r   lr(   r   br)   r   r   r  r  s              r,   r  zScatterPlotItem._maskAt  s    c6>>*EEGOAEEGOAV]]+
A		A	A

AO99X499Z#8		,',A		,',AfX&BAIAEE99X&&(FB*Q"))+*Q"))+ GAGA		)$99S>A%)+99S>A%)+ 99S>A%)+ 99S>A%)	+ 	, !  ! s$   )G >G GGG"!G"c                    |j                         t        j                  j                  j                  k(  r}| j                  |j                               }t        |      dkD  r?|| _        |j                          | j                  j                  | | j                  |       y |j                          y |j                          y r   )buttonr
   r   MouseButton
LeftButtonr  r&  r[   
ptsClickedaccept
sigClickedr7  ignore)r   evr  s      r,   mouseClickEventzScatterPlotItem.mouseClickEvent+  s}    99;&))//:::--)C3x!|"%		$$T4??B? 		IIKr.   c           	      ,   | j                   d   r| j                  d   }|j                  r#t        j                  | j                  d         }n| j                  |j                               }| j                         r4d| j                  d   ||z  <   || j                  d<   | j                          | j                         |   d d d   }| j                         }|| j                   d   t        |      dkD  rd}|d | D cg c]`  } | j                   d   |j                         j                         |j                         j                         |j                               b }}t        |      |kD  r,|j                  d	j                  t        |      |z
               |j!                  d
j#                  |             d| _        n$| j$                  s|j!                  d       d| _        | j&                  j)                  | ||       y y c c}w )Nr  r   r   r   rI   r     )r   r   r   z({} others...)z

F T)r  r   exitrW   
zeros_liker  r&  _hasHoverStyler5  r  
getViewBoxr[   r   r   r   r  
setToolTipjoinr  
sigHoveredr7  )	r   r  oldr   r  vbcutoffr  r  s	            r,   
hoverEventzScatterPlotItem.hoverEvent8  s   99[!))I&CwwmmDIIi$89ll2668,""$56		,'c	2'*		)$  "[[]3'"-F "B~$))E"2">v;?F%+GV_6! ,499U+bffhjjlbffhjjlQSQXQXQZ[ 6C 66{V+

#3#:#:3v;;O#PQMM&++c"23+0D(--MM"%+/D(OO  vr2= "(6s   A%Hc                 ,     t         fddD              S )Nc              3   r   K   | ].  }j                   d |j                         z      t        |   k7   0 yw)r
  N)r  r  r  ).0r   r   s     r,   	<genexpr>z1ScatterPlotItem._hasHoverStyle.<locals>.<genexpr>Z  s9      B 99Wsyy{23~c7JJ Bs   47r	  )rb  r   s   `r,   r  zScatterPlotItem._hasHoverStyleY  s!     B@B B 	Br.   rP   )TNNry  )r   i  )NNN)r   N),r   r   r   r   r
   Signalr  r  r  r6  r   r  r"  r4  rC  rH  r  rR   rS   rS  rV  rY  r1  r-  r5  rd  rc  re  rs  r   r  r  r  r  r  r   warnOnExceptionr  r  r  r  r  r  r  r   r.   r,   r   r   J  s   ( vvv6Jvvv6J"V]]6*N:$x2'hw'r
.!+&,&,,&\&0&*#$00#1 HD+M:#
 N! N!`!6+,Z3BBr.   c                       e 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d Zd Zd Zd Zd Zd Zd Zd Zd Zy)r   z
    Class referring to individual spots in a scatter plot.
    These can be retrieved by calling ScatterPlotItem.points() or
    by connecting to the ScatterPlotItem's click signals.
    c                 T    || _         || _        t        j                  |      | _        y rP   )r   _indexweakrefref_SpotItem__plot_ref)r   r   plotindexs       r,   r   zSpotItem.__init__e  s"    
 "++d+r.   c                 "    | j                         S rP   )r  r   s    r,   _plotzSpotItem._plotm  s      r.   c                      | j                   d   S )z/Return the user data associated with this spot.r   r   r   s    r,   r   zSpotItem.dataq  s    zz&!!r.   c                     | j                   S )zAReturn the index of this point as given in the scatter plot data.)r  r   s    r,   r  zSpotItem.indexu  s    {{r.   c                 v    | j                   d   dk(  r| j                  j                  d   S | j                   d   S )zReturn the size of this spot.
        If the spot has no explicit size set, then return the ScatterPlotItem's default size instead.rK   rI   )r   r  r  r   s    r,   rK   zSpotItem.sizey  s7     ::f#::??6**::f%%r.   c                 N    t        | j                  d   | j                  d         S rB  )r	   r   r   s    r,   r&  zSpotItem.pos  s    TZZ_djjo66r.   c                 T    | j                   j                  | j                               S rP   )r  	mapToViewr&  r   s    r,   viewPoszSpotItem.viewPos  s    zz##DHHJ//r.   c                 B    || j                   d<   | j                          y)zSet the size of this spot.
        If the size is set to -1, then the ScatterPlotItem's default size
        will be used instead.rK   Nr   
updateItem)r   rK   s     r,   rV  zSpotItem.setSize  s     "

6r.   c                     | j                   d   }|| j                  j                  d   }	 t        |      }t	        t
        j                               |t        t
              z     }|S #  Y |S xY w)zReturn the symbol of this spot.
        If the spot has no explicit symbol set, then return the ScatterPlotItem's default symbol instead.
        rJ   )r   r  r  rd   rY   rV   r   r[   )r   rJ   r   s      r,   rJ   zSpotItem.symbol  sk     H%>ZZ__X.F	FA',,.)!c'l*:;F 	s   ;A) )A.c                 B    || j                   d<   | j                          y)zSet the symbol for this spot.
        If the symbol is set to '', then the ScatterPlotItem's default symbol will be used instead.rJ   Nr  )r   rJ   s     r,   rS  zSpotItem.setSymbol  s      &

8r.   c                     | j                   d   }|| j                  j                  d   }t        j                  |      S )NrL   )r   r  r  r{   r|   )r   rL   s     r,   rL   zSpotItem.pen  s5    jj;**//%(Cxx}r.   c                 T    t        |i || j                  d<   | j                          y)z!Set the outline pen for this spotrL   N)r   r   r  r   r~   r  s      r,   rR   zSpotItem.setPen  s$    "D2E2

5r.   c                 B    d| j                   d<   | j                          y)zVRemove the pen set for this spot; the scatter plot's default pen will be used instead.NrL   r  r   s    r,   resetPenzSpotItem.resetPen  s     

5r.   c                     | j                   d   }|| j                  j                  d   }t        j                  |      S )NrM   )r   r  r  r{   r   )r   rM   s     r,   rM   zSpotItem.brush  s6    

7#=JJOOG,Ezz%  r.   c                 T    t        |i || j                  d<   | j                          y)z Set the fill brush for this spotrM   N)r   r   r  r  s      r,   rS   zSpotItem.setBrush  s$    &66

7r.   c                 B    d| j                   d<   | j                          y)zZRemove the brush set for this spot; the scatter plot's default brush will be used instead.NrM   r  r   s    r,   
resetBrushzSpotItem.resetBrush  s    "

7r.   c                      | j                   d   S )NrN   r  r   s    r,   	isVisiblezSpotItem.isVisible  s    zz)$$r.   c                 B    || j                   d<   | j                          y)z(Set whether or not this spot is visible.rN   Nr  )r   rN   s     r,   
setVisiblezSpotItem.setVisible  s     '

9r.   c                 "    || j                   d<   y)z+Set the user-data associated with this spotr   Nr  )r   r   s     r,   r  zSpotItem.setData  s    !

6r.   c                     d| j                   d<   | j                  j                  | j                   j                  d             y )N)r   r   r   r   r   r   )r   r  r5  r  r   s    r,   r  zSpotItem.updateItem  s1    #/

< 

tzz11!45r.   N)r   r   r   r   r   r   r  r   r  rK   r&  r  rV  rJ   rS  rL   rR   r  rM   rS   r  r
  r  r  r  r   r.   r,   r   r   ^  sz    , ! !"&70

!
%
"6r.   )r1   r   r   r   )/r   ra   r  collectionsr   numpyrW   r  r   r   r   r{   r   r	   r
   r   r   __all__	name_listr#   rV   r%   r$   addRectr-   rf  r   r<  cr&   r   r   r'   closeSubpath
QTransformtrrotater   r  r^   rx   r   r   r  r   r   r   )r  s   0r,   <module>r     s8      #       *j
)Q	
	J0e0023J
K   dD!Q7 8   ]V]]4q!4 5 %  
/
.
/
.	5


/
% '
0 LLN DAqGAJqtu  !
!Q AJ	
 U 		"vvgcl# 		"
 34 w}56 w|45  "TDUYZ
2	)	+~& ~BQBn QBhs6v s6S" Ks   H