
    e                         d dl Z d dlmZmZmZmZmZmZmZ d dlZ	ddl
mZ ddl
mZ ddl
mZ ddlmZ ddlmZmZmZ d	d
lmZ dgZ G d de      Zy)    N)ceilfloorisfinitelog10sqrtfrexpr      )debug)	functions)getConfigOption)Point)QtCoreQtGui	QtWidgets   )GraphicsWidgetAxisItemc                   L   e Zd ZdZd4dZd Zd Zd Zd Zd Z	d5d	Z
d6d
Zd7dZd Zd Zd Zd Zd5dZd Zd5dZd Zd Zd Zd Zd Zd Zd Zd5dZd6dZd Zd Zd Zd Z d  Z!d! Z"d5d"Z#d# Z$d$ Z%d8d%Z&d& Z'd7d'Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4y)9r   a6  
    GraphicsItem showing a single plot axis with ticks, values, and label.
    Can be configured to fit on any side of a plot, 
    Can automatically synchronize its displayed scale with ViewBox items.
    Ticks can be extended to draw a grid.
    If maxTickLength is negative, ticks point into the plot.
    Nc                 L   t        j                  | |       t        j                  |       | _        d| _        || _        |dvrt        d      |dv r| j                  j                  d       d}nd}dd	gd
ddd|ddg d||d	d	dd| _	        d
| _
        d| _        d| _        d| _        |	| _        |
| _        || _        || _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        | j3                  d       | j5                  dd       || j7                          n| j7                  |       || j9                          n| j9                  |       || j;                          n| j;                  |       d| _        || j?                  |       d| _         y)a  
        =============== ===============================================================
        **Arguments:**
        orientation     one of 'left', 'right', 'top', or 'bottom'
        maxTickLength   (px) maximum length of ticks to draw. Negative values draw
                        into the plot, positive values draw outward.
        linkView        (ViewBox) causes the range of values displayed in the axis
                        to be linked to the visible range of a ViewBox.
        showValues      (bool) Whether to display values adjacent to ticks
        pen             (QPen) Pen used when drawing axis and (by default) ticks
        textPen         (QPen) Pen used when drawing tick labels.
        tickPen         (QPen) Pen used when drawing ticks.
        text            The text (excluding units) to display on the label for this
                        axis.
        units           The units for this axis. Units should generally be given
                        without any scaling prefix (eg, 'V' instead of 'mV'). The
                        scaling prefix will be automatically prepended based on the
                        range of data displayed.
        args            All extra keyword arguments become CSS style options for
                        the <span> tag which will surround the axis label and units.
        =============== ===============================================================
        N)leftrighttopbottomzHOrientation argument must be one of 'left', 'right', 'top', or 'bottom'.r   r   iFT   r	         )FF))r   皙?)r	   g333333?)   g?)   g?)tickTextOffsettickTextWidthtickTextHeightautoExpandTextSpaceautoReduceTextSpacehideOverlappingLabelstickFontstopAxisAtTicktextFillLimits
showValues
tickLengthmaxTickLevelmaxTextLevel	tickAlpha      ?r   r   )!r   __init__r   QGraphicsTextItemlabelpictureorientation	ExceptionsetRotationstyle	textWidth
textHeight
fixedWidthfixedHeight	labelText
labelUnitslabelUnitPrefix
labelStylelogMode_tickDensity_tickLevels_tickSpacingscaleautoSIPrefixautoSIPrefixScale	showLabelsetRangesetPen
setTextPen
setTickPen_linkedView_linkToView_internalgrid)selfr4   pentextPentickPenlinkViewparentmaxTickLengthr*   textunits
unitPrefixargshide_overlapping_labelss                 B/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/AxisItem.pyr0   zAxisItem.__init__   s   0 	f-006
&@@fgg++JJ""3'&+#&*#  !!f #'#'%<, %''

