
    Le0                     J   d dl Zd dlZd dl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mZ dd	lmZmZ dd
lmZ  G d de	          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d d e          Z! G d! d"e          Z" G d# d$e"          Z# G d% d&e"          Z$ G d' d(e"          Z% G d) d*e"          Z&dS )+    N)patches)Line2D   )abbreviated_exception)
match_spec)HLinesHSpansVLinesVSpans   )ColorbarPlotElementPlot)mpl_rc_contextc                   (     e Zd ZdZ fdZd Z xZS )ABLine2Dz
    Draw a line based on its slope and y-intercept. Additional arguments are
    passed to the <matplotlib.lines.Line2D> constructor.
    c                    |d         } t                      j        g g g|R i | || _        || _        |                    |            |j        j                                         |                     d            | j	        j
                            d| j                   | j	        j
                            d| j                   d S )Naxesxlim_changedylim_changed)super__init___slope
_interceptadd_linefigurecanvasdraw_update_limr   	callbacksconnect)selfslope	interceptargskwargsax	__class__s         Alib/python3.11/site-packages/holoviews/plotting/mpl/annotation.pyr   zABLine2D.__init__   s    F^ 	R1$111&111#
D 		 		##ND4DEEE	##ND4DEEEEE    c                     t          j        | j                                                  }| j        |z  | j        z   }|                     ||           | j                            |            dS )z( called whenever axis x/y limits change N)nparrayr   
get_xboundr   r   set_datadraw_artist)r!   eventxys       r(   r   zABLine2D._update_lim'   sa    HTY))++,,[1_/a	d#####r)   )__name__
__module____qualname____doc__r   r   __classcell__r'   s   @r(   r   r      sV         
F F F F F"$ $ $ $ $ $ $r)   r   c                   d     e Zd ZdZ ej        dd          Z fdZed	d            Z	d Z
 xZS )
AnnotationPlotzH
    AnnotationPlot handles the display of all annotation elements.
    Fz-
        Whether to show legend for the plot.defaultdocc                 ^    || _          t                      j        |fi | g | j        d<   d S Nannotations)_annotationr   r   handles)r!   
annotationparamsr'   s      r(   r   zAnnotationPlot.__init__7   s<    %..v...&(]###r)   Nc                    | j         j        }| j        d         }|                     | j         ||          }t	          ||          }| j        d         }| j        | j                 }t                      5  | 	                    ||j
        |          }d d d            n# 1 swxY w Y   || j        d<   |                     |||          S )Naxisr@   )elementranges)hmaplastkeyscompute_rangesr   rB   stylecyclic_indexr   draw_annotationdata_finalize_axis)r!   rI   rC   keyrG   optsrB   s          r(   initialize_plotzAnnotationPlot.initialize_plot<   s   Y^
