
    e4                         d dl Zd dlZd dlmZmZmZ d dlm	Z	 d dl
mZmZ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e          ZdS )    N)CategoricalColorMapperDatetimeAxisLinearColorMapper)	NdOverlay)Dataset	HistogramImagePoints)	histogram)property_to_dict   )LoggingComparisonTestCase   )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S )TestSideHistogramPlotc                    t          t          j                            dd                    }t	          j        |                                          }|                                 t          t          |j
                                                            }|j
        d         }|j
        d         }|                     d|j        v           |                     d|j        v           d S )Nd      mainrightcolor_mapper)r
   nprandomrandr   get_plothistinitialize_plotnextitersubplotsvalues
assertTruehandles)selfpointsplotadjoint_plot	main_plot
right_plots         Qlib/python3.11/site-packages/holoviews/tests/plotting/bokeh/test_histogramplot.pytest_side_histogram_no_cmapperz4TestSideHistogramPlot.test_side_histogram_no_cmapper   s    	sA..//&v{{}}55D!5!5!7!78899 )&1	!*73
i.??@@@j.@@AAAAA    c                 X   t           j        ddddf         dz  \  }}t          t          j        |dz  |dz  z             d          }t	          j        |                                          }|                                 t          t          |j
                                                            }|j
        d         }|j
        d         }|                     |j        d	         |j        d	                    |                     |j        d
         |j        d                    dS )z#Assert histogram shares colormapper3   皙?r   r4   r   r   boundsr   r   r   	color_dimr   N)r   mgridr	   sinr   r   r   r   r    r!   r"   r#   assertIsr%   assertEqualvdims)r&   xyimgr(   r)   r*   r+   s           r,   test_side_histogram_cmapperz1TestSideHistogramPlot.test_side_histogram_cmapper   s   hs2vs2v~&,!BF1a419%%k:::&sxxzz22D!5!5!7!78899 )&1	!*73
i'7 (8	: 	: 	:*;71FFFFFr.   c                    t           j        ddddf         dz  \  }}t          t          j        |dz  |dz  z             d          }|                    ddgd	d
          }t          j        |          }|                                 t          t          |j
                                                            }|j
        d         }|j
        d         }|j
        d         }	|                     |j        d         |j        d                    |                     |j        d         |	j        d                    |                     |j        d         |j        d                    dS )z,Assert weighted histograms share colormapperr0   r1   r2   r   r3   r5   r=   r>   zT)	dimensionweight_dimensionmean_weightedr   r   topr   r7   r   N)r   r8   r	   r9   r   r   r   r   r    r!   r"   r#   r:   r%   r;   r<   )
r&   r=   r>   r?   adjointr(   r)   r*   r+   top_plots
             r,   $test_side_histogram_cmapper_weightedz:TestSideHistogramPlot.test_side_histogram_cmapper_weighted(   sZ   hs2vs2v~&,!BF1a419%%k:::((c3Z#)-  / /&w//D!5!5!7!78899 )&1	!*73
(/i'7 (8	: 	: 	:i'7&~6	8 	8 	8*;71FFFFFr.   c                    t          j        d t          dd          D                       }t          t	          |d          d          }t          j        |          }|j        d         }t          j        g d          t          j        g d	d
          t          j        g dd
          d}|                                D ]&\  }}| 	                    |j
        |         |           '|j        d         }|j        d         }	|                     |t                     | 	                    |	j        t          j        dd                     | 	                    |	j        t          j        dd                     d S )Nc                 :    g | ]}t          j        d d|          S )i  r   )dtdatetime.0is     r,   
