
    I.eou                        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* G d de          Z+ G d de+          Z, G d d e+          Z- G d! d"e+          Z. G d# d$e+          Z/ G d% d&e+          Z0 G d' d(e+          Z1 G d) d*e+          Z2 G d+ d,ej3                  Z4 G d- d.e          Z5 G d/ d0e5          Z6 G d1 d2e5          Z7 G d3 d4e5          Z8dS )5    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tiles)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   /   s    @ #D33F333r*   c                   b     e Zd Z ej        ed          ZdZ fdZd Z	e
d             Z xZS )Controls)class_
precedenceTc                    || _          t                      j        di | i }| j        D ]:}t	          | j        |         t          j        t          j        f          rddi||<   ;t          j        | j        dd|          | _	        d S )N	throttledTFstretch_width)	show_namesizing_modewidgets )
_datasuper__init__param
isinstanceNumberRangepnParam	_controls)selfdfparamswidget_kwargsp	__class__s        r(   rV   zControls.__init__X   s    
""6""" 	7 	7A$*Q-%,)DEE 7$/#6a J'!	
 
 
r*   c                     | j         S N)r]   r^   s    r(   	__panel__zControls.__panel__f   s
    ~r*   c                 l    d | j                                                                         D             S )Nc                 2    i | ]\  }}|d v	||dk    ||S ))namerG   N rS   r&   kvs      r(   
<dictcomp>z#Controls.kwargs.<locals>.<dictcomp>k   s@     P P PA000Q]qBww 1GNwwr*   )rW   valuesitemsrf   s    r(   rF   zControls.kwargsi   sB    P P!2!2!4!4!:!:!<!< P P P 	Pr*   )__name__
__module____qualname__rW   ClassSelectorr	   rG   _Controls__abstractrV   rg   propertyrF   __classcell__rc   s   @r(   rI   rI   R   s        "u"&R@@@HJ
 
 
 
 
   P P XP P P P Pr*   rI   c                   n    e Zd Z ej                    Z ej        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	          Z fd
Zed             Z ej        dddd          d             Z xZS )Colormappinglinear)r|   logeq_histdefaultobjectsNr   Colormap)r   labelr   TFc                      t                      j        |fi | d|vr,| j        j        j                            dd          | _        d S d S )N	symmetricF)rU   rV   rG   
_converter
_plot_optsgetr   r^   rE   r`   rc   s      r(   rV   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colorrT   rf   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_CMAPSrp   rG   r   r   r   r   colorbarr   rT   dtype)r^   keyr   s      r(   _update_coloroptszColormapping._update_coloropts   s     	49D9M9M9O9O4P4P#P#PF=!===!%=++XC DMMZ4:%%:dj)/4Du}}# !F!#&			r*   )rr   rs   rt   rW   rZ   climSelectorcnormStringr   Booleanr   r   CMAPSr   rescale_discrete_levelsr   rV   rw   r   dependsr   rx   ry   s   @r(   r{   r{   o   s.       5;==DEN85Q5Q5QRRREEL&&&Eu}T***H5>-"9 *E; ; ;D ,emD999e,,,I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)rr   rs   rt   rW   	MagnitudealpharS   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rightr   Fr   N)r   N)r   boundsTc                 d     t                      j        |fi | |                                  d S re   )rU   rV   _update_rangesr   s      r(   rV   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
   rJ   )rG   xlimr   _convert_to_intrW   rL   r   ylim)r^   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)rX   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*   )rr   rs   rt   rW   r   r   _legend_positionslegendr   logxlogyIntegerheightwidth
responsiveshared_axesrZ   r   r   rV   r   r   staticmethodr   rx   ry   s   @r(   r   r      sZ       U^G\5STTTF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          Z ej	        dd          Z
 ej        d	d
d          ZdS )LabelszTitle for the plot)doczAxis labels for the x-axis.zAxis labels for the y-axis.zAxis labels for the colorbar.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   )r   h  z\
        Rotates the axis ticks along the x-axis by the specified
        number of degrees.)r   r   r   N)rr   rs   rt   rW   r   titlexlabelylabelclabelrY   	fontscaler   rotrS   r*   r(   r   r      s        EL1222EU\;<<<FU\;<<<FU\=>>>FQ -C D D DI %-( 9   CCCr*   r   c                      e Z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 ej
        ded          Z ej        ddd          d             ZdS )
GeographicFzu
        Whether the plot should be treated as geographic (and assume
        PlateCarree, i.e. lat/lon coordinates).r   Nzu
        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'.r   r   r   110m)r   50m10mz3
        The scale at which to render the features.z
        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'.geoTr   on_initc                 >   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        _        | j        |d         | _        | j        d| _        | j        
dg| _        d S d S )Nr   )CRSc              3   P   K   | ]!}|                     d           s
|dk    |V  "dS )_r   N)
startswith)r&   rm   s     r(   	<genexpr>z4Geographic._update_crs_projection.<locals>.<genexpr>%  sH       
 
<<$$
)*e )3
 
r*   GOOGLE_MERCATORPlateCarreeTr,   )boolr   r8   GEO_KEYSrW   constantcartopy.crsr   sortedconcrete_descendentskeysinsertremover3   r   r5   r7   r9   )r^   enabledr   r   crs_lists        r(   _update_crs_projectionz!Geographic._update_crs_projection  s9   tx/4<00 	3 	3C+2{DJsO$$ 	F###### 
 
1#66;;==
 
 
 
 
 	,---=)))&&&!)
(0
%?"&qkDO%!%D= (MDMMM ! r*   )rr   rs   rt   rW   r   r   r   r3   Dictr4   ObjectSelectorr5   r6   r7   r8   ListSelectorGEO_FEATURESr9   r:   	GEO_TILESr;   r   r   rS   r*   r(   r   r      s       
%- ,3 4 4 4C %. ,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 !E y G' ( ( (E
 U]5t444* * 54* * *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   	rasterizerf   s    r(   _toggle_rasterizezOperations._toggle_rasterizeP  !    > 	#"DNNN	# 	#r*   r   c                 &    | j         r	d| _        d S d S r   )r   r   rf   s    r(   _toggle_datashadezOperations._toggle_datashadeU  r   r*   r   c                     | j         p| j        }| | j        j        _        | | j        j        _        | | j        j        _        | | j        j        _        d S re   )r   r   rW   	dynspreadr   
x_sampling
y_sampling
aggregator)r^   r   s     r(   _update_optionszOperations._update_optionsZ  sR    .2DN,3
%-4
&-4
&-4
&&&r*   )rr   rs   rt   rW   r   r   r   r   AGGREGATORSr   r   rY   r   r   r   r   r   r   rS   r*   r(   r   r   9  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                   4    e Zd Z ej        i dd          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   r   r   N)rr   rs   rt   rW   r   optsrS   r*   r(   r  r  c  s1        5:b(; B1 2 2 2DDDr*   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)rr   rs   rt   rW   r   live_updaterS   r*   r(   r  r  m  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   )rK   rJ   z#
        Code to generate the plot.)rL   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   r`   s      r(   rD   zhvPlotExplorer.from_data  sS    4   	&EFFFt__ 	& CC%Cs4""6"""r*   c                     | j         S re   )_layoutrf   s    r(   rg   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          j         j        g dd	d
dg |di           _         j                             j        d            j                             j        d            j                             j        d                                             t          j        dd           _        t/          d i | _        t          j         j        d
t          j                   _        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           _%        t          j!        &                    d	d           _'        t          j(         j#        t          j         j        t          j        d j%        j)        fd j'        f          d	           j        t          j)        *                                d           _+         j        ,                    d           d S )!Nxyy_multic                 X    i | ]&}|t           j        v |                    |          'S rS   )r  rW   pop)r&   rm   r`   s     r(   ro   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s<     
 
 
IO## vzz!}}###r*   c                 "    i | ]\  }}|d v	||S ))r  r  r  rS   rl   s      r(   ro   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s)    QQQ1!;P2P2Pq!2P2P2Pr*   c                 N    i | ]!}|j         v|                    |          "S rS   rW   r  )r&   rm   r`   r^   s     r(   ro   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s<     
 
 

