
    eW4                         d dl Zd dlmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZ ddlmZ dd	lmZmZ  G d
 de          ZdS )    N)CategoricalColorMapper
LinearAxisLinearColorMapper)	NdOverlayOverlay)Bars)property_to_dict   )ParamLogStream   )TestBokehPlotbokeh_rendererc                       e 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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S )TestBarPlotc                     t          t          j                            dd          dg          }|                    dg          }|                     |ddg           d S )	N
   r
   Dim with spaces)kdimshovertoolsr   z@{Dim_with_spaces})yz@{y}r   nprandomrandopts_test_hover_infoselfobjs     Klib/python3.11/site-packages/holoviews/tests/plotting/bokeh/test_barplot.py&test_bars_hover_ensure_kdims_sanitizedz2TestBarPlot.test_bars_hover_ensure_kdims_sanitized   s_    29>>"Q''0A/BCCChhgYh''c$M}#]^^^^^    c                     t          t          j                            dd          dg          }|                    dg          }|                     |ddg           d S )	Nr   r
   r   vdimsr   r   )xz@{x}r   r   r    s     r#   &test_bars_hover_ensure_vdims_sanitizedz2TestBarPlot.test_bars_hover_ensure_vdims_sanitized   s_    29>>"Q''0A/BCCChhgYh''cM3\#]^^^^^r%   c                     t          ddg                              d          }t          j        |          }|                                 |j        }|                     t          |j                  d           d S )NAr   Br
   F)show_legendr   )	r   r   r   get_plotinitialize_plotstateassertEquallenlegend)r!   barsplotfigs       r#   test_bars_suppress_legendz%TestBarPlot.test_bars_suppress_legend   sr    Xx())..5.AA&t,,jSZ!,,,,,r%   c                    t          g ddgdg          }t          j        |          }|                                 |j        d         }|j                                        D ]%}|                     t          |          d           &d S )Nr)   r   zr   r(   sourcer   )	r   r   r1   r2   handlesdatavaluesr4   r5   )r!   r7   r8   r>   vs        r#   test_empty_barszTestBarPlot.test_empty_bars   s    BsCj666&t,,h'##%% 	( 	(ASVVQ''''	( 	(r%   c                    t          g dddgdg          }t          j        |          }|j        d         }|                     d |j        d         D             g d	           |                     t          |j        d                   g d
           |                     |j        d         t          j        g d                     |j        d         }|                     |j	        g d           d S )N)r-   r   r   )r-   r   )r/   r   r
   IndexCategoryValuer=   r>   c                 ,    g | ]}t          |          S  )tuple).0r)   s     r#   
<listcomp>z<TestBarPlot.test_bars_grouped_categories.<locals>.<listcomp>,   s    DDDq%((DDDr%   xoffsets)r-   0r/   rQ   r-   1)rQ   rQ   rT   )r   r
   rF   x_range)rP   rS   rR   r/   rT   )
r   r   r1   r?   r4   r@   listr   arrayfactors)r!   r7   r8   r>   rU   s        r#   test_bars_grouped_categoriesz(TestBarPlot.test_bars_grouped_categories'   s   <<<"J/yB B B&t,,h'DDFK
,CDDD===	? 	? 	?fk*566HHHW-rx


/C/CDDD,y)*Z*Z*Z[[[[[r%   c                 8   t          ddgdz  g ddz  t          j                            d          fddgd	                              t          j        
          }t          j        |          }|j        d         }| 	                    |j
        g d           d S )Nr-   r/         r   r   r      GrouprH   rI   functionrU   )rS   )r-   3)r-   10rV   )r/   rc   )r/   rd   r   r   r   randn	aggregatemeanr   r1   r?   r4   rY   r!   boxr8   rU   s       r#   test_bars_multi_level_sortedz(TestBarPlot.test_bars_multi_level_sorted3   s    C:b=***R-1D1DEJ'2 22;)RW)2M2M 	&s++,y) +V +V +V 	W 	W 	W 	W 	Wr%   c                 8   t          g ddz  ddgdz  t          j                            d          fddgd	                              t          j        
          }t          j        |          }|j        d         }| 	                    |j
        g d           d S )Nr]   r   r-   r/   r\   r_   r`   rH   rI   ra   rU   ))rT   r-   )rT   r/   )rc   r-   )rc   r/   )rd   r-   )rd   r/   re   ri   s       r#   4test_box_whisker_multi_level_sorted_alphanumericallyz@TestBarPlot.test_box_whisker_multi_level_sorted_alphanumerically;   s    :::b=3*R-1D1DEJ'2 22;)RW)2M2M 	&s++,y) +V +V +V 	W 	W 	W 	W 	Wr%   c                 b   t          g ddz  ddgdz  t          j                            d          fddgd	                              t          j        
          }t          |g          }t          j        |          }|j	        d         j
        d         }t          |t                    sJ d S )N)rT   2rc   r   r-   r/   r\   r_   r`   rH   rI   ra   r8   r   )r   r   r   rf   rg   rh   r   r   r1   r?   left