,  )  
 !$ua;KKMKK?OOOOG$?OOOOG$%%h/	    c                 H   |j                         D ]  \  }}|| j                  vrt        d|z        |dv rt        |t              st        d|z        |dk(  r4| j                  dv r|| j                  d   d<   j|| j                  d   d<   }|dk(  rH	 t        |      d	k(  r&t        |d   t              rt        |d   t              sJ 	 || j                  |<   || j                  |<    d| _	        | j                          | j                          y#  t        d
      xY w)a  
        Set various style options.

        ===================== =======================================================
        Keyword Arguments:
        tickLength            (int) The maximum length of ticks in pixels.
                              Positive values point toward the text; negative
                              values point away.
        tickTextOffset        (int) reserved spacing between text and axis in px
        tickTextWidth         (int) Horizontal space reserved for tick text in px
        tickTextHeight        (int) Vertical space reserved for tick text in px
        autoExpandTextSpace   (bool) Automatically expand text space if the tick
                              strings become too long.
        autoReduceTextSpace   (bool) Automatically shrink the axis if necessary
        hideOverlappingLabels (bool or int)

                              * *True*  (default for horizontal axis): Hide tick labels which extend beyond the AxisItem's geometry rectangle.
                              * *False* (default for vertical axis): Labels may be drawn extending beyond the extent of the axis.
                              * *(int)* sets the tolerance limit for how many pixels a label is allowed to extend beyond the axis. Defaults to 15 for `hideOverlappingLabels = False`.

        tickFont              (QFont or None) Determines the font used for tick
                              values. Use None for the default font.
        stopAxisAtTick        (tuple: (bool min, bool max)) If True, the axis
                              line is drawn only as far as the last tick.
                              Otherwise, the line is drawn to the edge of the
                              AxisItem boundary.
        textFillLimits        (list of (tick #, % fill) tuples). This structure
                              determines how the AxisItem decides how many ticks
                              should have text appear next to them. Each tuple in
                              the list specifies what fraction of the axis length
                              may be occupied by text, given the number of ticks
                              that already have text displayed. For example::

                                  [(0, 0.8), # Never fill more than 80% of the axis
                                   (2, 0.6), # If we already have 2 ticks with text,
                                             # fill no more than 60% of the axis
                                   (4, 0.4), # If we already have 4 ticks with text,
                                             # fill no more than 40% of the axis
                                   (6, 0.2)] # If we already have 6 ticks with text,
                                             # fill no more than 20% of the axis

        showValues            (bool) indicates whether text is displayed adjacent
                              to ticks.
        tickAlpha             (float or int or None) If None, pyqtgraph will draw the
                              ticks with the alpha it deems appropriate.  Otherwise,
                              the alpha will be fixed at the value passed.  With int,
                              accepted values are [0..255].  With value of type
                              float, accepted values are from [0..1].
        ===================== =======================================================

        Added in version 0.9.9
        z!%s is not a valid style argument.)r+   r!   r"   r#   zArgument '%s' must be intr!   r   r   r   r(   r	   z5Argument 'stopAxisAtTick' must have type (bool, bool)N)itemsr7   	NameError
isinstanceint
ValueErrorr4   lenboolr3   _adjustSizeupdate)rO   kwdskwdvalues       r[   setStylezAxisItem.setStyle   s.   j  	(IC$**$ Cc IJJYY!%-$%@3%FGG&&##'886;DJJ/036;DJJ/03((^u:?z%(D/IjY^_`YacgNhhhNh #(

3"'

3)	(, ^$%\]]s   6DD!c                     | j                         j                  | j                         d | _        | j                         j                  |        y N)scene
removeItemr2   rO   s    r[   closezAxisItem.close   s5    



+


%r\   c                 `    || _         d| _        | j                          | j                          y)zSet the alpha value (0-255) for the grid, or False to disable.

        When grid lines are enabled, the axis tick lines are extended to cover
        the extent of the linked ViewBox, if any.
        N)rN   r3   prepareGeometryChangerf   )rO   rN   s     r[   setGridzAxisItem.setGrid   s'     	""$r\   c                 &   t        |      dk(  r|d   | _        ndt        |      dk(  r|\  }}n"|j                  d      }|j                  d      }|| j                  dv r|| _        || j                  dv r|| _        | j                  q| j                  dv r+| j	                         j                  d| j                         n8| j                  dv r*| j	                         j                  d| j                         d| _        | j                          y)	a  
        Set log scaling for x and/or y axes.

        If two positional arguments are provided, the first will set log scaling
        for the x axis and the second for the y axis. If a single positional
        argument is provided, it will set the log scaling along the direction of
        the AxisItem. Alternatively, x and y can be passed as keyword arguments.

        If an axis is set to log scale, ticks are displayed on a logarithmic scale
        and values are adjusted accordingly. (This is usually accessed by changing
        the log mode of a :func:`PlotItem <pyqtgraph.PlotItem.setLogMode>`.) The 
        linked ViewBox will be informed of the change.
        r   r   r	   xyN)r   r   r   )rc   r@   getr4   rL   
setLogModer3   rf   )rO   rY   kwargsru   rv   s        r[   rx   zAxisItem.setLogMode   s     t9>7DL4yA~1JJsOJJsO}!1!15F!F }!1!15F!F '#44  "--c4<<@!!%66  "--c4<<@r\   c                 p    || j                   d<   d| _        | j                          | j                          y)zs
        (QFont or None) Determines the font used for tick values. 
        Use None for the default font.
        r'   N)r7   r3   rr   rf   )rO   fonts     r[   setTickFontzAxisItem.setTickFont  s0    
 "&

:""$ 	r\   c                 .   d}| j                   d | _        y | j                   j                         }t        j                  dd      }| j
                  dk(  ra|j                  t        | j                         j                         dz  |j                         dz  z                |j                  |        n| j
                  dk(  r|j                  t        | j                         j                         dz  |j                         dz  z                |j                  t        | j                         j                         |j                         z
  |z                n| j
                  dk(  r`|j                  |        |j                  t        | j                         j                         dz  |j                         dz  z
               n| j
                  dk(  r|j                  t        | j                         j                         dz  |j                         dz  z
               |j                  t        | j                         j                         |j                         z
  |z                | j                   j                  |       d | _        y )	Nr   r   r   r	   r   r          @r   )r2   r3   boundingRectr   QPointFr4   setYra   sizeheightwidthsetXsetPos)rO   evnudgebrps        r[   resizeEventzAxisItem.resizeEvent  s    ::DLZZ$$&NN1a v%FF3tyy{))+A-
