
    ]e~                        d dl Zd dlZd dlZd dl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 ddlmZ dd	lmZmZmZ  e eej                   eej                  z
   eej                   z
   ed
g          z             e eej                   edg          z
            ej         dZ!g de!d         z   e!d         z   e!d<   g de!d<    e ee!d         e!d         z   e!d         z                       e!d<   d  e            D             Z"ej#        Z$g dZ%dg ee          z   Z&g dZ'g dZ(dZ)dZ*d Z+d7dZ, G d de          Z- G d d e-          Z. G d! d"e-          Z/ G d# d$e-          Z0 G d% d&e-          Z1 G d' d(e-          Z2 G d) d*e-          Z3 G d+ d,e-          Z4 G d- d.ej5                  Z6 G d/ d0e          Z7 G d1 d2e7          Z8 G d3 d4e7          Z9 G d5 d6e7          Z:dS )8    N)datetime_types	dt_to_int	is_number	max_range)tile_sources)
list_cmaps)Viewer   )HoloViewsConverter)hvPlot)is_geodataframe	is_xarrayinstantiate_crs_strpointsdataset)	dataframegriddedgeom)	bivariateheatmaphexbinlabelsvectorfieldr   r   r   2d)histkde
boxwhiskerviolinr   barbarhstatsr   allc                 <    g | ]}|                     d           |S )_r_r)endswith).0cms     )lib/python3.11/site-packages/hvplot/ui.py
<listcomp>r)       s)    >>>"++f*=*=>>>>    )borders	coastlinelandlakesoceanriversstatesgrid)crs
crs_kwargs
projectionprojection_kwargsglobal_extentprojectfeaturesfeature_scale)Ncountminmaxmeansumanyi'     c                 &    t          j        | fi |S )as  Explore your data and design your plot via an interactive user interface.

    This function returns an interactive Panel component that enable you to quickly change the
    settings of your plot via widgets.

    Reference: https://hvplot.holoviz.org/getting_started/explorer.html

    Parameters
    ----------
    data : pandas.DataFrame | xarray.DataArray | xarray.Dataset
        Data structure to explore.
    kwargs : optional
        Arguments that `data.hvplot()` would also accept like `kind='bar'`.

    Returns
    -------
    hvplotExporer
        Panel component to explore the data and design your plot.

    Example
    -------

    >>> import hvplot.pandas
    >>> import pandas as pd
    >>> df = pd.DataFrame({"x": [1, 2, 3], "y": [1, 4, 9]})
    >>> hvplot.explorer(df)

    You can also specify initial values

    >>> hvplot.explorer(df, kind='bar', x='x')
    )hvPlotExplorer	from_data)datakwargss     r(   explorerrG   0   s    @ #D33F333r*   c                 "   |pi }| j         D ]Y}|dk    r	||vri ||<   t          | j         |         t           j        t           j        f          rd||         d<   d||         d<   Zd|t          d}|r||d<   t          j        | j         fi |}|S )	NnameT	throttledstretch_widthsizing_modeF)	show_namewidgetswidth
parameters)param
isinstanceNumberRangeCONTROLS_WIDTHpnParam)instwidgets_kwargsrP   pnamerF   panes         r(   _create_param_paner\   S   s    #)rN  ? ?F??&&$&N5!dj'%,)DEE 	615N5!+./>um,,! F
  *)|8DJ))&))DKr*   c                   f     e Zd Z ej        ed          Zi ZdZ fdZ	d Z