<listcomp>zHTestSideHistogramPlot.test_histogram_datetime64_plot.<locals>.<listcomp>;   s&    GGGa"+dAq11GGGr.   r      Date   )num_binssource)r   r   r   r   )2017-01-01T00:00:00.0000002017-01-01T18:00:00.0000002017-01-02T12:00:00.0000002017-01-03T06:00:00.000000zdatetime64[us])dtype)rX   rY   rZ   2017-01-04T00:00:00.000000)rF   leftr   xaxisx_rangerW   usr\   )r   arrayranger   r   r   r   r%   itemsr;   dataassertIsInstancer   start
datetime64end)
r&   datesr   r(   rV   rd   kvr^   range_xs
             r,   test_histogram_datetime64_plotz4TestSideHistogramPlot.test_histogram_datetime64_plot:   s   GG5A;;GGGHH//!<<<&t,,h'8LLL))H L L L '( ( ( X L L L '( ( (

 

 JJLL 	0 	0DAqV[^Q////W%,y)e\2226RTX(Y(YZZZbm4PRV&W&WXXXXXr.   c                    t          g d                              d          }t          j        |          }|j        d         |j        d         }}|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d	           d S )
N)r   r   r   r4   r   r   r2   paddingr_   y_range瘙?ffffff@gffffffg333333@r   optsr   r   r%   r;   rf   rh   r&   r'   r(   r_   rt   s        r,   test_histogram_padding_squarez3TestSideHistogramPlot.test_histogram_padding_squareR   s    44455::3:GG&v..<	2DL4K(;<<<c***---c*****r.   c                    t          g d                              d          }t          j        |          }|j        d         |j        d         }}|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d	           d S )
Nro   )r   r   rq   r2   rr   r_   rt   ru   rv   r   皙	@rw   ry   s        r,   &test_histogram_padding_square_positivez<TestSideHistogramPlot.test_histogram_padding_square_positive[   s    3334499#9FF&v..<	2DL4K(;<<<c******c*****r.   c                    t          g d                              d          }t          j        |          }|j        d         |j        d         }}|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d	           d S )
N))r   rp   )r   r2   rr   r_   rt   ru   rv   g	r   rw   ry   s        r,   &test_histogram_padding_square_negativez<TestSideHistogramPlot.test_histogram_padding_square_negatived   s    66677<<S<II&v..<	2DL4K(;<<<c***---a(((((r.   c                    t          g d                              dd          }t          j        |          }|j        d         |j        d         }}|                     |j        d           |                     |j        d           |                     |j        d	           |                     |j        d
           d S )Nr|   r2   X  rs   widthr_   rt   gffffff?g333333@r   r}   rw   r&   r   r(   r_   rt   s        r,    test_histogram_padding_nonsquarez6TestSideHistogramPlot.test_histogram_padding_nonsquarem   s    66677<<SPS<TT	&y11<	2DL4K---d+++***c*****r.   c                    t          g d                              dd          }t          j        |          }|j        d         |j        d         }}|                     |j        d           |                     |j        d           |                     |j        d	           |                     |j        d
           d S )N))r   r   )r   r   rq   r2   T)rs   logxr_   rt   g	=kW?g+@r   r}   rw   r   s        r,   test_histogram_padding_logxz1TestSideHistogramPlot.test_histogram_padding_logxv   s    55566;;Cd;SS	&y11<	2DL4K(;<<<&8999***c*****r.   c                    t          g d                              dd          }t          j        |          }|j        d         |j        d         }}|                     |j        d           |                     |j        d           |                     |j        d	           |                     |j        d
           | j        	                    dd           d S )Nr|   r2   T)rs   logyr_   rt   ru   rv   g{Gz?gu
@WARNINGz2Logarithmic axis range encountered value less than)
r   rx   r   r   r%   r;   rf   rh   log_handlerassertContainsr   s        r,   test_histogram_padding_logyz1TestSideHistogramPlot.test_histogram_padding_logy   s    66677<<St<TT	&y11<	2DL4K(;<<<c***---&8999''	3ghhhhhr.   c                    t          d t          dd          D                                           d          }t          j        |          }|j        d         |j        d         }}|                     |j        t          j	        d                     |                     |j
        t          j	        d	                     |                     |j        d
           |                     |j
        d           d S )Nc                 B    g | ]}t          j        d |z  d          |fS z2016-04-0%dnsr   rg   rN   s     r,   rQ   zPTestSideHistogramPlot.test_histogram_padding_datetime_square.<locals>.<listcomp>   .    ```qma.? F FJ```r.   r   rT   r2   rr   r_   rt   z2016-03-31T04:48:00.000000000z2016-04-03T19:12:00.000000000r   r}   r   rb   rx   r   r   r%   r;   rf   r   rg   rh   r   s        r,   &test_histogram_padding_datetime_squarez<TestSideHistogramPlot.test_histogram_padding_datetime_square   s    ``TYZ[]^T_T_```aaff g 
 
	 &y11<	2DL4K6U(V(VWWWbm4S&T&TUUU***c*****r.   c                    t          d t          dd          D                                           dd          }t          j        |          }|j        d         |j        d         }}|                     |j        t          j	        d	                     |                     |j
        t          j	        d
                     |                     |j        d           |                     |j
        d           d S )Nc                 B    g | ]}t          j        d |z  d          |fS r   r   rN   s     r,   rQ   zSTestSideHistogramPlot.test_histogram_padding_datetime_nonsquare.<locals>.<listcomp>   r   r.   r   rT   r2   r   r   r_   rt   z2016-03-31T08:24:00.000000000z2016-04-03T15:36:00.000000000r   r}   r   r   s        r,   )test_histogram_padding_datetime_nonsquarez?TestSideHistogramPlot.test_histogram_padding_datetime_nonsquare   s    ``TYZ[]^T_T_```aaffs g 
 
	 &y11<	2DL4K6U(V(VWWWbm4S&T&TUUU***c*****r.   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           |                     |j        d
           d S )N)r   r   #000)r   r   #F00)r   r   #0F0r>   colorr<   r   cdsglyphr   r   r   fieldblack)r   rx   r   r   r%   r;   rd   r   ra   r   