1<=>FFE6N(FF3tyy{))+A-
1<=>FF3tyy{((*299;6u<=>&FFE6NFF3tyy{((*2-
2=>?)FF3tyy{((*2-
2=>?FF3tyy{))+BIIK7=>?

!r\   c                     | j                   j                  |       | j                  dv r| j                          n| j	                          | j
                  r| j                          yy)z'Show/hide the label text for this axis.r   N)r2   
setVisibler4   _updateWidth_updateHeightrE   updateAutoSIPrefix)rO   shows     r[   rG   zAxisItem.showLabel,  sW     	

d#00 ##% r\   c                     |xs d| _         |xs d| _        |xs d| _        t        |      dkD  r|| _        |s|rdnd}| j                  |       | j                          y)a  Set the text displayed adjacent to the axis.

        ==============  =============================================================
        **Arguments:**
        text            The text (excluding units) to display on the label for this
                        axis.
        units           The units for this axis. Units should generally be given
                        without any scaling prefix (eg, 'V' instead of 'mV'). The
                        scaling prefix will be automatically prepended based on the
                        range of data displayed.
        args            All extra keyword arguments become CSS style options for
                        the <span> tag which will surround the axis label and units.
        ==============  =============================================================

        The final text generated for the label will look like::

            <span style="...options...">{text} (prefix{units})</span>

        Each extra keyword argument will become a CSS option in the above template.
        For example, you can set the font size and color of the label::

            labelStyle = {'color': '#FFF', 'font-size': '14pt'}
            axis.setLabel('label text', units='V', **labelStyle)

         r   TFN)r<   r=   r>   rc   r?   rG   _updateLabel)rO   rV   rW   rX   rY   visibles         r[   setLabelzAxisItem.setLabel7  s\    6 +2)/Rt9q="DO5$uwr\   c                     | j                   j                  | j                                | j                          d| _        | j                          y)z9Internal method to update the label according to the textN)r2   setHtmllabelStringre   r3   rf   ro   s    r[   r   zAxisItem._updateLabel\  s9    

4++-.r\   c           	      n   | j                   dk(  r1| j                  r| j                  dk(  rd}n/dd| j                  z  z  }nd| j                  | j                   d}| j                  d|}dj                  | j                  D cg c]  }|d| j                  |    c}      }d	|d
|dS c c}w )Nr   r/   z(x%g)() ;z: z<span style='z'>z</span>)r=   rE   rF   r>   r<   joinr?   )rO   rW   skr7   s        r[   r   zAxisItem.labelStringc  s    ??b $$(>(>#(E3t'='=#=>	 ! !% 4 4dooFE~~u-dooVa);<VW/4a88 Ws   B2c                 z   | j                   dv r| j                  d   r)|| j                  kD  s|| j                  dz
  k  rF|| _        n>t        | j                  |      }|| j                  kD  s|| j                  dz
  k  r|| _        | j                  d   r| j	                          y y | j                  d   r)|| j
                  kD  s|| j
                  dz
  k  rF|| _        n>t        | j
                  |      }|| j
                  kD  s|| j
                  dz
  k  r|| _        | j                  d   r| j                          y y )Nr   r%   
   r$   )r4   r7   r8   maxr   r9   r   )rO   ru   mxs      r[   _updateMaxTextSizezAxisItem._updateMaxTextSizer  s    00zz/0t~~%T^^b-@)@%&DN+&"t~~/B*B%'DNzz/0!!# 1 zz/0t&!doo.B*B&'DO!,'2"0D+D&(DOzz/0""$ 1r\   c                 b    | j                   dv r| j                          y | j                          y Nr   )r4   r   r   ro   s    r[   re   zAxisItem._adjustSize  s)    00 r\   c                 2    || _         | j                          y)zSet the height of this axis reserved for ticks and tick labels.
        The height of the axis label is automatically added.

        If *height* is None, then the value will be determined automatically
        based on the size of the tick text.N)r;   r   rO   hs     r[   	setHeightzAxisItem.setHeight  s     r\   c                 <   | j                         sd}n| j                  | j                  d   sd}n+| j                  d   r| j                  }n| j                  d   }|| j                  d   r| j                  d   d   ndz  }|t	        d| j                  d         z  }| j
                  j                         r;|| j
                  j                         j                         dz  z  }n| j                  }| j                  |       | j                  |       d | _
        y )	Nr   r*   r$   r#   r!   r   r+   r   )	isVisibler;   r7   r9   r   r2   r   r   setMaximumHeightsetMinimumHeightr3   r   s     r[   r   zAxisItem._updateHeight  s    ~~A'zz,/AZZ 56A

#34A

<8PTZZ 01!4VWWSDJJ|455::'')00299;cAAA$$a a r\   c                 2    || _         | j                          y)zSet the width of this axis reserved for ticks and tick labels.
        The width of the axis label is automatically added.

        If *width* is None, then the value will be determined automatically
        based on the size of the tick text.N)r:   r   rO   ws     r[   setWidthzAxisItem.setWidth  s     r\   c                 <   | j                         sd}n| j                  | j                  d   sd}n+| j                  d   r| j                  }n| j                  d   }|| j                  d   r| j                  d   d   ndz  }|t	        d| j                  d         z  }| j
                  j                         r;|| j
                  j                         j                         dz  z  }n| j                  }| j                  |       | j                  |       d | _
        y )Nr   r*   r$   r"   r!   r+   r   )r   r:   r7   r8   r   r2   r   r   setMaximumWidthsetMinimumWidthr3   r   s     r[   r   zAxisItem._updateWidth  s    ~~A&zz,/AZZ 56A

?3A