ed             Z xZS )Controls)class_
precedenceTc                 H    || _          t                      j        di | d S )N )_datasuper__init__)selfdfparams	__class__s      r(   rf   zControls.__init__r   s-    
""6"""""r*   c                 .    t          | | j                  S )N)rY   )r\   _widgets_kwargsrg   s    r(   	__panel__zControls.__panel__v   s    !$t7KLLLLr*   c                 l    d | j                                                                         D             S )Nc                 2    i | ]\  }}|d v	||dk    ||S ))rI   rG   N rc   r&   kvs      r(   
<dictcomp>z#Controls.kwargs.<locals>.<dictcomp>{   s@     P P PA000Q]qBww 1GNwwr*   )rQ   valuesitemsrm   s    r(   rF   zControls.kwargsy   sB    P P!2!2!4!4!:!:!<!< P P P 	Pr*   )__name__
__module____qualname__rQ   ClassSelectorr	   rG   rl   _Controls__abstractrf   rn   propertyrF   __classcell__rj   s   @r(   r^   r^   j   s        "u"&R@@@HOJ# # # # #M M M P P XP P P P Pr*   r^   c                       e Zd Z ej        dd          Z ej        ddg d          Z ej        d	          Z	 ej
        d	          Z ej        ed         d
e          Z ej
        d	          Z ej
        dd          ZdddiiZ fdZed             Z ej        dddd          d             Z xZS )ColormappingzColorbar Limits (clim)z0
        Upper and lower limits of the colorbar.labeldoczColorbar Normalization (cnorm)linear)r   logeq_hist)r   defaultobjectsNr   Colormap)r   r   r   TFz4
        Whether the data are symmetric around zero.r   r   climplaceholderz
(min, max)c                      t                      j        |fi | d|vr,| j        j        j                            dd          | _        d S d S )N	symmetricF)re   rf   rG   
_converter
_plot_optsgetr   rg   rE   ri   rj   s      r(   rf   zColormapping.__init__   sY    (((((f$$!]5@DD[RWXXDNNN %$r*   c                 d    | j         j        t          j        v rdS | j        d uo| j        | j        v S NT)rG   kind_hvConverter_colorbar_typescolorrd   rm   s    r(   colormappedzColormapping.colormapped   s5    =!===4z%B$*
*BBr*   r   zexplorer.kindr   watchc                 l   | j         r-| j        t          t                                                    vrd S | j        j        t          j        v r| j	        rdnd}d| _
        n@| j        | j        v r0| j        | j                 j        j        }|dv rd}n| j	        rd}nd}nd S t          |         | _        d S )N	divergingr   TOSUcategorical)r   cmaplistDEFAULT_CMAPSrv   rG   r   r   r   r   colorbarr   rd   dtype)rg   keyr   s      r(   _update_coloroptszColormapping._update_coloropts   s     	49D9M9M9O9O4P4P#P#PF=!===!%=++XC DMMZ4:%%:dj)/4Du}}# !F!#&			r*   )rx   ry   rz   rQ   rT   r   SelectorcnormStringr   Booleanr   r   CMAPSr   rescale_discrete_levelsr   rl   rf   r}   r   dependsr   r~   r   s   @r(   r   r      sk       5;5 <3 4 4 4D EN.,,,  E EL&&&Eu}T***H5>-"9 *E; ; ;D ,emD999e 27 8 8 8I |<=OY Y Y Y Y
 C C XC
 U]7O[EEE' ' FE' ' ' ' 'r*   r   c                   0    e Zd Z ej        d          ZdS )Styler
   r   N)rx   ry   rz   rQ   	Magnitudealpharc   r*   r(   r   r      s"        EOA&&&EEEr*   r   c                       e Zd Z ej        dej                  Z ej        d          Z	 ej        d          Z
 ej        dd          Z ej        dd          Z ej        d          Z ej        d          Z ej                    Z ej                    Z ej        d          Z	 ej        d          Z
 fd	Z ej        d
dd          d             Zed             Z xZS )Axesbottom_rightr   r   Fr   N)r   N)r   boundsTc                 d     t                      j        |fi | |                                  d S N)re   rf   _update_rangesr   s      r(   rf   zAxes.__init__   s:    (((((r*   zexplorer.xlimzexplorer.ylimr   c                    | j                                         }|tt          |d                   r_t          |d                   rJ|d         |d         k    r8|                     |          }d| j        j        _        || j        j        _        nd| j        j        _        | j                                         }|ut          |d                   r`t          |d                   rK|d         |d         k    r9|                     |          }d| j        j        _        || j        j        _        d S d| j        j        _        d S )Nr   r
   r_   )rG   xlimr   _convert_to_intrQ   ra   r   ylim)rg   r   r   s      r(   r   zAxes._update_ranges   s!   }!!##	$q' 2 2ya7I7IdSTgY]^_Y`N`N`''--D)*DJO&%)DJO"")+DJO&}!!##	$q' 2 2ya7I7IdSTgY]^_Y`N`N`''--D)*DJO&%)DJO""")+DJO&&&r*   c                     t          | d         t                    rGt          | d         t                    r,t          | d         d          t          | d         d          f} | S )z
        Converts datetime to int to avoid the error in https://github.com/holoviz/hvplot/issues/964.

        This function is a workaround and should be removed when a better solution is found.

        r   r
   ms)rR   r   r   )vals    r(   r   zAxes._convert_to_int   s\     c!fn-- 	E*SV^2T2T 	ESVT**Ic!fd,C,CDC
r*   )rx   ry   rz   rQ   r   r   _legend_positionslegendr   logxlogyIntegerheightrO   
responsiveshared_axesrT   r   r   rf   r   r   staticmethodr   r~   r   s   @r(   r   r      sZ       U^NL<Z[[[F5='''D5='''DU]4	:::FEM$y999Et,,,J%----K5;==D5;==D5='''D5='''D     U]?ODAAA, , BA,    \    r*   r   c                       e Zd Z ej        d          Z ej        d          Z ej        d          Z ej        dd          Z ej	        dd	
          Z
 ej        dddd          ZdS )LabelszTitle for the plot)r   zAxis labels for the x-axis.zAxis labels for the y-axis.zColorbar Label (clabel)z&
        Axis labels for the colorbar.r   r
   z
        Scales the size of all fonts by the same amount, e.g. fontscale=1.5
        enlarges all fonts (title, xticks, labels etc.) by 50%.r   r   )r   h  zX Tick Labels Rotation (rot)z\
        Rotates the axis ticks along the x-axis by the specified
        number of degrees.)r   r   r   r   N)rx   ry   rz   rQ   r   titlexlabelylabelclabelrS   	fontscaler   rotrc   r*   r(   r   r      s        EL1222EU\;<<<FU\;<<<FU\ 9 @) * * *F Q -C D D DI %-(*H O  CCCr*   r   c                       e Zd Z ej        ded          Z ej        dd          Z ej	        dd          Z
 ej        i d          Z ej        dd	          Z ej        i d
          Z ej        dd          Z ej        dd          Z ej        ded          Z ej        dg dd          Zddej        j        iiZ fdZ ej        dd          d             Z xZS )