isinstancer   )r!   rj   overlayr8   	left_axiss        r#   ,test_bars_multi_level_two_factors_in_overlayz8TestBarPlot.test_bars_multi_level_two_factors_in_overlayC   s    ???2%Sz"}bioob6I6IJJ'2 22;)RW)2M2M 	3%..&w//L(-a0	)Z0000000r%   c                 2   t          g dddgdg          }t          j        |                    d                    }|j        d         }|                     t          |j        d                   g d	           |                     t          |j        d                   g d
           |                     |j        d         t          j	        g d                     |                     |j        d         t          j	        g d                     d S )NrE   rG   rH   rI   r=   T)stackedr>   )rT   rQ   rQ   )r-   r-   r/   topr   r   r
   bottom)rF   r   r   )
r   r   r1   r   r?   r4   rW   r@   r   rX   )r!   r7   r8   r>   s       r#   !test_bars_positive_negative_mixedz-TestBarPlot.test_bars_positive_negative_mixedL   s   <<<"J/yB B B&tyyy'>'>??h'fk*566HHHfk'233___EEEU+RXiii-@-@AAAX.0D0DEEEEEr%   c                 <   t          g ddgdg          }t          j        |                    d                    }|j        d         }|j        d         }|j        d	         }|                     t          |j        d                   g d
           |                     |j        d         t          j	        g d                     |                     |j
        d           |                     |j        d           |                     |j        d           d S )Nr,   r.   )Cr^   rG   rI   r=   Tlogyr>   glyphy_ranger-   r/   r}   r   r
   r^   {Gz?u
@)r   r   r1   r   r?   r4   rW   r@   r   rX   ry   startendr!   r7   r8   r>   r   r   s         r#   test_bars_logyzTestBarPlot.test_bars_logyV   s   222")G96 6 6&tyydy';';<<h'W%,y)fk'233___EEEW-rx			/B/BCCCt,,,---&788888r%   c                 n   t          g ddgdg          j                            d          }t          j        |                    d                    }|j        d	         }|j        d
         }|j        d         }|                     t          |j	        d                   g d           |                     |j	        d         t          j        g d                     |                     |j        d           |                     |j        d           |                     |j        d           d S )Nr|   rG   rI   r=   )MbP?r^   )rI   Tr~   r>   r   r   r   r   r   r^   )r   redimranger   r1   r   r?   r4   rW   r@   r   rX   ry   r   r   r   s         r#   test_bars_logy_explicit_rangez)TestBarPlot.test_bars_logy_explicit_rangec   s    222")G96 6 66;EE
E<S<S 	&tyydy';';<<h'W%,y)fk'233___EEEW-rx			/B/BCCCu---...a(((((r%   c                     t          g d                              d          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )Nr   )r      )ylimr   r   r   r   r   r   r1   r?   r4   r   r   r!   r7   r8   r   s       r#   test_bars_ylimzTestBarPlot.test_bars_ylimp   st    III###22&t,,,y)***c*****r%   c                     t          g d                              d          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )N)r   r
   r
   rF   r^   r^   皙?paddingr   gffffffg333333@r   r!   pointsr8   r   s       r#   test_bars_padding_squarez$TestBarPlot.test_bars_padding_squarew   sy    ///0055c5BB&v..,y)---c*****r%   c                     t          g d                              d          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )Nr   )r
   r   r   r   r   r   r   皙	@r   r   s       r#   !test_bars_padding_square_positivez-TestBarPlot.test_bars_padding_square_positive~   sy    ...//44S4AA&v..,y)***c*****r%   c                     t          g d                              d          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )N))r   r   )r^   r   r   r   g	r   r   r   s       r#   !test_bars_padding_square_negativez-TestBarPlot.test_bars_padding_square_negative   sy    11122777DD&v..,y)---a(((((r%   c                     t          g d                              dd          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )Nr   r   iX  )r   widthr   r   r   r   r   s       r#   test_bars_padding_nonsquarez'TestBarPlot.test_bars_padding_nonsquare   s{    ,,,--223c2JJ&t,,,y)***c*****r%   c                     t          g d                              dd          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )N))r   r   )r
   r
   r   r   T)r   logxr   r   r   r   r   s       r#   test_bars_padding_logxz"TestBarPlot.test_bars_padding_logx   s{    +++,,11#D1II&t,,,y)***c*****r%   c                     t          g d                              dd          }t          j        |          }|j        d         }|                     |j        d           |                     |j        d           d S )Nr   r   T)r   r   r   r   r   r   r   s       r#   test_bars_padding_logyz"TestBarPlot.test_bars_padding_logy   s|    ,,,--223T2JJ&t,,,y)---&899999r%   c                    t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d                     |                     t          |j
                  d	di           |                     t          |j                  d
           d S )N)r   r   #000)r   r   #F00)r   r
   #0F0r   colorr'   r   cdsr   r   r   r   fieldblack)r   r   r   r1   r?   r4   r@   r   rX   r	   