im$$TYV<<J//|F#z$+,"$$ 	H 	H**4$GGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H&-]#""3
6"JJJs   3BB #B c                     | j         d         D ]}|                                 t                      5  |                     ||j        |          | j         d<   d d d            d S # 1 swxY w Y   d S r?   )rB   remover   rP   rQ   )r!   rS   rG   rC   rI   rN   rH   s          r(   update_handleszAnnotationPlot.update_handlesI   s    |M2 	 	GNN"$$ 	] 	]*.*>*>tZ_V[*\*\DL'	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	] 	]s   %A%%A),A)N)r3   r4   r5   r6   paramBooleanshow_legendr   r   rU   rX   r7   r8   s   @r(   r:   r:   /   s           %- 40 1 1 1K) ) ) ) )
 
K 
K 
K ^
K] ] ] ] ] ] ]r)   r:   c                        e Zd ZdZg dZd ZdS )	VLinePlotz Draw a vertical line on the axisalphacolor	linewidth	linestylevisiblec                 L    | j         r |j        |fi |gS  |j        |fi |gS rY   )invert_axesaxhlineaxvliner!   rG   positionrT   s       r(   rP   zVLinePlot.draw_annotationW   sG     	4 DL22T2233 DL22T2233r)   Nr3   r4   r5   r6   
style_optsrP    r)   r(   r^   r^   R   s4        &&HHHJ4 4 4 4 4r)   r^   c                        e Zd ZdZg dZd ZdS )	HLinePlot"Draw a horizontal line on the axisr_   c                 L    | j         r |j        |fi |gS  |j        |fi |gS )rp   )rf   rh   rg   ri   s       r(   rP   zHLinePlot.draw_annotationc   sG     	4 DL22T2233 DL22T2233r)   Nrk   rm   r)   r(   ro   ro   ^   s4        ((HHHJ4 4 4 4 4r)   ro   c                        e Zd ZdZg dZd ZdS )	VSpanPlot Draw a vertical span on the axisr`   ra   	facecolor	edgecolorrb   rc   rd   c                 H    | j         r |j        |i |gS  |j        |i |gS )rt   )rf   axhspanaxvspanr!   rG   	positionsrT   s       r(   rP   zVSpanPlot.draw_annotationq   A     	6 DL)4t4455 DL)4t4455r)   Nrk   rm   r)   r(   rs   rs   k   s:        &&7 7 7J6 6 6 6 6r)   rs   c                        e Zd ZdZg dZd ZdS )	HSpanPlot"Draw a horizontal span on the axisru   c                 H    | j         r |j        |i |gS  |j        |i |gS )r   )rf   rz   ry   r{   s       r(   rP   zHSpanPlot.draw_annotation   r}   r)   Nrk   rm   r)   r(   r   r   y   s:        ((7 7 7J6 6 6 6 6r)   r   c                       e Zd Zg dZd ZdS )	SlopePlotr_   c                     |\  }}| j         r*|dk    rt          j        t          j        f}nd|z  ||z   }}t          |d|i|}|gS )rp   r   r   r   )rf   r+   infr   )r!   rG   rj   rT   gradientr#   artists          r(   rP   zSlopePlot.draw_annotation   sc    &) 	H1}}626>&'jIh4F2G)87$7$77xr)   N)r3   r4   r5   rl   rP   rm   r)   r(   r   r      s.        HHHJ	 	 	 	 	r)   r   c                        e Zd ZdZg dZd ZdS )TextPlotzDraw the Text annotation object)r`   ra   familyweightrd   c                 `    |\  }}}}}}	}
| j         r||}}||d<    |j        |||f||	|
d|gS )Nfontsize)horizontalalignmentverticalalignmentrotation)rf   text)r!   rG   rQ   rT   r1   r2   r   r   r   r   r   s              r(   rP   zTextPlot.draw_annotation   ss    =A	;1dH	/(AqQ#Z	!At 50C.?#+5 5 045 5 6 	6r)   Nrk   rm   r)   r(   r   r      s4        %%BBBJ6 6 6 6 6r)   r   c                       e Zd Z ej        deefdd          Z ej        dd          Z	 ej        dd          Z
g dZdgZ ed	
          Zd Zd Zd ZdS )
LabelsPlotNTzA
      Index of the dimension from which the color will the drawn)r<   class_
allow_Noner=   z8
      Amount of offset to apply to labels along x-axis.r;   )
r`   ra   r   r   sizerd   r   r   cmapr   r   annotate)singlec                   
 t                      5  |                     ||          }d d d            n# 1 swxY w Y   fdt          d          D             \  }}                    d          

fd                    
          D             }| j        r||fn||f}| j        
|| j        z  }| j        
|| j        z  }d }                    | j                  }	|	r-| 	                    |||	                               |	          }d|v r|
                    d          }d|v r|
                    d          |d<   d|vrd|d<   d	|vrd|d	<   |||fz   |i fS )
Nc              3   B   K   | ]}                     |          V  d S rY   )dimension_values).0irH   s     r(   	<genexpr>z&LabelsPlot.get_data.<locals>.<genexpr>   s1      @@!'**1--@@@@@@r)      c                 :    g | ]}                     |          S rm   )pprint_value)r   vtdims     r(   
<listcomp>z'LabelsPlot.get_data.<locals>.<listcomp>   s'    MMM!!!$$MMMr)   cr   r   r   centerr   )r   _apply_transformsrangeget_dimensionr   rf   xoffsetyoffsetcolor_index_norm_kwargspop)r!   rH   rI   rN   xsysr   r|   cscdimr   s    `        @r(   get_datazLabelsPlot.get_data   s   "$$ 	C 	C**7FEBBE	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C A@@@uQxx@@@B$$Q''MMMMg.F.Ft.L.LMMM $ 0>RHHr2h	<#$,B<#$,B$$T%566 	0gvud;;;))$//B%<<3BU??		&0A0AE*- --hu5J/Ke++(U3F-GD":%ub00s   599c                 0   |d         h|                     dd           }t          t          j        |d                             }|                     d          |                     d          }}nd }|d d         }d |                                D             }g }	t          t          |           D ]\  }
|
d d         \  }}}t          |
          dk    rk|i|