<8PTZZ 01!4VWWSDJJ|455::'')00299;cAAAOOQQr\   c                     | j                   t        j                  t        d            S t        j                  | j                         S N
foreground)_penfnmkPenr   ro   s    r[   rP   zAxisItem.pen  s3    9988OL9::xx		""r\   c                     d| _         |s|rt        j                  |i || _        n#t        j                  t	        d            | _        | j                  j                         j                         | j                  d<   | j                          y)z
        Set the pen used for drawing text, axes, ticks, and grid lines.
        If no arguments are given, the default foreground color will be used
        (see :func:`setConfigOption <pyqtgraph.setConfigOption>`).
        Nr   color)	r3   r   r   r   r   r   namer?   r   rO   rY   ry   s      r[   rI   zAxisItem.setPen  sh     6$1&1DI!>?DI#'99??#4#9#9#; r\   c                     | j                   t        j                  t        d            S t        j                  | j                         S r   )_textPenr   r   r   ro   s    r[   rQ   zAxisItem.textPen  s3    == 88OL9::xx&&r\   c                     d| _         |s|rt        j                  |i || _        n#t        j                  t	        d            | _        | j                  j                         j                         | j                  d<   | j                          y)z
        Set the pen used for drawing text.
        If no arguments are given, the default foreground color will be used.
        Nr   r   )	r3   r   r   r   r   r   r   r?   r   r   s      r[   rJ   zAxisItem.setTextPen  sj    
 6HHd5f5DMHH_\%BCDM#'==#6#6#8#=#=#? r\   c                 x    | j                   | j                         S t        j                  | j                         S rl   )_tickPenrP   r   r   ro   s    r[   rR   zAxisItem.tickPen  s+    == 88:88DMM**r\   c                 ~    d| _         |s|rt        j                  |i || _        nd| _        | j	                          y)z{
        Set the pen used for drawing tick marks.
        If no arguments are given, the default pen will be used.
        N)r3   r   r   r   r   r   s      r[   rK   zAxisItem.setTickPen  s8    
 6HHd5f5DM DMr\   c                 R    || j                   k7  r|| _         | j                          yy)z
        Set the value scaling for this axis.

        Setting this value causes the axis to draw ticks and tick labels as if
        the view coordinate system were scaled. By default, the axis scaling is
        1.0.
        N)rD   r   )rO   rD   s     r[   setScalezAxisItem.setScale  s(     DJJDJ r\   c                 2    || _         | j                          y)aM  
        Enable (or disable) automatic SI prefix scaling on this axis.

        When enabled, this feature automatically determines the best SI prefix
        to prepend to the label units, while ensuring that axis values are scaled
        accordingly.

        For example, if the axis spans values from -0.1 to 0.1 and has units set
        to 'V' then the axis would display values -100 to 100
        and the units would appear as 'mV'

        This feature is enabled by default, and is only available when a suffix
        (unit string) is provided to display on the label.
        N)rE   r   )rO   enables     r[   enableAutoSIPrefixzAxisItem.enableAutoSIPrefix  s     #!r\   c           	         | j                   j                         r| j                  r#dt        j                  | j
                        z  }n| j
                  }t        j                  t        t        |d   | j                  z        t        |d   | j                  z                    \  }}| j                  dk(  r|dv rd}d}|| _        || _        nd| _        | j                          y )Nr   r   r   r   )r   mr/   )r2   r   r@   nparrayranger   siScaler   absrD   r=   rF   r>   r   )rO   _rangerD   prefixs       r[   r   zAxisItem.updateAutoSIPrefix&  s    ::!||RXXdjj11 jjS4::1E-FFSTIVZV`V`L`Ha)bcOUF"$:)=%*D"#)D %(D"r\   c                     t        |      rt        |      s$t        dt        |      dt        |      d      ||g| _        | j                  r| j                          yd| _        | j                          y)zSet the range of values displayed by the axis.
        Usually this is handled automatically by linking the axis to a ViewBox with :func:`linkToView <pyqtgraph.AxisItem.linkToView>`zNot setting range to [z, ]N)r   r5   strr   rE   r   r3   rf   )rO   mnr   s      r[   rH   zAxisItem.setRange7  sY     |8B<s2wBPQQ"X
##%DLKKMr\   c                 <    | j                   y| j                         S )z*Return the ViewBox this axis is linked to.N)rL   ro   s    r[   
linkedViewzAxisItem.linkedViewD  s     ###%%r\   c                 T   | j                          t        j                  |      | _        | j                  dv r&|j
                  j                  | j                         n%|j                  j                  | j                         |j                  j                  | j                         y )Nr   r   )
unlinkFromViewweakrefrefrL   r4   sigYRangeChangedconnectlinkedViewChangedsigXRangeChanged
sigResizedrO   views     r[   rM   zAxisItem._linkToView_internalK  s|     	";;t,00!!))$*@*@A!!))$*@*@A 6 67r\   c                 &    | j                  |       y)z`Link this axis to a ViewBox, causing its displayed range to match the visible range of the view.N)rM   r   s     r[   
linkToViewzAxisItem.linkToViewW  s    !!$'r\   c                 <   | j                         }d| _        | j                  dv r(|M|j                  j	                  | j
                         n'|%|j                  j	                  | j
                         |&|j                  j	                  | j
                         yy)z Unlink this axis from a ViewBox.Nr   )r   rL   r4   r   