fill_color
line_colorr!   r7   r8   r   r   s        r#   test_bars_color_opzTestBarPlot.test_bars_color_op   s    DDD%('N4 4 448DwD4G4G 	&t,,l5!W%'*BH5M5M5M,N,NOOO)%*:;;gw=OPPP)%*:;;WEEEEEr%   c                    t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|j        d         }|                     |t                     |                     |j        d	           |                     |j	        d
           |                     |j
        d         t          j        g d                     |                     t          |j                  d|d           |                     t          |j                  d           d S )Nr   r   r   )r   r   r   )r   r
   r
   r   r   r'   r   r   r   color_color_mapperr   r
   rx   r   	transformr   )r   r   r   r1   r?   
assertTruer   r4   lowhighr@   r   rX   r	   r   r   r!   r7   r8   r   r   cmappers         r#   test_bars_linear_color_opz%TestBarPlot.test_bars_linear_color_op   s0   555%('N4 4 448DwD4G4G 	&t,,l5!W%,34!2333a(((q)))'*BHYYY,?,?@@@)%*:;;w]d=e=efff)%*:;;WEEEEEr%   c                 N   t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|j        d         }|                     |t                     |                     |j        g d	           |                     |j	        d         t          j        g d	                     |                     t          |j                  d|d
           |                     t          |j                  d           d S )N))r   r   r-   )r   r   r/   )r   r
   r}   r   r   r'   r   r   r   r   r   r   r   )r   r   r   r1   r?   r   r   r4   rY   r@   r   rX   r	   r   r   r   s         r#   test_bars_categorical_color_opz*TestBarPlot.test_bars_categorical_color_op   s   ;;;%('N4 4 448DwD4G4G 	&t,,l5!W%,34!7888///:::'*BH___,E,EFFF)%*:;;w]d=e=efff)%*:;;WEEEEEr%   c                    t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d	                     | 	                    t          |j                  d
di           |                     t          |j                  d
di           d S )Nr   r   r   r'   )r   r   r   r   r   r   )r   r   r   r1   r?   r4   r@   r   rX   assertNotEqualr	   r   r   r   s        r#   test_bars_line_color_opz#TestBarPlot.test_bars_line_color_op   s    DDD%('N4 4 448DGD4L4L 	&t,,l5!W%,/:R:R:R1S1STTT,U-=>>,@WXXX)%*:;;g|=TUUUUUr%   c                    t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d	                     |                     t          |j
                  d
di           |                     t          |j                  d
di           d S )Nr   r   r   r'   r   r   r   r   r   r   )r   r   r   r1   r?   r4   r@   r   rX   r	   r   r   r   r   s        r#   test_bars_fill_color_opz#TestBarPlot.test_bars_fill_color_op   s    DDD%('N4 4 448DGD4L4L 	&t,,l5!W%,/:R:R:R1S1STTT)%*:;;g|=TUUU,U-=>>,@WXXXXXr%   c                 r   t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d                     |                     t          |j
                  d	di           d S )
Nr   )r   r   皙?)r   r
   ffffff?r   alphar'   )r   r   r   r   r   r   r   )r   r   r   r1   r?   r4   r@   r   rX   r	   