"" vzz!}}"""r*   c                 *    i | ]}|t           |         S rS   )KINDS)r&   groups     r(   ro   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  s    @@@%%u@@@r*   )r   r  r  groupbybyrO   Fr   )optionsgroups)
parametersrQ   rP   rR   r  lefti  )tabs_locationr   )rP   default_layoutc                     g | ]=}t          |t          j                  t          |j        t
                    6|j        >S rS   )rX   rW   ru   
issubclassrK   rI   )r&   rb   s     r(   r)   z+hvPlotExplorer.__init__.<locals>.<listcomp>  sS     
 
 
!U011
 18X..	
H
 
 
r*   c                 N    i | ]!}|j         v |                    |          "S rS   r  )r&   rm   r  extrass     r(   ro   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   )rj   lower)r&   r  cparamsr_   r^   s      r(   ro   z+hvPlotExplorer.__init__.<locals>.<dictcomp>  sR     
 
 
W HNNcc"??t?w??
 
 
r*   danger)
alert_typevisiblerQ   )      r-  r.  )rQ   margin)r-  r.  r   r.  PlotCode)rQ   stretch_bothrS   )-r   rX   r   r  copyr   rq   rU   rV   rT   r   _groupsr[   r\   rW   r]   r   _toggle_controls_check_y	_check_by	_populateTabs_control_tabsr  	statusbarRow
_statusbarr   rp   r	  _controllersupdate_refreshpaneAlert_alert	HoloViews_hv_paneMarkdown
_code_paneColumnlayoutHSpacerr  trigger)r^   r_   r`   r  r  statusbar_params	converterr  controlscontroller_params
controllerr  r&  rc   s   ```        @@r(   rV   zhvPlotExplorer.__init__  s   zz#

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

3W]^aWbVcF9
 
 
 
[[]]
 
 

 !1
 
QQQQQ
 
	

 
 
 
 
[[]]
 
 

 	""6"""