disconnectr   r   r   )rO   oldViews     r[   r   zAxisItem.unlinkFromView[  s    //#00"((33D4J4JK"((33D4J4JK))$*@*@A r\   c                 J   | j                   dv rK||j                         d   }|j                         r | j                  |d d d     y  | j                  |  y ||j                         d   }|j	                         r | j                  |d d d     y  | j                  |  y )Nr   r   r   )r4   	viewRange	yInvertedrH   	xInverted)rO   r   newRanges      r[   r   zAxisItem.linkedViewChangedi  s    00>>+A.~~x"~.x(>>+A.~~x"~.x(r\   c           	      .   d}| j                   d   }|du rn |du rd}n	 t        | j                   d         }| j                         }|| j                  du r| j                  | j                               }| j                   d   }| j                  dk(  r"|j                  d| t        d|       |      }|S | j                  dk(  r!|j                  t        d|      | d|      }|S | j                  d	k(  r"|j                  | d|t        d|             }|S | j                  d
k(  r|j                  | t        d|      |d      }|S | j                  | j                               |j                  | |j                               z  S # t        $ r Y \w xY w)Nr   r&   TF   r+   r   r   r   r   )r7   ra   rb   r   rN   mapRectFromParentgeometryr4   adjustedminmapRectToItemr   )rO   r   rZ   r   recttls         r[   r   zAxisItem.boundingRecty  s   "&**-D"E"d*$-A$$;<> __&
e!3))$--/:D L)B6)}}QS2YJ: K !!W,}}S2YAq9
 K	 !!U*}}aRAAb	z: K !!X-}}aRQrAq9K))$--/:Z=U=UVZ\f\s\s\u=vvv% #t#s   F 	FFc                    t        j                         }| j                  	 t        j                         }t        j
                  |      }| j                  d   r|j                  | j                  d          | j                  |      } |d       | | j                  |g|   |d       |j                          || _        | j                  j                  |       y # j                          w xY w)Nr'   zgenerate specszdraw picture)r
   Profilerr3   r   QPictureQPainterr7   setFontgenerateDrawSpecsdrawPictureendplay)rO   r   optwidgetprofilerr3   painterspecss           r[   paintzAxisItem.paint  s    >>#<<..*..1::j)OODJJz$:;..w7)*$$D$$W5u5^,"DL 	!	 s   BC! !C3c                 @    || _         d| _        | j                          y)a  
        The default behavior is to show at least two major ticks for axes of up to 300 pixels in length, 
        then add additional major ticks, spacing them out further as the available room increases.
        (Internally, the targeted number of major ticks grows with the square root of the axes length.)

        Setting a tick density different from the default value of `density = 1.0` scales the number of
        major ticks that is targeted for display. This only affects the automatic generation of ticks.
        N)rA   r3   rf   )rO   densitys     r[   setTickDensityzAxisItem.setTickDensity  s     $r\   c                 @    || _         d| _        | j                          y)at  Explicitly determine which ticks to display.
        This overrides the behavior specified by tickSpacing(), tickValues(), and tickStrings()
        The format for *ticks* looks like::

            [
                [ (majorTickValue1, majorTickString1), (majorTickValue2, majorTickString2), ... ],
                [ (minorTickValue1, minorTickString1), (minorTickValue2, minorTickString2), ... ],
                ...
            ]

        The two levels of major and minor ticks are expected. A third tier of additional ticks is optional.
        If *ticks* is None, then the default tick system will be used instead.
        N)rB   r3   rf   )rO   tickss     r[   setTickszAxisItem.setTicks  s     !r\   c                 ^    ||d}n|df|dfg}|| _         d| _        | j                          y)a  
        Explicitly determine the spacing of major and minor ticks. This
        overrides the default behavior of the tickSpacing method, and disables
        the effect of setTicks(). Arguments may be either *major* and *minor*,
        or *levels* which is a list of (spacing, offset) tuples for each
        tick level desired.

        If no arguments are given, then the default behavior of tickSpacing
        is enabled.

        Examples::

            # two levels, all offsets = 0
            axis.setTickSpacing(5, 1)
            # three levels, all offsets = 0
            axis.setTickSpacing(levels=[(3, 0), (1, 0), (0.25, 0)])
            # reset to default
            axis.setTickSpacing()
        Nr   )rC   r3   rf   )rO   majorminorlevelss       r[   setTickSpacingzAxisItem.setTickSpacing  s=    * >} !*uaj1"r\   c                 j   | j                   | j                   S t        ||z
        }|dk(  rg S d}t        dd| j                  z  t	        ||z        z        }||z  }t        |      \  }}	dt        |	dz
  dz        dz
  z  }
d|
z  |k  rd}|
dz  }
nd	D ]  }||
z  |k  s n |
z  }d
|z  |z  }|dk(  rd}nd}|D ]  }||
z  }||k\  s n |dfdfg}| j                  d   d
k\  rL|dk(  rd}n|dk(  rd}n|dk(  rd}nd}|}|D ]  }||
z  }||k\  s||k(  s n |k  r|j                  |df       |S )a  Return values describing the desired spacing and offset of ticks.

        This method is called whenever the axis needs to be redrawn and is a
        good method to override in subclasses that require control over tick locations.

        The return value must be a list of tuples, one for each set of ticks::

            [
                (major tick spacing, offset),
                (minor tick spacing, offset),
                (sub-minor tick spacing, offset),
                ...
            ]
        r   g     r@g      @g      $@r   gly	O
@g      Y@r   )2      r   r	   )r   r   )r   r  r  r,   )r   r	   r   r   r  )r	   r   r   r  r  )r   r   r   )	rC   r   r   rA   r   r   r   r7   append)rO   minValmaxValr   difref_sizeminNumberOfIntervalsmajorMaxSpacingmantissaexp2p10unitmajorScaleFactormajorIntervalminorMinSpacingtrialsminorScaleFactorminorIntervalr  extraIntervalextraScaleFactors                       r[   tickSpacingzAxisItem.tickSpacing  s     ($$$&6/"!8I"4$$$tDM':: 

  44 /$a"# 
 '>_,!sNG$0  #g-@ )72 c'$,r!F!F & 	,w6M/	
 AA

 ::n%*2%&!R''!R'$ -$*   07 : O3}7U },}a01r\   c           
         t        ||f      \  }}|| j                  z  }|| j                  z  }g }| j                  |||      }t        j                  g       }t        t        |            D ]  }||   \  }}	t        ||	z
  |z        |z  |	z   }