GeographicNz
        Whether to overlay the plot on a tile source. Tiles sources
        can be selected by name or a tiles object or class can be passed,
        the default is 'Wikipedia'.r   r   r   Fz
        Whether the plot should be treated as geographic (and assume
        PlateCarree, i.e. lat/lon coordinates). Require GeoViews.r   zu
        Coordinate reference system of the data specified as Cartopy
        CRS object, proj.4 string or EPSG code.z3
        Keyword arguments to pass to selected CRS.z2
        Projection to use for cartographic plots.z:
        Keyword arguments to pass to selected projection.zC
        Whether to expand the plot extent to span the whole globe.z
        Whether to project the data before plotting (adds initial
        overhead but avoids projecting data when plot is dynamically
        updated).z
        A list of features or a dictionary of features and the scale
        at which to render it. Available features include 'borders',
        'coastline', 'lakes', 'land', 'ocean', 'rivers' and 'states'.110m)r   50m10mz3
        The scale at which to render the features.geotypec                 b   d}	 dd l }d}n# t          $ r Y nw xY wt          dgz   }|s*t          fd|D                       rt          d           t	                      j        |fi  |s+|D ]}d| j        |         _        d| j        d         _        d S | 	                                 d S )NFr   Tr   c              3       K   | ]}|v V  	d S r   rc   )r&   pri   s     r(   	<genexpr>z&Geographic.__init__.<locals>.<genexpr>@  s'      #D#DAAK#D#D#D#D#D#Dr*   z<GeoViews must be installed to enable the geographic options.zgeo (require GeoViews))
geoviewsImportErrorGEO_KEYSr@   re   rf   rQ   constantr   _update_crs_projection)rg   rE   ri   gv_availabler   
geo_paramsr   rj   s     `    r(   rf   zGeographic.__init__7  s   	OOOLL 	 	 	D	 '
 	#D#D#D#D#D#D#D D D 	N   	((((( 	* . .)-
1&&&>DJu###'')))))s    
Tr   c                 V   t          | j        p| j                  }t          D ]}| | j        |         _        || _        |sd S ddlm} t          d t	          j	        |          
                                D                       }|                    dd           |                    dd           |                    d           || j        j        _        || j        j        _        i }| j        |d         |d<   | j        d|d<   | j        d	g|d
<    | j        j        di | d S )Nr   )CRSc              3   P   K   | ]!}|                     d           s
|dk    |V  "dS )_r   N)
startswith)r&   rs   s     r(   r   z4Geographic._update_crs_projection.<locals>.<genexpr>W  sH       
 
<<$$
)*e )3
 
r*   GOOGLE_MERCATORPlateCarreer5   Tr7   r,   r9   rc   )boolr   r8   r   rQ   r   cartopy.crsr   sortedconcrete_descendentskeysinsertremover3   r   r5   r7   r9   update)rg   enabledr   r   crs_listupdatess         r(   r   z!Geographic._update_crs_projectionM  s[   tx/4<00 	3 	3C+2{DJsO$$ 	F###### 
 
1#66;;==
 
 
 
 
 	,---=)))&&&!)
(0
%?"$,QKGL!%'+GO$= #.-GJ
$$G$$$$$r*   )rx   ry   rz   rQ   ObjectSelector	GEO_TILEStilesr   r   r   r3   Dictr4   r5   r6   r7   r8   ListSelectorGEO_FEATURESr9   r:   rV   rN   Togglerl   rf   r   r   r~   r   s   @r(   r   r     s        E y G' ( ( (E
 %- ,E F F FC %. ,3 4 4 4C B -6 7 7 7J &%d 95 6 6 6J #
2 4= > > > "EM$ 5F G G GM emE 0   G
 "u!$ KI J J JH
 )E(AWAWAW ^6 7 7 7M vrz'89:O* * * * *, U]5%%%% % &%% % % % %r*   r   c                      e Zd Z ej        dd          Z ej        dd          Z ej        ded          Z	 ej        dd          Z
 ej        dd	          Z ej        dd
          Z ej        dd          d             Z ej        dd          d             Z ej        dddd          d             ZdS )
OperationsFzm
        Whether to apply rasterization and shading using datashader
        library returning an RGB object.r   zk
        Whether to apply rasterization using the datashader library
        returning an aggregated Image.NzJ
        Aggregator to use when applying rasterize or datashade operation.r   z
        Allows plots generated with datashade=True or rasterize=True
        to increase the point size to make sparse regions more visible.zK
        Specifies the smallest allowed sampling interval along the x-axis.zK
        Specifies the smallest allowed sampling interval along the y-axis.	datashadeTr   c                 &    | j         r	d| _        d S d S NF)r  	rasterizerm   s    r(   _toggle_rasterizezOperations._toggle_rasterize  !    > 	#"DNNN	# 	#r*   r  c                 &    | j         r	d| _        d S d S r  )r  r  rm   s    r(   _toggle_datashadezOperations._toggle_datashade  r  r*   )r   on_initc                     | j         p| j        }| | j        j        _        | | j        j        _        | | j        j        _        | | j        j        _        d S r   )r  r  rQ   	dynspreadr   
x_sampling
y_sampling
aggregator)rg   r   s     r(   _update_optionszOperations._update_options  sR    .2DN,3
%-4
&-4
&-4
&&&r*   )rx   ry   rz   rQ   r   r  r  r   AGGREGATORSr  r  rS   r  r  r   r  r
  r  rc   r*   r(   r  r  n  sw       e 2, - - -I e 2* + + +I  k HM N N NJ e 2K L L LI d 1N O O OJ d 1N O O OJ U];d+++# # ,+# U];d+++# # ,+# U];4FFF5 5 GF5 5 5r*   r  c                   >    e Zd Z ej        dd          ZdddiiZdS )AdvancedzHoloViews .opts()z
        Options applied via HoloViews .opts().
        Examples:
        - image: {"color_levels": 11}
        - line: {"line_dash": "dashed"}
        - scatter: {'size': 5, 'marker': '^'}r   optsr   z{'size': 5, 'marker': '^'}N)rx   ry   rz   rQ   r   r  rl   rc   r*   r(   r  r    s@        5:/ 61 2 2 2D /KLMOOOr*   r  c                   2    e Zd Z ej        dd          ZdS )	StatusBarTzI
        Whether to automatically update the plot when a param is changedr   N)rx   ry   rz   rQ   r   live_updaterc   r*   r(   r  r    s1        %- 3L M M MKKKr*   r  c                       e Zd Z ej                    Z ej                    Z ej                    Z ej        g d          Z	 ej        g           Z
 ej        g           Z ej        e          Z ej        e          Z ej        e          Z ej        e          Z ej        e          Z ej        e          Z ej        e          Z ej        e          Z ej        dd          Zed             Z d	 Z! fd
Z"d Z#d Z$d Z%e&d             Z'e&d             Z(e&d             Z)ddZ*d Z+d Z,d Z-ddZ.d Z/d Z0d Z1 xZ2S )rC   Y)r   r   r   )r`   r_   z#
        Code to generate the plot.)ra   r   c                     t          |          rt          d          t          |          rt          } nt          }  | |fi |S )Nz'GeoDataFrame objects not yet supported.)r   	TypeErrorr   hvGridExplorerhvDataFrameExplorer)clsrE   ri   s      r(   rD   zhvPlotExplorer.from_data  sS    4   	&EFFFt__ 	& CC%Cs4""6"""r*   c                     | j         S r   )_layoutrm   s    r(   rn   zhvPlotExplorer.__panel__  s
    |r*   c                 	                         d                               d          }}dv r<t          d         t                    r                    d          nd         gd<   fd                                D             }t          ||fi d                                 D             } fd                                D              t                      j        d%i   _	        | _
        d  j        D             }t           g dd	g |d