#@@4<@@@J#F#F#F'5v>>?
 
 

 	
.777
	222
...W 
 
 
 #66%566(4>USUSYZZZ
 
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 $ 
 
 ))on)]]'**~*^^yKF" !568QRR+   OI&
 
 
 	
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 rS   rS   r&   rn   rR  s     r(   r)   z,hvPlotExplorer._populate.<locals>.<listcomp>  #    GGGAaw6F6Fa6F6F6Fr*   r   r  r  Nr   )r   	variablesgetattrrW   rX   r   r   setattrr^   rV  variables_no_indexpnamerb   rR  s        @r(   r8  zhvPlotExplorer._populate  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           	      j   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%        _&        d| j'        _(        n;# tR          $ 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 rS   rS   )r&   featurer:   s     r(   ro   z(hvPlotExplorer._plot.<locals>.<dictcomp>'  s    !c!c!cW'=!c!c!cr*   r9   i  
min_heightr!   r   r   )nTr   r  r  r  r  Fz+**Rendering failed with following error**: )objectr,  rS   )*r]   r  r  r  rX   r   lenrW   rp   r   r   r  rF   r   rI   r?  npr>   absr   
geographicr3   r  r   rT   MAX_ROWSr   r  sampler  loading_hvPlotr  r  r  _hvplotr  rE  rc  rC  r,  	Exception)r^   eventsr  rF   rn   opts_kwargsxmaxr   r4   r_   er:   s              @r(   _plotzhvPlotExplorer._plot  sa   %)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 "'DK 	 	 	K$$HQHH %        	 $)DL   5DL ((((s1   5A%K L$ 
L%$L	L$ LL$ $L2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
```)
r;  r  rr  rW   parameterizeddiscard_events	plot_codecoderG  rc  )r^   rn  s     r(   r@  zhvPlotExplorer._refresh>  s    ~) 	F

 //55 	) 	)((DI	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)!C!C!C!Cs   A((A,/A,c                     dS )NrE   rS   rf   s    r(   	_var_namezhvPlotExplorer._var_nameF  s    vr*   c                 2    | j         t          d         v rdS dS )Nr   TF)r   r  rf   s    r(   	_single_yzhvPlotExplorer._single_yJ  s    9d##4ur*   c                      t          d          )Nz"Must be implemented by subclasses.)NotImplementedErrorrf   s    r(   r4  zhvPlotExplorer._groupsP  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t          j        | j        ddiddidd          fdt          j        | j        dddiid          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   rb  )r   r   density)r   r  r  r  )r   r  r  r  r  Fieldsr   rN   )r   r   )rR   rP   r   r   r   r   r   r  )arear   lineohlcrgbstepr-  r{   )newr  r  r]   r  r[   r\   axesr   style
operationsrg  advancedr   colormappingr:  )r^   eventr,  r  tabss        r(   r5  zhvPlotExplorer._toggle_controlsT  s    		CUY"666 ),JGG 	CuyE$K//<<<JJ 	Cuy$>>>DF===JJBBBJ$.! 4>*+ 	D$)($/($/6 6 #$ $ $ % 28DKK.:"$ $ $ % $*%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
   )rd  r  r  oldr  r^   r  s     r(   r6  zhvPlotExplorer._check_yw  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  r]   r  r  rd  r  r  s     r(   r7  zhvPlotExplorer._check_by{  sa    9 	dn&???DL?UXY]YeUfUfijUjUjDGGG	 	????UjUjr*   c                 4    | j                                         S )z/Return the plot as a HoloViews object.
        )rl  clonerf   s    r(   hvplotzhvPlotExplorer.hvplot  s     |!!###r*   c                     |                                  }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.
        rk   z	.hvplot(
z
)z.opts(
)settings_build_kwargs_stringry  r  r  )r^   var_namer  settings_argssnippetr  	opts_argss          r(   rv  zhvPlotExplorer.plot_code  s     ==?? 	@ 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 )Nrk   z    =z,
rJ   )rq   )r^   rF   argsrm   rn   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saverl  )r^   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)
        rj   rG   r   r  r  r  Nc                     i | ]\  }}||	S rS   rS   rl   s      r(   ro   z+hvPlotExplorer.settings.<locals>.<dictcomp>  s    DDDTQAqDDDr*   )r>  rp   setrW   rW  r   r]   r  r  r   r   rq   )r^   r  rP  r`   rb   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*   re   )3rr   rs   rt   rW   r   r   r  r  r   r  r  r  ru   r   r  r{   r  r   r   r   rg  r   r  r  r;  r   r  r  r  r   rw  classmethodrD   rg   rV   r8  rr  r@  rw   ry  r{  r4  r5  r6  r7  r  rv  r  r  r  rx   ry   s   @r(   rC   rC   s  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 # # [#  S# S# S# S# S#j7 7 7*.) .) .)`D D D   X   X
 H H XH!% !% !% !%F    $ $ $
   0  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gdfrS   rf   s    r(   ry  zhvGeomExplorer._var_name  s    ur*   c                     dS r   rS   rf   s    r(   r{  zhvGeomExplorer._single_y      tr*   c                     d S re   rS   rf   s    r(   _xzhvGeomExplorer._x  r  r*   c                     d S re   rS   rf   s    r(   _yzhvGeomExplorer._y  r  r*   r  c                     d S re   rS   rf   s    r(   r   zhvGeomExplorer.xlim      r*   r  c                     d S re   rS   rf   s    r(   r   zhvGeomExplorer.ylim  r  r*   c                 
    ddgS )Nr   r   rS   rf   s    r(   r4  zhvGeomExplorer._groups  s    ;''r*   )rr   rs   rt   rW   r   r  r   rw   ry  r{  r  r  r   r   r   r4  rS   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   rk   r
   z['z']variable.z0.to_array('variable').transpose(..., 'variable')r   r  )xarrayrX   Datasetr   	data_varsrd  to_array	transpose_var_name_suffixrU   rV   )r^   dsr`   xrvar_name_suffixr  rc   s         r(   rV   zhvGridExplorer.__init__  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  rf   s    r(   ry  zhvGridExplorer._var_name  s#      	/-///4r*   c                 Z    | j         | j        j         p| j        j        d         n| j         S Nr   )r  r   rR  rf   s    r(   r  zhvGridExplorer._x  )    DHFN!?T_%<Q%?X\X^^r*   c                 Z    | j         | j        j         p| j        j        d         n| j         S r  )r  r   rR  rf   s    r(   r  zhvGridExplorer._y  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   )rT   r  r   r   re  nanminnanmaxr^   rp   s     r(   r   zhvGridExplorer.xlim  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 re   rT   r&   r  r^   s     r(   r   z&hvGridExplorer.ylim.<locals>.<genexpr>"  s)      ++A$*Q-++++++r*   c                 ^    g | ]*}t          j        |          t          j        |          f+S rS   re  r  r  r&   vss     r(   r)   z'hvGridExplorer.ylim.<locals>.<listcomp>#  -    JJJR29R==")B--8JJJr*   )r  rX   r   r   r^   r  rp   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   rS   rf   s    r(   r4  zhvGridExplorer._groups%  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 )NrR  c                     g | ]}|v|	S rS   rS   rT  s     r(   r)   z,hvGridExplorer._populate.<locals>.<listcomp>,  rU  r*   r   )r  r  r  r  r  r   r  r
   r     )	r   rV  rW  rW   rX   r   r   rX  rd  rY  s        @r(   r8  zhvGridExplorer._populate)  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*   )rr   rs   rt   rW   r   r  r   rV   rw   ry  r  r  r   r   r   r4  r8  rx   ry   s   @r(   r
  r
    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  r  r"   r   c                     dS )Nr_   rS   rf   s    r(   ry  zhvDataFrameExplorer._var_nameF  r  r*   c                 X    | j         dv rdS | j        | j                 }|j        j         dv S )N)r   boxr   Fr   )r   rT   r  r   r  s     r(   xcatzhvDataFrameExplorer.xcatJ  s3    90005DF#| E))r*   c                 Z    | j         | j        j         p| j        j        d         n| j         S r  )r  r   rV  rf   s    r(   r  zhvDataFrameExplorer._xQ  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   )r]   r  r  r  r   _process_chart_yrT   r  r{  rX   r   rd  )r^   r  s     r(   r  zhvDataFrameExplorer._yU  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   rS   rf   s    r(   r4  zhvDataFrameExplorer._groupsa  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  rT   r  rp   hasattrr  r   r   rd  re  nanr  r  r  s     r(   r   zhvDataFrameExplorer.xlime  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 rS   )rd  )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 re   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 rS   r  r  s     r(   r)   z,hvDataFrameExplorer.ylim.<locals>.<listcomp>  r  r*   )r  rX   r   rd  re  r  r   r  s   `  r(   r   zhvDataFrameExplorer.ylimw  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)rr   rs   rt   rW   r   zr  r   rw   ry  r  r  r  r4  r   r   r   rS   r*   r(   r  r  @  s       A5>&%,???D  X * * X* a a Xa 	 	 X	   X U]36 6 6" U]3	""L L #"L L Lr*   r  )9	holoviewsr  numpyre  panelr[   rW   holoviews.core.utilr   r   r   r   holoviews.elementr   holoviews.plotting.utilr   panel.viewabler	   rM  r   r   plottingr   rk  utilr   r   r   r   r  _kind_mapping_gridded_types_geom_typesr  r   _default_cmapsr   r   r   r   r   rh  rG   rI   r{   r   r   r   r   r   r  Parameterizedr  rC   r  r
  r  rS   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:-' -' -' -' -'8 -' -' -'`' ' ' ' 'H ' ' '
9 9 9 9 98 9 9 9x    X   &C* C* C* C* C* C* C* C*L'5 '5 '5 '5 '5 '5 '5 '5T2 2 2 2 2x 2 2 2M M M M M# M M MZ Z Z Z ZV Z Z Zz
( ( ( ( (^ ( ( (@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*   