t        ||
z
  |z        dz   }t        j                  |      |z  |
z   | j                  z  }t        j                  t        j                  ||ddt        j                  f   d|| j                  z  dz        d      }||    }t        j                  ||g      }|j                  || j                  z  |j                         f        | j                   r| j#                  ||||      S |S )a\  
        Return the values and spacing of ticks to draw::

            [
                (spacing, [major ticks]),
                (spacing, [minor ticks]),
                ...
            ]

        By default, this method calls tickSpacing to determine the correct tick locations.
        This is a good method to override in subclasses.
        r   Nr   g{Gz?)rtolatolr   axis)sortedrD   r,  r   r   r   rc   r   ra   arangeanyisclosenewaxisconcatenater  tolistr@   logTickValues)rO   r  r  r   r  
tickLevels	allValuesispacingoffsetstartnumvaluesrp   s                 r[   
tickValueszAxisItem.tickValuesB  s      01 	$**$** %%ffd;
HHRL	s:' 	@A(mOGV 6&=G34w>&HE ve|w./!3Ciinw.6$**DF FF

9fQ

]&;!'RVR\R\J\]aJabE UF^F	6':;ILL'$**,fmmo>?%	@( <<%%ffdEBB r\   c           
         g }|D ]  \  }}|dk\  s|j                  ||f         t        |      dk  rt        t        |            }t        t	        |            }	g }
t        ||	      D ]=  }|
j                  |t        j                  t        j                  dd            z          ? |
D cg c]  }||kD  s	||k  s| }
}|j                  d |
f       |S c c}w )Nr/      r   r   )
r  rc   ra   r   r   r   extendr   r   r3  )rO   r  r  r   stdTicksr  r=  tv1v2r  vru   s                r[   r9  zAxisItem.logTickValues{  s    
 $ 	+LWa#~gq\*	+ u:>U6]#BT&\"B E2r] =Q"))Ar*:!;;<= %?16ahQ?E?LL$' @s   .
C9C?Cc           	         | j                   r| j                  |||      S t        dt        t	        ||z                     }g }|D ]B  }||z  }t        |      dk  st        |      dk\  rd|z  }nd|z  |z  }|j                  |       D |S )az  Return the strings that should be placed next to ticks. This method is called
        when redrawing the axis and is a good method to override in subclasses.
        The method is called with a list of tick values, a scaling factor (see below), and the
        spacing between ticks (this is required since, in some instances, there may be only
        one tick and thus no other way to determine the tick spacing)

        The scale argument is used when the axis label is displaying units which may have an SI scaling prefix.
        When determining the text to display, use value*scale to correctly account for this prefix.
        For example, if the axis label's units are set to 'V', then a tick value of 0.001 might
        be accompanied by a scale value of 1000. This indicates that the label is displaying 'mV', and
        thus the tick should display 0.001 * 1000 = 1.
        r   gMbP?i'  z%gz%%0.%df)r@   logTickStringsr   r   r   r   r  )	rO   rA  rD   r=  placesstringsrJ  vsvstrs	            r[   tickStringszAxisItem.tickStrings  s     <<&&vug>>QeGEM2234 	!AUB2w~RE!1by!F*b0NN4 	! r\   c                 $   dt        j                  |      j                  t              z  t        j                  |      z  D cg c]  }d|z  	 }}ddddddd	d
ddd
}g }|D ]  }|j	                  d      r||j                  d      \  }	}
|
d   dk(  rdnd}dj                  |
dd  j                  d      D cg c]  }||   	 c}      }|	dk(  rd}	n|	dz   }	|j                  |	dz   |z   |z          |j                  |        |S c c}w c c}w )Nr   z%0.1gu   ⁰   ¹   ²   ³u   ⁴u   ⁵u   ⁶u   ⁷u   ⁸u   ⁹)
0123456789er   -u   ⁻r   r   rV  rW     ·10)	r   r   astypefloatcountsplitr   lstripr  )rO   rA  rD   r=  ru   estringsconvdictdstringsr`  rJ  r   signpppots                 r[   rL  zAxisItem.logTickStrings  s!   ')RXXf-=-D-DU-K'KbhhW\o']^!GAI^^
  	#Awws|wws|1 !!uggaell36GHx|HI8ADAD4# 56"	# 3 _" Is   D8D
c           
      J   t        j                         }| j                  d   |j                  | j                  d          | j	                  | j                               }| j                         }|| j                  du r|}n |j                  | |j                               }d}d}d}d}	| j                  dk(  r`|j                         t        ||      z   |j                         t        ||	      z   f}
|j                         }|j                         }d}d}nU| j                  d	k(  r_|j                         t        ||      z   |j!                         t        ||	      z   f}
|j#                         }|j#                         }d
}d}n| j                  dk(  r_|j!                         t        ||      z   |j                         t        ||      z   f}
|j%                         }|j%                         }d}d
}ny| j                  dk(  r_|j                         t        ||	      z   |j                         t        ||	      z   f}
|j'                         }|j'                         }d
}d
}nt)        d      t+        t-        | j.                  |
            }d|v ryt        |d
   |d   z
        j1                         }|dk(  ry| j2                  0| j5                  | j6                  d   | j6                  d
   |      }d}nig }g }| j2                  D ]V  }g }g }|j9                  d|f       |j9                  |       |D ]'  \  }}|j9                  |       |j9                  |       ) X | j6                  d
   | j6                  d   z
  }|dk(  rd
}d}nb|dk(  r8|j;                          |z  }| j6                  d   |z  |j;                         z
  }n%|j=                         |z  }| j6                  d   |z  }| j6                  D cg c]
  }||z  |z
   }}t?        |      }tA        |      } |d       g }g } t7        tC        |            D ]h  }!|j9                  g        ||!   d
   }"| j                  d   |!dz  dz   z  }#| j                  d   }$|$Sd|!d