fill_alphar   s        r#   test_bars_alpha_opzTestBarPlot.test_bars_alpha_op   s    999%('N4 4 448DwD4G4G 	&t,,l5!W%'*BH]]],C,CDDD)%*:;;gw=OPPPPPr%   c                    t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d	                     |                     t          |j
                  d
di           |                     t          |j                  d
di           d S )Nr   r   r   r'   )
line_alphar   r   r   r   r   )r   r   r   r1   r?   r4   r@   r   rX   r	   r   r   r   r   s        r#   test_bars_line_alpha_opz#TestBarPlot.test_bars_line_alpha_op   s    999%('N4 4 448DGD4L4L 	&t,,l5!W%,/---1H1HIII)%*:;;g|=TUUU,U-=>>,@WXXXXXr%   c                    t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d	                     | 	                    t          |j                  d
di           |                     t          |j                  d
di           d S )Nr   r   r   r'   )r   r   r   r   r   r   )r   r   r   r1   r?   r4   r@   r   rX   r   r	   r   r   r   s        r#   test_bars_fill_alpha_opz#TestBarPlot.test_bars_fill_alpha_op   s    999%('N4 4 448DGD4L4L 	&t,,l5!W%,/---1H1HIII,U-=>>,@WXXX)%*:;;g|=TUUUUUr%   c                 r   t          g dddg                              d          }t          j        |          }|j        d         }|j        d         }|                     |j        d         t          j        g d                     |                     t          |j
                  d	di           d S )
N))r   r   r   )r   r      )r   r
      r   
line_widthr'   )r   r   r   )r   r   r   r   )r   r   r   r1   r?   r4   r@   r   rX   r	   r   r   s        r#   test_bars_line_width_opz#TestBarPlot.test_bars_line_width_op   s    555%(,$79 9 99=9V9V 	&t,,l5!W%,/)))1D1DEEE)%*:;;g|=TUUUUUr%   c                 T   ddg}t          d t          |          D             d                              dd          }t          j        |          }t          |j                                        |          D ]+\  }}|                     |j	        d         j
        |           ,d S )Nblueredc           	      ^    i | ]*\  }}|t          t          j        |d z                       +S )r
   )r   r   arange)rM   ir   s      r#   
<dictcomp>z7TestBarPlot.test_op_ndoverlay_value.<locals>.<dictcomp>  s2    [[[XQUD1Q3$8$8[[[r%   Colorr   r   r   )r   	enumerater   r   r1   zipsubplotsrA   r4   r?   r   )r!   colorsrr   r8   subplotr   s         r#   test_op_ndoverlay_valuez#TestBarPlot.test_op_ndoverlay_value  s    %[[SYIZIZ[[[]deejjkq  Fj  G  G&w//!$-"6"6"8"86BB 	I 	INGUW_W5@%HHHH	I 	Ir%   c                 0   t          g dddg                              dd          }t                      5 }t          j        |           d d d            n# 1 swxY w Y   |j                                        }d}|                     ||           d S )Nr   r   r   r'   )r   color_indexzThe `color_index` parameter is deprecated in favor of color style mapping, e.g. `color=dim('color')` or `line_color=dim('color')`
Cannot declare style mapping for 'color' option and declare a color_index; ignoring the color_index.
)r   r   r   r   r1   streamreadr4   )r!   r7   loglog_msgwarnings        r#   !test_bars_color_index_color_clashz-TestBarPlot.test_bars_color_index_color_clash  s    555.* * **.$W'$*R*R 	 	*#D)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	**//##` 	
 	'*****s   AA!AN) __name__
__module____qualname__r$   r*   r:   rC   rZ   rk   rm   rt   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   r%   r#   r   r      s       _ _ _
_ _ _
- - -( ( (
\ 
\ 
\W W WW W W1 1 1F F F9 9 9) ) )+ + ++ + ++ + +) ) )+ + ++ + +: : :F F FF F FF F FV V VY Y YQ Q QY Y YV V VV V VI I I+ + + + +r%   r   )numpyr   bokeh.modelsr   r   r   holoviews.core.overlayr   r   holoviews.elementr   holoviews.plotting.bokeh.utilr	   utilsr   	test_plotr   r   r   rK   r%   r#   <module>r     s        N N N N N N N N N N 5 5 5 5 5 5 5 5 " " " " " " : : : : : : " " " " " " 4 4 4 4 4 4 4 4J+ J+ J+ J+ J+- J+ J+ J+ J+ J+r%   