i           _         j                             j        d	            j                             j        d            j                             j        d                                             t)          j        d           _        t/          d%i | _        t)          j         j        dt(          j        d           _        d  j                                                                        D             }i }	|D ]&fd                                D             |	<   'rt=          d            fd|	                                D              _          j        j         d%i  j          j                             j!        t           j                              j                                        D ]4}
|
j                             j!        t          |
j                             5 j        j                             j!        t           j        j                             t(          j"        #                    ddd           _$        t(          j"        %                    ddddt(          j                   _&        t(          j"        '                    ddd           _(        t)          j)         j$         j        t(          j*        +                                t)          j         j        t)          j        d  j&        j*        fd! j(        f          d"          dd#$           _,         j        -                    d	           d S )&Nxyy_multic                 X    i | ]&}|t           j        v |                    |          'S rc   )r  rQ   pop)r&   rs   ri   s     r(   ru   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s<     
 
 
IO## vzz!}}###r*   c                 "    i | ]\  }}|d v	||S ))r#  r$  r%  rc   rr   s      r(   ru   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s)    QQQ1!;P2P2Pq!2P2P2Pr*   c                 N    i | ]!}|j         v|                    |          "S rc   rQ   r'  )r&   rs   ri   rg   s     r(   ru   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s<     
 
 

"" vzz!}}"""r*   c                 *    i | ]}|t           |         S rc   )KINDS)r&   groups     r(   ru   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s    @@@%%u@@@r*   )r   r#  r$  groupbybyr   )optionsgroups)rP   rY   r/  left)tabs_locationF)   8   r   r5  )rM   default_layoutmarginc                     g | ]=}t          |t          j                  t          |j        t
                    6|j        >S rc   )rR   rQ   r{   
issubclassr`   r^   )r&   r   s     r(   r)   z+hvPlotExplorer.__init__.<locals>.<listcomp>  sS     
 
 
!U011
 18X..	
H
 
 
r*   c                 N    i | ]!}|j         v |                    |          "S rc   r*  )r&   rs   r  extrass     r(   ru   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s8     & & &	>> 6::a==!>>r*   z8__init__() got keyword(s) not supported by any control: c                 \    i | ](\  }}|j                                          |fd i|)S )rG   )rI   lower)r&   r  cparamsrh   rg   s      r(   ru   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  sR     
 
 
W HNNcc"??t?w??
 
 
r*   dangerrK   )
alert_typevisiblerL   stretch_both   )r4  r4  r4     bottom)rL   
min_heightr7  widget_locationwidget_layout)r4  r4  r   rD  )rL   rF  r7  PlotCode)rL   iX  )rL   r   rc   ).r   rR   r   r'  copyr   rw   re   rf   rd   r   _groupsr\   	_controlsrQ   r   _toggle_controls_check_y	_check_by	_populaterV   Tabs_control_tabsr  	statusbarrW   Row
_statusbarr   rv   r  _controllersr   _refreshr[   Alert_alert	HoloViews_hv_paneMarkdown
_code_paneColumnlayoutDividerr!  trigger)rg   rh   ri   r#  r$  statusbar_params	converterr1  controlscontroller_params
controllerr  r;  rj   s   ```        @@r(   rf   zhvPlotExplorer.__init__  s   zz#

31&==3=fSk43P3P c

3W]^aWbVcF9
 
 
 
[[]]
 
 

 !1
 
QQQQQ
 
	

 
 
 
 
[[]]
 
 

 	""6"""
#@@4<@@@+:::"f$E$EF
 
 

 	
.777
	222
...W6:::"66%566(N6!	
 
 

 
Z''))0022
 
 
  	 	C& & & & && & &c""
  	S6SS  
 
 
 
 
 1 7 7 9 9
 
 
 	