z   z  }$| j                  dur|$| j                  dz  tE        jF                  d|z  tC        |"      d
z   z  dd      z  z  }$ntI        |$tJ              rB|$dz  }$tA        dtM        tO        |$                  }$t?        dtM        tO        |$                  }$n0tI        |$tL              r|$dkD  s|$dk  rt)        d      tQ        d      | jS                         }%|%jU                         j                         tV        jX                  jZ                  j\                  k(  rct_        j`                  |%      }%t_        jb                  |%je                               }&|&jg                  tM        |$             |%ji                  |&       |"D ]  }'|'|z  |z
  }||k  s||kD  r||!   j9                  d       *||!   j9                  |       ||g}(||g})||(|<   ||)|<   | j                  du r|)|xx   |#|z  z  cc<   | j9                  |%t        |(      t        |)      f        k  |d       | j                  d   d   du rt?        t-        t>        |            }*|dk(  r2tA        |
d   jk                         |*      }+|
d   jm                  |+       n1tA        |
d   jo                         |*      }+|
d   jq                  |+       | j                  d   d
   du rtA        t-        t@        |            },|dk(  r2t?        |
d
   jk                         |,      }+|
d
   jm                  |+       n1t?        |
d
   jo                         |,      }+|
d
   jq                  |+       | js                         |
d   |
d
   f}-| j                  d   |   }.d}/d}0g }1g }2| j                  d   s|-| |2fS t7        t?        tC        |      | j                  d   d
z               D ]  }!|3||!   \  }3}| ju                  || jv                  | jx                  z  |3      }n||!   }tC        |      dk(  rMt7        tC        |            D ]  }4||!   |4   d||4<    g }5|D ]  }6|6|5j9                  d       |j                  tW        jz                  dddd      tV        jX                  j|                  j~                  |6      }7|7j                  |7j;                         dz         |5j9                  |7       |1j9                  |5d           tC        |1      dkD  r|dk(  rct        j                  |1D 8cg c]  }8|8j;                          c}8      }9t        j@                  |1D 8cg c]  }8|8j=                          c}8      }/ngt        j                  |1D 8cg c]  }8|8j=                          c}8      }9t        j@                  |1D 8cg c]  }8|8j;                          c}8      }/nd}9d}/|!dkD  rDtK        |9      |z  }:d};| j                  d    D ]  \  }<}=tC        |2      |<k\  s|:|=k\  sd}; n |;r n|/}0t7        tC        |            D ]  }4||4   }>|>||!   |4   }|5|4   }?|?j;                         }@|?j=                         }AtA        d| j                  d         |.z   }tW        jz                         }B| j                  dk(  rotV        jX                  j|                  j                  tV        jX                  j|                  j                  z  }CtW        jz                  ||z
  Az
  |@d!z  z
  |A|@      }Bnp| j                  d	k(  rktV        jX                  j|                  j                  tV        jX                  j|                  j                  z  }CtW        jz                  ||z   |@d!z  z
  A|@      }Bn| j                  dk(  rntV        jX                  j|                  j                  tV        jX                  j|                  j                  z  }CtW        jz                  |Ad"z  z
  ||z
  @z
  |A|@      }Bny| j                  dk(  rjtV        jX                  j|                  j                  tV        jX                  j|                  j                  z  }CtW        jz                  |Ad"z  z
  ||z   |A@      }BCtV        jX                  j                  j                  z  }D| j                         }7|7j                  B      s|2j9                  BD|>f          |d#       | j                  |0       |-| |2fS c c}w c c}8w c c}8w c c}8w c c}8w )$z
        Calls tickValues() and tickStrings() to determine where and how ticks should
        be drawn, then generates from this a set of drawing commands to be
        interpreted by drawPicture().
        r'   NFg      r/   r   r   r   r   r   r   r   z>self.orientation must be in ('left', 'right', 'top', 'bottom')initr+   g      ?r.      g     o@g?g        zlineAlpha should be [0..255]z/Line Alpha should be of type None, float or intzcompute ticksr(   Tr!   r*   r-   d   r   r)   r	   r~   zcompute text)Mr
   r   r7   r   r   r   r   rN   r   r   r4   topRightr   bottomRightr   topLeft
bottomLeftr   r   r   rb   listmapmapToDevicelengthrB   rB  r   r  r   r   r   r   rc   r   clip_scalarr`   re  ra   round	TypeErrorrR   brushr   Qt
BrushStyleSolidPatternr   QPenQColorr   setAlphasetColorrv   r   ru   r   rP   rQ  rF   rD   QRectFAlignmentFlagAlignCenterr   r   sum
AlignRightAlignVCenter	AlignLeftAlignHCenterAlignBottomAlignTopTextFlagTextDontClipcontainsr   )ErO   r   r  boundsr   
tickBoundsleft_offsetright_offset
top_offsetbottom_offsetspan	tickStarttickStoptickDirr1  pointslengthInPixelsr:  rQ  levelrA  rN  valstrnr  xScaler>  ru   xRangexMinxMaxtickPositions	tickSpecsr<  r  r+   	lineAlpharR   r   rJ  p1p2minTickPositionstopmaxTickPositionaxisSpec
textOffset	textSize2lastTextSize2	textRects	textSpecsr=  jrectsr   r   rtextSizetextFillRatiofinishednTextslimitrP  textRectr   r   r   
alignFlags	textFlagssE                                                                        r[   r  zAxisItem.generateDrawSpecs  sr    >>#::j!-IIdjj,-''8__&
e!3J#11$
8O8O8QRJ
v%OO%k:(FF&&(5m+LLND"((*I||~HGD(NN$u\:'FF%%'%m*LLND")I{{}HGD&%%'%Z*HH&&(5z+JJLD"))+I}}HGD)NN$u[-'HHOO%lM(JJLD"(Izz|HGD]^^ c$**D126>vay6!945<<>Q #A

1~VJK JK)) )!!4.1""7+!& )ICMM#&NN4()) jjmdjjm+!8FFqy --/)C/A/&--/A#-A//3zz:!!f*v%::6{6{ 	s:' *	BA  $qM!$E L1aeS[AJ