d         }|d         j        j	        dv r||z
  ||z
  z  } ||          |d	<   n3||v r|
                    |          nt          j        } ||          |d	<   t          |fi fd
|                                D             }|	                     |j        |||fi |           d|	iS )NrF   r   vminvmaxc                 N    i | ]"\  }}t          |t          j                  ||#S rm   )
isinstancer+   ndarray)r   kr   s      r(   
<dictcomp>z+LabelsPlot.init_artists.<locals>.<dictcomp>   s/    XXXtq!jBJ>W>WXaXXXr)   r      ifra   c                 (    i | ]\  }}||         S rm   rm   )r   r   r   r   s      r(   r   z+LabelsPlot.init_artists.<locals>.<dictcomp>   s#    )Q)Q)Qda!QqT)Q)Q)Qr)   r   )r   listr+   uniqueitems	enumerateziplendtypekindindexnandictappendr   )r!   r&   	plot_argsplot_kwargsr   colorsr   r   
vectorizedtextsitemr1   r2   r   ra   r%   r   s                   @r(   init_artistszLabelsPlot.init_artists   s   R=$??6400D")IbM2233F$00+//&2I2I$DDD!#2#IXX{'8'8':':XXX
 i11 	8 	8GAtbqbJAq$4yyA~~$"2QR=&+t33"T\d4i8E+/4;;K((38F??FLL///E+/4;;K(+RR)Q)Q)Q)Qj>N>N>P>P)Q)Q)QRRFLLAt66v667777%  r)   c                 d    d| j         v r$| j         d         D ]}|                                 d S d S )Nr   )rB   rW   )r!   r   s     r(   teardown_handleszLabelsPlot.teardown_handles   sF    t|##,x0     $#   r)   )r3   r4   r5   rZ   ClassSelectorstrintr   Numberr   r   rl   _nonvectorized_stylesr   _plot_methodsr   r   r   rm   r)   r(   r   r      s        %%%dC:15 <DE E EK el4 .; < < <G el4 .; < < <GR R RJ $HD
+++M1 1 14! ! !4         r)   r   c                   f    e Zd ZdZg dZej        ddgz   Z e e	eez                       Zd Z
dS )	ArrowPlotzDDraw an arrow using the information supplied to the Arrow annotation)r`   ra   lwrb   rd   textsizer   c           
         |\  }}}}}}	| j         r||}}|                                }t          d|	ifi fd| j        D             }
fd| j        D             }|dv rd|dk    r|n| f}n|dv r|dk    r|n| df}d	|v r| j                            d
           d|v r|                    d          |d	<    |j        |f||fd|dd|
d|gS )N
arrowstylec                 *    i | ]}|v ||         S rm   rm   r   r   rT   s     r(   r   z-ArrowPlot.draw_annotation.<locals>.<dictcomp>  s%    UUUA1PT99QQ999r)   c                 *    i | ]}|v ||         S rm   rm   r   s     r(   r   z-ArrowPlot.draw_annotation.<locals>.<dictcomp>  s$    KKK1dAtAwr)   )r   ^r   r   )><r   r   zGArrow fontsize style option is deprecated, use textsize option instead.r   zoffset pointsr   )xy
textcoordsxytexthava
arrowprops)	rf   lowerr   _arrow_style_opts_text_style_optsrZ   warningr   r   )r!   rG   rQ   rT   r1   r2   r   	directionpointsr   r   textoptsr   s      `         r(   rP   zArrowPlot.draw_annotation   sj   4811dIvz(AqQOO%%	<
3 W WUUUU1GUUUW W
KKKK(=KKK
""9c>>w?FF*$$ )3ffVGQ?F!!J  > ? ? ?!!#+<<
#;#;HZ d A1v/%+X)3A A7?A A B 	Br)   N)r3   r4   r5   r6   r   r   rl   r   sortedsetrP   rm   r)   r(   r   r      sm        JJHHH*j*-EE-0@@AABBJB B B B Br)   r   c                        e Zd ZdZg dZd ZdS )
SplinePlotz:Draw the supplied Spline annotation (see Spline docstring))r`   rw   rb   rc   rd   c                     |\  }}t          |          sg S t          j        t          j                            ||          fddi|}|                    |           |gS )Nrv   none)r   r   	PathPatchmplpathPath	add_patch)r!   rG   rQ   rT   vertscodespatchs          r(   rP   zSplinePlot.draw_annotation  sp    u5zz 	I!#(--u"="= < <,2<6:< <uwr)   Nrk   rm   r)   r(   r   r     s4        @@LLLJ    r)   r   c                   ^     e Zd Z ej        dd          Zg dZd Zd
 fd	Zd fd		Z	 xZ
S )_SyntheticAnnotationPlotTzF
        Whether to include the annotation in axis range calculations.r;   ru   c                 4   t          t          j                  r}nJt          | j        j        j                  }t                    d |         }t          fd|D              }t          || j
        | j                           fd|D             S )Nc                      g | ]
}|         S rm   rm   )r   nr|   s     r(   r   z<_SyntheticAnnotationPlot.draw_annotation.<locals>.<listcomp>0  s    <<<A9Q<<<<r)   c                      g | ]
} |i S rm   rm   )r   valfnrT   s     r(   r   z<_SyntheticAnnotationPlot.draw_annotation.<locals>.<listcomp>2  s(    333SC 4  333r)   )r   r+   r   r   rJ   rK   kdimsr   r   getattr_methodsrf   )r!   rG   r|   rT   valuesr   
first_keysr	  s     ``   @r(   rP   z(_SyntheticAnnotationPlot.draw_annotation*  s    i,, 	>FFty~+,,Di$/J<<<<<<<=FT4=)9:;;33333F3333r)   Ncombinedc                    t                                          |||          }t          |t                    r(t          j        |d         t          j        |d         f}n+t          |t                    r'|d         t          j        |d         t          j        f}nt          |t                    rct          j	        |          }t          j        |d d         
                                t          j        |dd                                          f}nwt          |t                    rbt          j	        |          }|d d         
                                t          j        |dd                                          t          j        f}|S )Nr   r   )r   get_extentsr   r   r+   r   r
   r	   pdr,   minmaxr   )r!   rH   rI   
range_typer%   extentsr'   s         r(   r  z$_SyntheticAnnotationPlot.get_extents4  s3   ''%%gvzBBgv&& 		Kfgaj"&'!*<GG(( 	Kaj"&'!*bf<GG(( 	Khw''Gfgbqbkoo//9J9JJGG(( 	Khw''Gbqbkoo''1B1BBFJGr)   c                    t                                          |          }| j        rdnd}t          |t          j        j                  r7|                    |d                    |                    |d                    nL|j        d                             |d                    |j        d                             |d                    |S )N)rI   yxr   r   r   )	r   rU   rf   r   r   r   Axes
set_xlabel
set_ylabel)r!   rI   r   labelsr'   s       r(   rU   z(_SyntheticAnnotationPlot.initialize_plotB  s    (((77)3tfchm,, 	1fQi(((fQi((((KN%%fQi000KN%%fQi000r)   )Nr  rY   )r3   r4   r5   rZ   r[   apply_rangesrl   rP   r  rU   r7   r8   s   @r(   r  r  "  s         5= 4I J J JL7 7 7J4 4 4     	 	 	 	 	 	 	 	 	 	r)   r  c                       e Zd ZdZdS )HLinesAnnotationPlot)rg   rh   Nr3   r4   r5   r  rm   r)   r(   r  r  N          %HHHr)   r  c                       e Zd ZdZdS )VLinesAnnotationPlot)rh   rg   Nr   rm   r)   r(   r#  r#  R  r!  r)   r#  c                       e Zd ZdZdS )HSpansAnnotationPlot)ry   rz   Nr   rm   r)   r(   r%  r%  V  r!  r)   r%  c                       e Zd ZdZdS )VSpansAnnotationPlot)rz   ry   Nr   rm   r)   r(   r'  r'  Z  r!  r)   r'  )'
matplotlibr   numpyr+   pandasr  rZ   r   matplotlib.linesr   core.optionsr   	core.utilr   rH   r   r	   r
   r   r   r   plotr   r   r:   r^   ro   rs   r   r   r   r   r   r   r  r  r#  r%  r'  rm   r)   r(   <module>r/     s                      # # # # # # 1 1 1 1 1 1 # # # # # # 5 5 5 5 5 5 5 5 5 5 5 5 . . . . . . . .            $ $ $ $ $v $ $ $@ ]  ]  ]  ]  ][  ]  ]  ]F	4 	4 	4 	4 	4 	4 	4 	4
4 
4 
4 
4 
4 
4 
4 
46 6 6 6 6 6 6 66 6 6 6 6 6 6 6        6 6 6 6 6~ 6 6 6 J  J  J  J  J  J  J  J ZB B B B B B B B<        ) ) ) ) )~ ) ) )X& & & & &3 & & && & & & &3 & & && & & & &3 & & && & & & &3 & & & & &r)   