fill_color
line_colorr&   r   r(   r   r   s        r,   test_histogram_color_opz-TestSideHistogramPlot.test_histogram_color_op   s    NNN%('N4 4 448DwD4G4G 	&y11l5!W%'*BH5M5M5M,N,NOOO)%*:;;gw=OPPP)733333r.   c                 f   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           |                     |j        d           d S )N)r   r   r   )r   r   r   )r   r   r   r>   r   r   r   r   r   color_color_mapperr   r   )r   r   r   r   	transformr   )r   rx   r   r   r%   r$   r   r;   lowhighrd   r   ra   r   r   r   r&   r   r(   r   r   cmappers         r,   test_histogram_linear_color_opz4TestSideHistogramPlot.test_histogram_linear_color_op   s'   ???%('N4 4 448DwD4G4G 	&y11l5!W%,34!2333a(((q)))'*BHYYY,?,?@@@)%*:;;w]d=e=efff)733333r.   c                 4   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
           |                     |j        d           d S )N))r   r   A)r   r   B)r   r   Cr>   r   r   r   r   r   r   )r   r   r   r   r   )r   rx   r   r   r%   r$   r   r;   factorsrd   r   ra   r   r   r   r   s         r,   #test_histogram_categorical_color_opz9TestSideHistogramPlot.test_histogram_categorical_color_op   s   EEE%('N4 4 448DwD4G4G 	&y11l5!W%,34!7888///:::'*BH___,E,EFFF)%*:;;w]d=e=efff)733333r.   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   rx   r   r   r%   r;   rd   r   ra   assertNotEqualr   r   r   r   s        r,   test_histogram_line_color_opz2TestSideHistogramPlot.test_histogram_line_color_op   s    NNN%('N4 4 448DGD4L4L 	&y11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   rx   r   r   r%   r;   rd   r   ra   r   r   r   r   r   s        r,   test_histogram_fill_color_opz2TestSideHistogramPlot.test_histogram_fill_color_op   s    NNN%('N4 4 448DGD4L4L 	&y11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   rx   r   r   r%   r;   rd   r   ra   r   
fill_alphar   s        r,   test_histogram_alpha_opz-TestSideHistogramPlot.test_histogram_alpha_op   s    CCC%('N4 4 448DwD4G4G 	&y11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   rx   r   r   r%   r;   rd   r   ra   r   r   r   r   r   s        r,   test_histogram_line_alpha_opz2TestSideHistogramPlot.test_histogram_line_alpha_op   s    CCC%('N4 4 448DGD4L4L 	&y11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   rx   r   r   r%   r;   rd   r   ra   r   r   r   r   r   s        r,   test_histogram_fill_alpha_opz2TestSideHistogramPlot.test_histogram_fill_alpha_op   s    CCC%('N4 4 448DGD4L4L 	&y11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   rT   )r   r      r>   
line_widthr   )r   r   r   )r   rT   r   r   )r   rx   r   r   r%   r;   rd   r   ra   r   r   r   s        r,   test_histogram_line_width_opz2TestSideHistogramPlot.test_histogram_line_width_op   s    ???%(,$79 9 99=9V9V 	&y11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)rO   rP   r   s      r,   
<dictcomp>zATestSideHistogramPlot.test_op_ndoverlay_value.<locals>.<dictcomp>  s2    ```(!UUIbi!nn$=$=```r.   Colorr   r   r   )r   	enumeraterx   r   r   zipr"   r#   r;   r%   r   )r&   colorsoverlayr(   subplotr   s         r,   test_op_ndoverlay_valuez-TestSideHistogramPlot.test_op_ndoverlay_value  s    %``iX^N_N_```bijjoop{  IPo  Q  Q&w//!$-"6"6"8"86BB 	I 	INGUW_W5@%HHHH	I 	Ir.   N)__name__
__module____qualname__r-   r@   rI   rm   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r.   r,   r   r      s       B B BG G GG G G$Y Y Y0+ + ++ + +) ) )+ + ++ + +i i i	+ 	+ 	+	+ 	+ 	+4 4 44 4 44 4 4V V VY Y YQ Q QY Y YV V VV V VI I I I Ir.   r   )rM   rL   numpyr   bokeh.modelsr   r   r   holoviews.core.overlayr   holoviews.elementr   r   r	   r
   holoviews.operationr   holoviews.plotting.bokeh.utilr   utilsr   	test_plotr   r   r   r   r.   r,   <module>r      s
           P P P P P P P P P P , , , , , , ? ? ? ? ? ? ? ? ? ? ? ? ) ) ) ) ) ) : : : : : : . . . . . . 4 4 4 4 4 4 4 4xI xI xI xI xI5} xI xI xI xI xIr.   