..D-...
TZ(8(8999+2244 	J 	JJ""4=$z7G2H2HIIII""4=$t~7K2L2LMMMgmmO $ 
 
 ))&3}$BF * < < '**&3} + N NyKOIF" !568QRR*   (
 
 
  	
6"""""r*   c                 t   | j         j        }t          | j         dg           fd|D             }| j        D ]~}|dk    r	| j        |         }t	          |t          j                  rN|dk    r||_        n||_        |dk    s|dk    r-t          | |d          t          | ||j        d                    dS )zO
        Populates the options of the controls based on the data type.
        indexesc                     g | ]}|v|	S rc   rc   r&   rt   ri  s     r(   r)   z,hvPlotExplorer._populate.<locals>.<listcomp>>  #    GGGAaw6F6Fa6F6F6Fr*   r   r#  r$  Nr   )r   	variablesgetattrrQ   rR   r   r   setattrrg   rm  variables_no_indexrZ   r   ri  s        @r(   rQ  zhvPlotExplorer._populate8  s     O-	$/9b99GGGGGGGZ 	7 	7E
5!A!U^,, 7C<< )AII 2AI SLLESLLgdE46P6P6XD%1666	7 	7r*   c           	         d| j         j        v r| j        n| j        }t	          |t
                    rt          |          dk    r|d         }i }| j                                                                        D ]}t	          |t                    r|j
        st	          |t                    r|j                            di           }Pt	          |t                    r|                    |j                   |                    d          rd|vr[t!          j        t!          j        |                                                     }|dk    rdnd	| j        _        | j        j        |d<   d
D ]>}|                    | di           }t/          |                    |          fi |||<   ?|                    dd           fd|                    dg           D             |d<   d|d<   | j        }t          |          t2          k    rY| j        t6          d         v sE|                    d          s0|                    d          s|                    t2                    }d| j        _        	  t?          |          d| j        | j         || j!        | j"        d|| _#        |r | j#        j$        di | | j#        | j%        _&        t          | j%        j'                  dk    r| j%        j'        D ]	}	d|	_(        
d| j)        _*        n;# tV          $ r.}
| j)        j                            d|
 d           Y d }
~
nd }
~
ww xY wd| j        _        d S # d| j        _        w xY w)Nr%  r
   r   r  r   r3   r   r   r   )r3   r5   _kwargsr:   c                     i | ]}|S rc   rc   )r&   featurer:   s     r(   ru   z(hvPlotExplorer._plot.<locals>.<dictcomp>f  s    !c!c!cW'=!c!c!cr*   r9   i  rF  r!   r  r  )nTr   r#  r$  r/  r.  )rD  r4  r4  r4  Fz+**Rendering failed with following error**: )objectrA  rc   ),rM  rP   r%  r$  rR   r   lenrQ   rv   r   r   r  rF   r   r^   r   npr=   absr   
geographicr3   r'  r   rd   MAX_ROWSr   r,  sampler!  loading_hvPlotr#  r/  r.  _hvplotr  r\  rx  
widget_boxr7  rZ  rA  	Exception)rg   r$  rF   rt   opts_kwargsxmaxr   r4   rh   wer:   s              @r(   _plotzhvPlotExplorer._plotM  s   %)BBBDLLa 	3q66Q;;!A""$$++-- 	( 	(A!Z((  !X&& (hll6266Ax(( (ah'''::e 
	dF""vbfTYY[[11227;s{{mmHY# $ 3u, Q Q#ZZ3<<
1&**S//PPZPPs"JJ==M!c!c!c!c

S]_aHbHb!c!c!cF:"|Zr77XtyE'N'B'BfjjQ\F]F]'Bagakaklwaxax'BX&&B#	)&72;; Y$&A$'4< SY DL  1!!00K000#'<DM  4=+,,q001 - -A,AHH"'DK 	 	 	K$$HQHH %        	 $)DL   5DL ((((s1   5BL M 
M$M<M MM M%c                    | j         j        sd S |                                  t          j                            |           5  |                                 | _        d d d            n# 1 swxY w Y   d| j         d| j        _	        d S )Nz
```python
z
```)
rT  r  r  rQ   parameterizeddiscard_events	plot_codecoder^  rx  )rg   eventss     r(   rX  zhvPlotExplorer._refresh  s    ~) 	F

 //55 	) 	)((DI	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)!C!C!C!Cs   A((A,/A,c                     dS )NrE   rc   rm   s    r(   	_var_namezhvPlotExplorer._var_name  s    vr*   c                 2    | j         t          d         v rdS dS )Nr   TF)r   r,  rm   s    r(   	_single_yzhvPlotExplorer._single_y  s    9d##4ur*   c                      t          d          )Nz"Must be implemented by subclasses.)NotImplementedErrorrm   s    r(   rL  zhvPlotExplorer._groups  s    !"FGGGr*   Nc                    d}|r|j         dv rddg}d}n6|r|j         t          d         v rg d}n|r|j         dv rd | _        g d	}ng d
}|| j        _        d| j        fg}|r]|d| j        fd| j        fd| j        fd| j        fd| j	        fd| j
        fgz  }|r&|j         dvr|                    dd| j        f           || j        d d <   d S )NT)tabler   r   columnsFr   rw  )r   r   density)r   r%  r/  r.  )r   r#  r%  r/  r.  Fieldsr   r   r   r  r   r  )arear   lineohlcrgbstepr4  r   )newr,  r#  rM  rP   axesr   style
operationsr|  advancedr   colormappingrS  )rg   eventrA  rP   tabss        r(   rN  zhvPlotExplorer._toggle_controls  sA    		CUY"666 ),JGG 	CuyE$K//<<<JJ 	Cuy$>>>DF===JJBBBJ$.!4>*+ 
	D#4;'$*%t/t/T]+ D  D*XXXA0ABCCC $111r*   c                 d    t          |j                  dk    r| j        r|j        | _        d S d S d S Nr
   )ry  r  r/  oldr$  rg   r  s     r(   rO  zhvPlotExplorer._check_y  s7    uy>>A$'YDFFF r*   c                     |j         r6d| j        j        v r*| j        r%t	          | j                  dk    rg | _        d S d S d S d S d S )Nr%  r
   )r  rM  rP   r%  ry  r/  r  s     r(   rP  zhvPlotExplorer._check_by  sa    9 	dn&???DL?UXY]YeUfUfijUjUjDGGG	 	????UjUjr*   c                 4    | j                                         S )z/Return the plot as a HoloViews object.
        )r  clonerm   s    r(   hvplotzhvPlotExplorer.hvplot  s     |!!###r*   c                     |                                  }d|vrd|d<   d|d<   d}|r|                     |          }|p| j         d| d}| j        j        }|r|                     |          }|d| dz  }|S )	a  Return a string representation that can be easily copy-pasted
        in a notebook cell to create a plot from a call to the `.hvplot`
        accessor, and that includes all the customized settings of the explorer.

        >>> hvexplorer.plot_code(var_name='data')
        "data.hvplot(x='time', y='value')"

        Parameters
        ----------
        var_name: string
            Data variable name by which the returned string will start.
        r   r   rE  rG  rq   z	.hvplot(
z
)z.opts(
)settings_build_kwargs_stringr  r  r  )rg   var_namer  settings_argssnippetr  	opts_argss          r(   r  zhvPlotExplorer.plot_code  s     ==??8##!/HX&."# 	@ 55h??M/MM=MMM}! 	111$77I0)0000Gr*   c                 n    d}|r0|                                 D ]\  }}|d| d|dz  }|d d         }|S )Nrq   z    =z,
r_   )rw   )rg   rF   argsrs   rt   s        r(   r  z#hvPlotExplorer._build_kwargs_string  s\     	 , ,1+q++1++++9Dr*   c                 6    t          j        | j        |fi | dS )a5  Save the plot to file.

        Calls the `holoviews.save` utility, refer to its documentation
        for a full description of the available kwargs.

        Parameters
        ----------
        filename: string, pathlib.Path or IO object
            The path or BytesIO/StringIO object to save to
        N)_hvsaver  )rg   filenamerF   s      r(   r  zhvPlotExplorer.save  s&     	x22622222r*   c                 (   i }| j                                         D ]K}t          |j                  ddhz
  }|D ]-}t	          ||          }||j        |         j        k    r|||<   .L| j        j        D ]3}t	          | |          }|| j        |         j        k    s|dk    r|||<   4d|v r|                    d          |d<   |                    dd           d t          t          |                                                    D             }|S )	a   Return a dictionary of the customized settings.

        This dictionary can be reused as an unpacked input to the explorer or
        a call to the `.hvplot` accessor.

        >>> hvplot.explorer(df, **settings)
        >>> df.hvplot(**settings)
        rI   rG   r   r%  r$  r  Nc                     i | ]\  }}||	S rc   rc   rr   s      r(   ru   z+hvPlotExplorer.settings.<locals>.<dictcomp>  s    DDDTQAqDDDr*   )rW  rv   setrQ   rn  r   rM  rP   r'  r   r   rw   )rg   r  rg  ri   r   values         r(   r  zhvPlotExplorer.settings  s5    +2244 	( 	(J)**fj-AAF ( (
A..J,Q/777"'HQK( * 	$ 	$AD!$$E
1---f#  $LL33HSMVT"""DDVD1A1A,B,B%C%CDDDr*   r   )3rx   ry   rz   rQ   r   r   r#  r$  r   r%  r/  r.  r{   r   r  r   r  r   r   r   r|  r  r  r  rT  r   r  r  r  r   r  classmethodrD   rn   rf   rQ  r  rX  r}   r  r  rL  rN  rO  rP  r  r  r  r  r  r~   r   s   @r(   rC   rC     s       5>DAA e 3777G		B	'	'	'B e ,,,G 5d+++D&5&l;;;L U ///F$$J777J$$J777J##9555IEu---E"u"(333H5<2 ,& ' ' 'D # # [#  [# [# [# [# [#z7 7 7*4) 4) 4)lD D D   X   X
 H H XH% % % %:    $ $ $
   6  3 3 3      r*   rC   c                      e Zd Z ej        ded                   Zed             Zed             Z	ed             Z