;/I 1Q3K	99E)4"..$.BX\_`e\fgh\hBilnpr2s!ssIIu-S 	3uY'7#89	Sy)9%:;	Is+OQ$%CDD QRRllnG}}$$&&))*>*>*K*KK**W-W]]_5s9~.  ' BZ6)t8q4x!!$++D1a ''*VV$4#499%tH
7 22H  '59eBi!@AB9*	BV 	! ::&'*d2!#c="9:Oqy4799;8QT"4799;8QT"::&'*d2!#c="9:Oqy4799;8QT"4799;8QT"HHJQa1 ZZ 01$7
 			 zz,'i33s3z?DJJ~,Fq,HIJ ^	:A"",Q-**643I3IDJJ3VX_`%a.7|q  3w<( & #A&.!%GAJ&
 E 
09LL&aC(EvyyG^G^GjGjlmnB LLs!23LL$$$U2Y/
0 9~!19!vv9&Eaqxxz&EFH "9'Ea	'E FI!vv)&DQqwwy&DEH "I'Fq
'F GI	1u !&h. @ %)ZZ0@%A MFE9~/MU4J#' %M
 3w<( ":qz<!!$Q' 8!* (Qtzz,78:E}}##v-!'!8!8!C!CFIID[D[DhDh!hJ!==&)>6!8eU[\D%%0!'!8!8!B!B699CZCZCgCg!gJ!==&!VAX,vVD%%.!'!8!8!E!EfiiF]F]FiFi!iJ!==58Xf_V5KUTZ[D%%1!'!8!8!E!EfiiF]F]FfFf!fJ!==58Xf_eVTD&););)H)HH	 &&({{4(  $	4!89E":y^	:~ 	  	.)Y//C ;| 'F'E&D'Fs   :vv
v
 v
1v 
c                    t        j                         }|j                  |j                  j                  d       |j                  |j                  j
                  d       |\  }}}|j                  |       |j                  ||       |D ])  \  }}}|j                  |       |j                  ||       +  |d       | j                  d   |j                  | j                  d          |j                  | j                                | j                         j                         }	|j                  |	       |D ]"  \  }
}}|j                  |
t        |      |       $  |d       y )NFTz
draw ticksr'   z	draw text)r
   r   setRenderHint
RenderHintAntialiasingTextAntialiasingrI   drawLiner7   r   rQ   r   toAlignedRectsetClipRectdrawTextra   )rO   r   r  r  r  r  rP   r  r  boundingr   flagsrV   s                r[   r  zAxisItem.drawPicture  s-   >>#	1159	55t< R		

2r % 	KCRHHSMJJr2	 	 ::j!-IIdjj,-	 $$&446	h!* 	/D%JJtSZ.	/ 	r\   c                     t        j                  |        | j                  dv r| j                          y | j	                          y r   )r   r   r4   r   r   ro   s    r[   r   zAxisItem.show  7    D!00 r\   c                     t        j                  |        | j                  dv r| j                          y | j	                          y r   )r   hider4   r   r   ro   s    r[   r  zAxisItem.hide
  r  r\   c                 0   | j                         }|y |j                         j                  |j                               r|j	                          y | j
                  dv r|j                  |d       n|j                  |d       |j                          y Nr   r   r0  r   )r   sceneBoundingRectr  scenePosignorer4   
wheelEventacceptrO   eventlvs      r[   r  zAxisItem.wheelEvent  sz    __:!**5>>+;<LLN #44e!,e!,r\   c                    | j                         }|y |j                         j                  |j                               r|j	                          y | j
                  dv r|j                  |d      S |j                  |d      S r  )r   r  r  buttonDownScenePosr  r4   mouseDragEventr  s      r[   r  zAxisItem.mouseDragEvent!  s}    __:!**5+C+C+EFLLN00$$U$33$$U$33r\   c                 J    | j                         }|y |j                  |      S rl   )r   mouseClickEventr  s      r[   r  zAxisItem.mouseClickEvent/  s'    __:!!%((r\   )
NNNNNTr   r   r   rl   )T)NNN)r/   )5__name__
__module____qualname____doc__r0   rj   rp   rs   rx   r|   r   rG   r   r   r   r   re   r   r   r   r   rP   rI   rQ   rJ   rR   rK   r   r   r   rH   r   rM   r   r   r   r   r
  r  r  r  r,  rB  r9  rQ  rL  r  r  r   r  r  r  r  r  r\   r[   r   r      s	   fTM^&
	$L
4	&#J9%4!,,#
'
+
 "$"&
8(B) w<*$>Tn7r,68\0|:!! 4)r\   )r   mathr   r   r   r   r   r   numpyr   r   r
   r   r   r   r   r  r   r   r   r   __all__r   r  r\   r[   <module>r     s>     A A A      ) ) *,e)~ e)r\   