ed             Z ej        d          d	             Z ej        d
          d             Zed             ZdS )hvGeomExplorerNr"   r   c                     dS )Ngdfrc   rm   s    r(   r  zhvGeomExplorer._var_name  s    ur*   c                     dS r   rc   rm   s    r(   r  zhvGeomExplorer._single_y      tr*   c                     d S r   rc   rm   s    r(   _xzhvGeomExplorer._x  r  r*   c                     d S r   rc   rm   s    r(   _yzhvGeomExplorer._y"  r  r*   r#  c                     d S r   rc   rm   s    r(   r   zhvGeomExplorer.xlim&      r*   r$  c                     d S r   rc   rm   s    r(   r   zhvGeomExplorer.ylim*  r  r*   c                 
    ddgS )Nr   r   rc   rm   s    r(   rL  zhvGeomExplorer._groups.  s    ;''r*   )rx   ry   rz   rQ   r   r,  r   r}   r  r  r  r  r   r   r   rL  rc   r*   r(   r  r    s       5>$e===D  X   X   X   X U]3   U]3   ( ( X( ( (r*   r  c                       e Zd Z ej        ded                   Z fdZed             Z	ed             Z
ed             Z ej        d          d	             Z ej        d
d          d             Zed             Zd Z xZS )r  imager"   r   c                 l   dd l }d}t          ||j                  rmt          |j                  }t          |          dk    r||d                  }d|d          d}n+|                    d                              dd          }d}d	|vrd
|d	<   || _         t                      j
        |fi | d S )Nr   rq   r
   z['z']variable.z0.to_array('variable').transpose(..., 'variable')r   r  )xarrayrR   Datasetr   	data_varsry  to_array	transpose_var_name_suffixre   rf   )rg   dsri   xrvar_name_suffixr  rj   s         r(   rf   zhvGridExplorer.__init__6  s    b"*%% 	UR\**I9~~""	!%"7y|"7"7"7[[,,66sJGG"T$F6N /&&v&&&&&r*   c                 (    | j         r
d| j          S dS )Nr  da)r  rm   s    r(   r  zhvGridExplorer._var_nameF  s#      	/-///4r*   c                 Z    | j         | j        j         p| j        j        d         n| j         S Nr   )r#  r   ri  rm   s    r(   r  zhvGridExplorer._xM  )    DHFN!?T_%<Q%?X\X^^r*   c                 Z    | j         | j        j         p| j        j        d         n| j         S r  )r$  r   ri  rm   s    r(   r  zhvGridExplorer._yQ  r  r*   r#  c                     	 | j         | j                 }n#  Y dS xY w|j        j        dv rd S t	          j        |          t	          j        |          fS )Nr   r
   r   )rd   r  r   r   rz  nanminnanmaxrg   rv   s     r(   r   zhvGridExplorer.xlimU  s[    	Z(FF	44<%%4	&!!29V#4#455s    r$  r%  c                       j         }t          |t                    s|g} fd|D             }t          d |D                       S )Nc              3   2   K   | ]}j         |         V  d S r   rd   r&   r$  rg   s     r(   r   z&hvGridExplorer.ylim.<locals>.<genexpr>d  s)      ++A$*Q-++++++r*   c                 ^    g | ]*}t          j        |          t          j        |          f+S rc   rz  r  r  r&   vss     r(   r)   z'hvGridExplorer.ylim.<locals>.<listcomp>e  -    JJJR29R==")B--8JJJr*   )r  rR   r   r   rg   r$  rv   s   `  r(   r   zhvGridExplorer.ylim_  sY    G!T"" 	A+++++++JJ6JJJKKKr*   c                 
    g dS )N)r   r   r   rc   rm   s    r(   rL  zhvGridExplorer._groupsg  s    ////r*   c                    | j         j        }t          | j         dg           fd|D             }| j        D ]
}|dk    r
| j        |         }t	          |t          j                  r|dv r|_        n||_        |dk    r.t          | |d           t          | ||j        d                    x|dk    r.t          | |d           t          | ||j        d                    |d	k    rXt          t          | |g                     dk    r6t          |j                  d
k    rt          | ||j        d
d                     d S )Nri  c                     g | ]}|v|	S rc   rc   rk  s     r(   r)   z,hvGridExplorer._populate.<locals>.<listcomp>n  rl  r*   r   )r#  r$  r.  r/  r#  r   r$  r
   r.     )	r   rm  rn  rQ   rR   r   r   ro  ry  rp  s        @r(   rQ  zhvGridExplorer._populatek  sg   O-	$/9b99GGGGGGGZ 	8 	8E
5!A!U^,, 8777 'AII 2AI C<<GD%$>$>$FD%16666c\\gdE4&@&@&HD%16666i''CeR0H0H,I,IQ,N,NSVWXW`SaSadeSeSeD%122777!	8 	8r*   )rx   ry   rz   rQ   r   r,  r   rf   r}   r  r  r  r   r   r   rL  rQ  r~   r   s   @r(   r  r  2  s(       5>'5<@@@D' ' ' ' '    X _ _ X_ _ _ X_ U]36 6 6 U]3	""L L #"L 0 0 X08 8 8 8 8 8 8r*   r  c                   0   e Zd Z ej                    Z ej        ded                   Zed             Z	ed             Z
ed             Zed             Zed             Z ej        d	          d
             Z ej        dd          d             ZdS )r  scatterr"   r   c                     dS )Nrh   rc   rm   s    r(   r  zhvDataFrameExplorer._var_name  r  r*   c                 X    | j         dv rdS | j        | j                 }|j        j         dv S )N)r   boxr   Fr   )r   rd   r#  r   r  s     r(   xcatzhvDataFrameExplorer.xcat  s3    90005DF#| E))r*   c                 Z    | j         | j        j         p| j        j        d         n| j         S r  )r#  r   rm  rm   s    r(   r  zhvDataFrameExplorer._x  s)    FJfn!AT_%>q%AZ^Z``r*   c                 2   d| j         j        v r| j        r| j        }nId| j         j        vr| j        r| j        }n,| j                            | j        | j        d | j                  }t          |t                    rt          |          dk    r|d         }|S )Nr%  r
   r   )rM  rP   r%  r$  r   _process_chart_yrd   r  r  rR   r   ry  )rg   r$  s     r(   r  zhvDataFrameExplorer._y  s    111dl1AAdn777DF7AA00TWdDN[[Aa 	3q66Q;;!Ar*   c                     dgS )Nr   rc   rm   s    r(   rL  zhvDataFrameExplorer._groups  s
    }r*   r#  c                 z   | j         dk    r| j        j        j        }n	 | j        | j                  }n#  Y dS xY wt	          |d          r|                                }|j        j        dv rd S t          |          st          j
        t          j
        fS t          j        |          t          j        |          fS )Nindexr  compute_chunk_sizesr   )r  rd   r  rv   hasattrr  r   r   ry  rz  nanr  r  r  s     r(   r   zhvDataFrameExplorer.xlim  s    7gZ%,FFDG,tt6011 	2//11F<%%4V 	$FBF##	&!!29V#4#455s   2 7r$  r%  c                       j         }t          |t                    s|g}d  fd|D             D             }t          |          st          j        t          j        fS t          d |D                       S )Nc                 0    g | ]}t          |          |S rc   )ry  )r&   yss     r(   r)   z,hvDataFrameExplorer.ylim.<locals>.<listcomp>  s#    EEESWWE"EEEr*   c              3   2   K   | ]}j         |         V  d S r   r  r  s     r(   r   z+hvDataFrameExplorer.ylim.<locals>.<genexpr>  s)      99!
1999999r*   c                 ^    g | ]*}t          j        |          t          j        |          f+S rc   r  r  s     r(   r)   z,hvDataFrameExplorer.ylim.<locals>.<listcomp>  r  r*   )r  rR   r   ry  rz  r  r   r  s   `  r(   r   zhvDataFrameExplorer.ylim  s    G!T"" 	AEE9999q999EEE6{{ 	$FBF##JJ6JJJKKKr*   N)rx   ry   rz   rQ   r   zr,  r   r}   r  r  r  r  rL  r   r   r   rc   r*   r(   r  r    s       A5>)U5\BBBD  X * * X* a a Xa 	 	 X	   X U]36 6 6" U]3	""L L #"L L Lr*   r  )NN);	holoviewsr  numpyrz  panelrV   rQ   holoviews.core.utilr   r   r   r   holoviews.elementr   holoviews.plotting.utilr   panel.viewabler	   rd  r   r   plottingr   r  utilr   r   r   r   r  _kind_mapping_gridded_types_geom_typesr,  r   _default_cmapsr   r   r   r   r  r}  rU   rG   r\   r^   r   r   r   r   r   r  r  Parameterizedr  rC   r  r  r  rc   r*   r(   <module>r     s                O O O O O O O O O O O O * * * * * * . . . . . . ! ! ! ! ! ! 9 9 9 9 9 9 ' ' ' ' ' ' A A A A A A A A A A
 L&''L'((	)L$%%	& 	XJ	  vcc,566i[9I9IIJJ$
	 
	 TSSV[\eVffinouivvdRRRgvcc%,uY/??%-OPPQQe>>jjll>>>+   FVVL)))	   BAA 4  4  4F   .P P P P Pv P P P*5' 5' 5' 5' 5'8 5' 5' 5'p' ' ' ' 'H ' ' '
9 9 9 9 98 9 9 9x    X   *^% ^% ^% ^% ^% ^% ^% ^%B'5 '5 '5 '5 '5 '5 '5 '5T	N 	N 	N 	N 	Nx 	N 	N 	NM M M M M# M M Me e e e eV e e eP( ( ( ( (^ ( ( (@M8 M8 M8 M8 M8^ M8 M8 M8`?L ?L ?L ?L ?L. ?L ?L ?L ?L ?Lr*   