
    e0i                        d dl mZ d dlZd dlZd dlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZmZmZmZmZmZmZ ddlmZ  G d de          Z  G d de          Z! G d de          Z" ej#        dg d          Z$ ej#        dd          Z% edd          Z& G d dej'                  Z( G d de(          Z) G d d          Z* G d  d!e*          Z+ G d" d#e*          Z, G d$ d%e*          Z-d& Z.dS )'    )
namedtupleN)
bothmethod   )Dataset)ElementLayout)AdjointLayout)CallbackErrorStore)	NdOverlayOverlay)	GridSpace)CrossFilterSetDerivedPipe	PlotResetSelectionExprSequence
SelectModeStream)
DynamicMapc                   4    e Zd Z ej        ddd          ZdS )_CmapNT)default
allow_Noneconstant)__name__
__module____qualname__param	Parametercmap     3lib/python3.11/site-packages/holoviews/selection.pyr   r      s&        5?4D4HHHDDDr#   r   c                   4    e Zd Z ej        ddd          ZdS )_SelectionExprOverrideNTz=
            dim expression of the current selection override)r   r   doc)r   r   r   r   r    selection_exprr"   r#   r$   r&   r&      s4        $U_TD G@ A A ANNNr#   r&   c                   V     e Zd Z ej        d          Z fdZed             Z xZ	S )_SelectionExprLayersT)r   c                 D     t                      j        ||gfddi| d S )N	exclusiveT)super__init__)selfexpr_overridecross_filter_setparams	__class__s       r$   r.   z_SelectionExprLayers.__init__%   sF    ,-	
 	
9=	
AG	
 	
 	
 	
 	
r#   c                 ~    |d         }|d         }|                     dd           dd|d         giS dd|d         giS )Nr   r   r(   exprsT)get)clsstream_values	constantsoverride_expr_valuescross_filter_set_valuess        r$   transform_functionz'_SelectionExprLayers.transform_function*   s]    ,Q/"/"2##$4d;;Gd$89I$JKLLd$;<L$MNOOr#   )
r   r   r   r   Listr5   r.   classmethodr<   __classcell__r3   s   @r$   r*   r*   "   sn        EJ%%%E
 
 
 
 

 P P [P P P P Pr#   r*   Stylesg      ?colorsalphaRegionElement)region_elementSelectionStreamsz'style_stream exprs_stream cmap_streams c                        e Zd ZdZ ej        dd          Z ej        dd          Ze fd            Z	d Z
d	 Zd
 ZddZed             Zd Z xZS )_base_link_selectionsa  
    Baseclass for linked selection functions.

    Subclasses override the _build_selection_streams class method to construct
    a _SelectionStreams namedtuple instance that includes the required streams
    for implementing linked selections.

    Subclasses also override the _expr_stream_updated method. This allows
    subclasses to control whether new selections override prior selections or
    whether they are combined with prior selections
    Fz@
        Whether to link any streams on the input to the output.r   r'   Tz3
        Whether to highlight the selected regions.c                      t                      j        di |}t          |j                  |_        t                      |_        i |_        i |_        | 	                    |          |_
        |S )N)moder"   )r-   instancer   cross_filter_mode_cross_filter_streamr&   _selection_override_selection_expr_streams_plot_reset_streams_build_selection_streams_selection_streamsself_or_clsr2   instr3   s      r$   rM   z_base_link_selections.instanceQ   sr    uww))&)) %38N$O$O$O!#9#;#; ')$#%  #."F"Ft"L"Lr#   c                     |j         dk    r	d| _        d S |j         dk    r	d| _        d S |j         dk    r	d| _        d S |j         dk    r	d| _        d S d S )Nreplace	overwriteappendunion	intersectsubtractinverse)newselection_mode)r/   events     r$   _update_modez"_base_link_selections._update_mode`   sv    9	!!"-DY(""")DY+%%"-DY*$$"+D %$r#   c                    ddl m} t          || j        | j        | j                  }|| j        |<   | j                            |           t          |          | j
        |<   |j        fd}t          ||          s0t          |          }|j                            | j        d           | j
        |         j                            |dg           dS )	z
        Register an Element or DynamicMap that may be capable of generating
        selection expressions in response to user interaction events
        r   )Table)rL   include_region
index_cols)sourcec                 ^    | r*|                                  |                                 d S d S N)clear_historyrb   	resettingstreams     r$   clear_stream_historyz=_base_link_selections._register.<locals>.clear_stream_history}   s7     $$&&& r#   rL   rm   N)elementre   r   ra   show_regionsrg   rQ   rO   append_input_streamr   rR   history_stream
isinstancer   r   watchrc   )r/   hvobjre   selection_expr_seqro   mode_streams         r$   	_registerz_base_link_selections._registerj   s   
 	#""""" 3+,
 
 

 /A$U+!556HIII*35*A*A*A ' 4F3T 	 	 	 	
 %'' 	?$E222K##D$5v>>> '-33 ;-	
 	
 	
 	
 	
r#   c                      | j         j        di | t          j        t          j        vrt          dt          j        z            |                     |                                          S )NzCannot perform link_selections operation since the selected backend %r is not loaded. Load the plotting extension with hv.extension or import the plotting backend explicitly.r"   )r   updater   current_backend	renderersRuntimeError_selection_transformclone)r/   rv   kwargss      r$   __call__z_base_link_selections.__call__   ss    
##F### 77  5 8=7L	 M N N N ((777r#   r"   c           	         
 ddl m} t          t                    rމj        }t          |j                  dk    r2t           fd|j        D                                                       S  |           t          j
        t                    r                                t          j        t          j                 j
                 }|                                                   j         j                            d           j                  S t          j
        t                    rMt-          j        dd          dk    r3t           fd|j        D                                                       S t-          j        dd          d	k    r<|j        d
         }                     |                              |j                  S  j                            d           S t          t                    rt          j        t          j                 t                             }t-          |dd                               j                  }                     |           |                    |                               j        | j                            |d           j                  S S t          t<          t          t>          t@          tB          f          rtE           fd#                                D                       
t          t>                    rF
fd}t          |          }	tI          
%                                          |	j        j        dd<   n9                    
          }	tM          |	d          r|	                                }	|	S S )zs
        Transform an input HoloViews object into a dynamic object with linked
        selections enabled.
        r   )initialize_dynamicc                 :    g | ]}                     |          S r"   r   ).0elr/   s     r$   
<listcomp>z>_base_link_selections._selection_transform.<locals>.<listcomp>   s4          68D--b11     r#   N)cachenamedynamic_mulc                 >    g | ]}                     |           S )
operationsr   )r   r   r   r/   s     r$   r   z>_base_link_selections._selection_transform.<locals>.<listcomp>   s<           --bZ-HH     r#   dynamic_operationr   r   zQlinked selection: Encountered DynamicMap that we don't know how to recurse into:
selection_displaylinkc                 F    g | ]\  }}|                     |          fS r"   r   )r   kvr   r/   s      r$   r   z>_base_link_selections._selection_transform.<locals>.<listcomp>   sB     < < <%)Q T66q*EEF < < <r#   c                  2   g }                                 D ]e\  }}t          |d                   D ]J\  }}|t          |          k    r|                    g            ||                             ||f           Kft	          fd|D                       S )Nr"   c                 :    g | ]}                     |          S r"   )r   )r   nrv   s     r$   r   zO_base_link_selections._selection_transform.<locals>.compose.<locals>.<listcomp>   s#    #@#@#@qEKKNN#@#@#@r#   )items	enumeratelenr[   r   )	argsr   r`   r   r   ir   datarv   s	          r$   composez;_base_link_selections._selection_transform.<locals>.compose   s    C $

 3 31%.qu%5%5 3 3EAr CHH}} #

2FMM1b'22223 ##@#@#@#@C#@#@#@AAAr#   collate)'plotting.utilr   rt   r   callbackr   inputsr   r   
issubclasstyper   ry   r   registryr|   r   build_selectionrT   rQ   r6   _cachegetattrr   apply	operationr   warningr   link_inputsr   r   r   r	   dictr   listvalueshasattr)r/   rv   r   r   r   chartobjrp   r   	new_hvobjr   s   ```       @r$   r   z*_base_link_selections._selection_transform   s   
 	655555eZ(( @	~H8?##a''        <DO       799 u%%%%*g.. u%%%u'<=ejI..u55EE+UJ044UDAA F    UZ11 %.&$77=HH          &o        799 66:MMMoa(000LLRR&( ( ( 
""7-27 7   w''  	N5#89$u++FEu1488D++4+;+<<w'''..w77GG+Wj044WdCC4; H    LI}UVV 	 < < < < <-2[[]]< < < = =D%++ 4B B B B B B 'w//	/3DKKMM/B/B	")!!!,,!KK--	9i00 4 ) 1 1 3 3I Lr#   c                     t                      )zg
        Subclasses should override this method to return a _SelectionStreams
        instance
        NotImplementedError)r7   rW   s     r$   rS   z._base_link_selections._build_selection_streams   s     "###r#   c                     t                      )a  
        Called when one of the registered HoloViews objects produces a new
        selection expression.  Subclasses should override this method, and
        they should use the input expression to update the `exprs_stream`
        property of the _SelectionStreams instance that was produced by
        the _build_selection_streams.

        Subclasses have the flexibility to control whether the new selection
        express overrides previous selections, or whether it is combined with
        previous selections.
        r   )r/   rv   r(   bboxrF   r   s         r$   _expr_stream_updatedz*_base_link_selections._expr_stream_updated   s     "###r#   )r"   )r   r   r   __doc__r   Booleanr   rq   r   rM   rc   ry   r   r   r>   rS   r   r?   r@   s   @r$   rI   rI   >   s       
 
  %- 4C D D DK !5= 46 7 7 7L     Z, , ,
 
 
@8 8 8F F F FP $ $ [$$ $ $ $ $ $ $r#   rI   c                       e Zd ZdZ ej        ddgdd          Z ej        dd          Z ej	        dd	          Z
 ej        dd
d          Z ej        g ddd          Z ej        dd          Z ej        dd          Ze fd            Z ej        dd
          d             Zd ZddZed             Zed             Zed             Zed             Z xZS )link_selectionsz
    Operation which automatically links selections between elements
    in the supplied HoloViews object. Can be used a single time or
    be used as an instance to apply the linked selections across
    multiple objects.
    rZ   r]   zP
        Determines how to combine selections across different
        elements.)objectsr   r'   Na7  
        If provided, selection switches to index mode where all queries
        are expressed solely in terms of discrete values along the
        index_cols.  All Elements given to link_selections must define the index_cols, either as explicit dimensions or by sharing an underlying Dataset that defines them.rJ   zi
        dim expression of the current selection or None to indicate
        that everything is selected.Tz[
        Color of selected data, or None to use the original color of
        each element.)r   r   r'   )rZ   r]   r\   r_   zU
        Determines how to combine successive selections on the same
        element.g?z"
        Alpha of unselected data.z"
        Color of unselected data.c                      t                      j        di |}i |_        i |_        d|_        g |_        i |_        |                     |           |S )NTr"   )r-   rM   _obj_selections_obj_regions_reset_regions	_datasetsr   _install_param_callbacksrU   s      r$   rM   zlink_selections.instance  sb    uww))&))  "" ,,T222r#   r(   )ru   c                    | j         }| j        D ]\  }}}|j        }| j                            |i           x| j        |<   }||v r%||         }|                    |j                  c S |                                 t          	                    ||| j                  }|||<   |                    |r|j        n|           d S )Nr   )
r(   r   _plot_idr   r6   rb   r   clearSelectionDisplay_select)	r/   sel_exprpipedsrawrefds_cacher   sel_dss	            r$   _update_pipeszlink_selections._update_pipes-  s    &!^ 
	< 
	<MD"c+C*.+//#r*B*BBDKx8##)zztyz11111   %--b(DKHHF!'HXJJ3:FKKFJ;;;;
	< 
	<r#   c                     d}t          |t                    sd}t          |          }t          |j                  }| j                            |||f           |j        j        S )ao  
        Returns a parameter which reflects the current selection
        when applied to the supplied data, making it easy to create
        a callback which depends on the current selection.

        Args:
            data: A Dataset type or data which can be cast to a Dataset

        Returns:
            A parameter which reflects the current selection
        FTr   )rt   r   r   r   r   r[   r   )r/   r   r   r   s       r$   selection_paramzlink_selections.selection_param<  sd     $(( 	!C4==D###tT3/000zr#   c                     || j         n|}||S t          |t                    }|st          |          }||                    |                   }|r|n|j        S )aG  
        Filters the provided data based on the current state of the
        current selection expression.

        Args:
            data: A Dataset type or data which can be cast to a Dataset
            selection_expr: Optionally provide your own selection expression

        Returns:
            The filtered data
        )r(   rt   r   r   r   )r/   r   r(   expr
is_datasetfiltereds         r$   filterzlink_selections.filterP  si     '5&<t"".<Kg..
 	!4==D

4(()%8xx8=8r#   c                     fd}j                             |dg           fd}j                             |dg           fd}j                             |dg           fd}j                             |dg           fd	}j        j                             |dg           j                                        D ]8}|fd
}t          d|           |j        j                             |dg           9d S )Nc                      j                                         D ]"}|                                 j        |_        #d S rj   )rQ   r   resetra   rL   _rn   rW   s     r$   update_selection_modezGlink_selections._install_param_callbacks.<locals>.update_selection_modeg  sD    6==?? 2 2"12 2r#   ra   c                  \    j                                          j        j         _        d S rj   )rO   r   rN   rL   )r   rW   s    r$   update_cross_filter_modezJlink_selections._install_param_callbacks.<locals>.update_cross_filter_modeq  s,    %++----1-CD%***r#   rN   c                      j                                         D ]"}j        |_        |                                 #d S rj   )rQ   r   rq   rf   rb   r   s     r$   update_show_regionzDlink_selections._install_param_callbacks.<locals>.update_show_regiony  sE    6==??  (,(9% r#   rq   c                      j         }j        j         }t          |          t          |          k    r+j        rd_        j                            |           d S d S )NF)r(   )r(   rO   reprrq   rP   rb   )r   new_selection_exprcurrent_selection_exprrW   s      r$   update_selection_exprzGlink_selections._install_param_callbacks.<locals>.update_selection_expr  sr    !%!4%)%>%M"&''40F+G+GGG$ .(-D%(..>P.QQQQQ	 HGr#   r(   c                  |    j         j        }t          j                  t          |          k    r	|_        d S d S rj   )rO   r(   r   )r   r   rW   s     r$   selection_expr_changedzHlink_selections._install_param_callbacks.<locals>.selection_expr_changed  sE    !%!:!ID'((D1C,D,DDD&8### EDr#   c                 6    | r|                                  d S d S rj   )rk   rl   s     r$   ro   zFlink_selections._install_param_callbacks.<locals>.clear_stream_history  s,     +((*****+ +r#   zregistering reset for rm   )r   ru   rO   rQ   r   printplot_reset_stream)	rV   rW   r   r   r   r   r   rn   ro   s	    `       r$   r   z(link_selections._install_param_callbackse  s   	2 	2 	2 	2 	2 	
!$4#5	
 	
 	
	D 	D 	D 	D 	D 	
$':&;	
 	
 	
	 	 	 	 	
 	
 0	
 	
 	
	R 	R 	R 	R 	R 	
!$4#5	
 	
 	
	9 	9 	9 	9 	9
 	!'--"%5$6	
 	
 	

 299;; 	 	F7= + + + + *F333$*00${m   	 	r#   c                 @   t          j        j        gj                  t	          j                  t	          j                  gfd}j                            |g d           t          j
        j                  }t          |          S )NrB   r!   c                      j         j        g}                    |j                   d                             j                   d         #d                             j                   d S d S )NrB   r   r   r   )unselected_colorselected_colorrb   unselected_alphaunselected_cmapselected_cmap)r   rC   cmap_streamsrW   style_streams     r$   update_colorsz?link_selections._build_selection_streams.<locals>.update_colors  s    +T-@AFfD4IJJJO!!t';!<<<A*Q%%4+=%>>>>> +*r#   )r   r   r   )r   exprs_streamr   )_Stylesr   r   r   r   r   r   r   ru   r*   rP   rO   _SelectionStreams)r7   rW   r   r   r   r   s    `  @@r$   rS   z(link_selections._build_selection_streams  s     )4+>?'
 
 
 t+,,,t)***

	? 	? 	? 	? 	? 	? 	? 	
'a'a'abbb ,$d&?
 
 !%%%
 
 
 	
r#   c                 <    | j         dS t          | j                   S )z=
        The datashader colormap for unselected data
        N)r   _color_to_cmapr/   s    r$   r   zlink_selections.unselected_cmap  s#    
  (4d3444r#   c                 <    | j         dnt          | j                   S )z;
        The datashader colormap for selected data
        N)r   r   r   s    r$   r   zlink_selections.selected_cmap  s!    
 *2tttGZ8[8[[r#   rj   )r   r   r   r   r   SelectorrN   r=   rg   r    r(   Colorr   ra   	Magnituder   r   r   rM   dependsr   r   r   r   r>   rS   propertyr   r   r?   r@   s   @r$   r   r      s         'k*K F  
 D /o p p pJ
 %U_T 8( ) ) )N !U[$ E   N $U^>>> Z  N
 'us 9% & & & #u{4 6% & & &     Z  U]#4000< < 10<  (9 9 9 9* : : Z:z 
 
 [
B 5 5 X5 \ \ X\ \ \ \ \r#   r   c                   8    e Zd ZdZd ZddZedd            ZdS )r   z
    Base class for selection display classes.  Selection display classes are
    responsible for transforming an element (or DynamicMap that produces an
    element) into a HoloViews object that represents the current selection
    state.
    c                     | S rj   r"   )r/   rp   s     r$   r   zSelectionDisplay.__call__  s    r#   Nc                 &    |i }t                      rj   r   r/   selection_streamsrv   r   region_streamr   s         r$   r   z SelectionDisplay.build_selection  s    =E!###r#   c                 V   |i }ddl m}m} ddlm} t          ||          r| j        }d }|j        |v r/||j                 }||v r	||         }n!|                                 ni x}||j        <   	 |j	        j
        rK||                    |ddd          }|                    |j	                            ||                     }	n|j	        j        r)||                    |ddd          }|j        |         }	nt          | ||f          r_t!          |j	        d          rJ||                    |dd          }|                    |j	                            ||                     }	n1||                    |ddd	          }|                    |
          }	n# t$          $ rS}
t'          |
                              dd                              dd          }t+          d| d| d          |
d }
~
wt,          $ r}
t+          d|
z            |
d }
~
ww xY w|||<   n| }	|	S )Nr   )CurveSpread)dimTF)expandedflatstrictmask)
keep_indexr  )computer  r  )selection_mask" .zRlinked_selection aborted because it could not display selection for all elements: z on 'z'.zUlinked_selection aborted because it could not display selection for all elements: %s.)rp   r  r  util.transformr  rt   datasetr   r   	interfacegriddedr   r   r  multiilocr   selectKeyErrorstrrY   r
   	Exception)rp   r(   r   r  r  r  r  r  r   	selectione	key_errors               r$   r   zSelectionDisplay._select  s   =E********''''''nc** %	 oGD5(( !12!X--#N3DDNN$$$$5775!12Z$, D|-33GdQV_d3ee 'g.?.D.DWte.T.T U UII&, D|-33GeRW`e3ff 'T 2II%99 DggFWY_>`>` D|-33GUZ3[[ 'g.?.D.DWte.T.T U UII|-33GUW[di3jj 'd C CI q q qFFNN333;;CDD	# %iKT%i %i[b%i %i %i j jopq Z Z Z# %NPQ%R S SXYZZ (,H^$$Is&   2D.F! !
H+AG99HHHNNrj   )r   r   r   r   r   r   staticmethodr   r"   r#   r$   r   r     sa           $ $ $ $
 + + + \+ + +r#   r   c                       e Zd ZdZddZdS )NoOpSelectionDisplayz
    Selection display class that returns input element unchanged. For use with
    elements that don't support displaying selections.
    Nc                     |S rj   r"   r
  s         r$   r   z$NoOpSelectionDisplay.build_selection  s    r#   r(  )r   r   r   r   r   r"   r#   r$   r+  r+    s2         
     r#   r+  c                   X    e Zd ZdZddZd ZddZed	             Zd
 Z	d Z
ddZd ZdS )OverlaySelectionDisplayz
    Selection display base class that represents selections by overlaying
    colored subsets on top of the original element in an Overlay container.
    colorFTc                 z    t          |t          t          f          s	|g| _        n|| _        || _        || _        d S rj   )rt   r   tuplecolor_propsis_cmapsupports_region)r/   
color_propr3  r4  s       r$   r.   z OverlaySelectionDisplay.__init__&  sB    *tUm44 	* *|D)D.r#   c                 .      fd j         D             S )Nc                 *    i | ]}|j         rgnS r"   )r3  )r   r5  r/  r/   s     r$   
<dictcomp>z<OverlaySelectionDisplay._get_color_kwarg.<locals>.<dictcomp>/  s8     4 4 4 t|>UGG 4 4 4r#   )r2  )r/   r/  s   ``r$   _get_color_kwargz(OverlaySelectionDisplay._get_color_kwarg.  s7    4 4 4 4 4"&"24 4 4 	4r#   Nc                     ddl m} t          |j        j                  }|st                      S g }t          |          D ]m}	|j        g}
|	dk    r|                    d          n|}|j	        |	         }|
                     j        |g|
z   |	|d          }|                    |           nt          |          D ]C}	||	         }|j	        |	         }|j        |g}
|
                     j        |	|
d          }|||	<   D| j        r fd}||j        g}
|                    d          
                    ||
d	          }t          |t                     r|j        nt#          |          }t%          |d
d           dk    st'          ||          r|                    d|           n|                    |           t          |                                          S )Nr   )	HistogramFr   T)streamslayer_numberr   per_element)r=  r<  r>  c                 l    |d         }||                                  }                    ||          S )Nr   )_empty_region_style_region_element)rp   rF   rC   r   r   r/   s        r$   update_regionz>OverlaySelectionDisplay.build_selection.<locals>.update_regionP  s;    #)!9 !)%,%:%:%<%<N11.BRSSSr#   )link_dataset_selection_dims)rp   r;  r   r   rC   r   ranger   r   r   r   _build_layer_callbackr[   _apply_style_callbackr4  rt   r   r   r   r   insertr   )r/   r  rv   r   r  r   r;  
num_layerslayersr=  r<  r   cmap_streamlayerrB  regioneltypes   `                r$   r   z'OverlaySelectionDisplay.build_selection2  s5   &&&&&&*7>??
 	99!*-- 	! 	!L(56G-9Q->->%++5+)))EC+8FKII*[M'4I)D   E MM%    !*-- 	) 	)L<(E+8FK(5{CGKK*T    E $)F<   $)=$T T T T T %&7&DEG[[e[,,22='X]2^^F#-eZ#@#@QUZZd5kkFv0$771<<
6S\@]@]<a((((f%%%v&&(((r#   c                     g }|j         D ]=}t          |d          r|                    |          }|                    |           >|                    |          S )Nr!   r   r   )r   r   rM   r[   )r7   pipeliner!   r   ops        r$   _inject_cmap_in_pipelinez0OverlaySelectionDisplay._inject_cmap_in_pipeline`  sl    
% 	" 	"Br6"" ,[[d[++b!!!!  J 777r#   c                     |                      |||         |          }|j        }||                     ||          }||u r ||j                  S  ||          S rj   )r   rP  rR  r  )	r/   rp   r5   r=  r!   r   r   r%  rP  s	            r$   rF  z-OverlaySelectionDisplay._build_layer_callbacki  sl    LL%*=uEE	#44XtDDHi8GO,,,8I&&&r#   c                 h    i }|dk    rd|d<   nd}|||d<   |r||         nd } | j         |||fi |S )Nr   Fcolorbarr   r!   )_build_element_layer)	r/   rp   r=  rC   r!   rD   r   optsr/  s	            r$   rG  z-OverlaySelectionDisplay._apply_style_callbacks  sf    1$DEDL(.8|$$D(t(%GG$GGGr#   c                     t                      rj   r   )r/   rp   layer_colorlayer_alphar(   s        r$   rV  z,OverlaySelectionDisplay._build_element_layer~      !###r#   c                     t                      rj   r   )r/   rF   r   s      r$   rA  z-OverlaySelectionDisplay._style_region_element  r[  r#   )r/  FTr(  )T)r   r   r   r   r.   r9  r   r>   rR  rF  rG  rV  rA  r"   r#   r$   r.  r.     s         
/ / / /4 4 4,) ,) ,) ,)\ 8 8 [8' ' '	H 	H 	H$ $ $ $$ $ $ $ $r#   r.  c                   "    e Zd ZdZddZddZdS )	ColorListSelectionDisplayzd
    Selection display class for elements that support coloring by a
    vectorized color list.
    r/  rD   Nc                 4    |g| _         |g| _        || _        d S rj   )r2  alpha_propsbackend)r/   r5  
alpha_propra  s       r$   r.   z"ColorListSelectionDisplay.__init__  s!    &<&<r#   c                      |i } fd}|j         |j        g}|                    ||d|          }|D ]} ||          }|S )Nc                 `   ddl m} | j        }|dd          }d         }|pd} ||dd          d         fddd          D             }	t          |          }
t	          j        |gt          |	          z             }t	          j        |
d	
          }t          t          dt          |                    |          D ]'\  }}|s||d d <   |||
                    |          <   (||         fdj        D             } |                     |          j        dj        dd|S )Nr   linear_gradientr   z#e6e9ec#000000      c                     g | ]}|pS r"   r"   )r   c
backup_clrs     r$   r   zWColorListSelectionDisplay.build_selection.<locals>._build_selection.<locals>.<listcomp>  s    CCC1qJCCCr#   int8)dtypec                     i | ]}|S r"   r"   )r   r5  rC   s     r$   r8  zWColorListSelectionDisplay.build_selection.<locals>._build_selection.<locals>.<dictcomp>  s    PPP*fPPPr#   T)ra  r   r"   )r   rf  r  r   nparrayr   zerosziprE  r   r2  rP  rW  ra  )r   rC   rD   r5   r   rf  r   selection_exprsr   selected_colorsr   clrs
color_indsr   r   
color_optsrl  r/   s    `              @r$   _build_selectionzCColorListSelectionDisplay.build_selection.<locals>._build_selection  sh   666666B#ABBiO%ay  0<9()99aHHKJCCCCqrr
CCCOBA8-.o1F1FFGGD!6222JuQD		22ODD 3 34 3$%JqqqMM12Jtzz"~~..*%FPPPPt?OPPPJ'2;;r??'WDWWJWWWr#   T)r<  r>  r   )r   r   r   )	r/   r  rv   r   r  r   ry  sel_streamsrQ  s	   `        r$   r   z)ColorListSelectionDisplay.build_selection  s|    =E	X 	X 	X 	X 	X2 )57H7UV,kt[`aa 	 	BBuIIEEr#   )r/  rD   Nr(  )r   r   r   r   r.   r   r"   r#   r$   r^  r^    sF         
   
" " " " " "r#   r^  c                 t    ddl m}  |d| d          d         } || dd          d         } |||d          S )z<
    Create a light to dark cmap list from a base color
    r   re  z#ffffffrh  ri  rg  @   )r   rf  )r/  rf  start_color	end_colors       r$   r   r     s\     /.....!/)UA66q9K  y!44Q7I?;	2666r#   )/collectionsr   numpyrp  r   param.parameterizedr   	core.datar   core.elementr   r   core.layoutr	   core.optionsr
   r   core.overlayr   r   core.spacesr   r<  r   r   r   r   r   r   r   utilr   r   r&   r*   definer   _RegionElementr   ParameterizedFunctionrI   r   r   r+  r.  r^  r   r"   r#   r$   <module>r     sI   " " " " " "      * * * * * *       ) ) ) ) ) ) ) ) & & & & & & . . . . . . . . , , , , , , , , " " " " " "                       I I I I IF I I IA A A A AV A A A
P P P P P7 P P P& &-2
6
6
6tDDD J-  
v$ v$ v$ v$ v$E7 v$ v$ v$r\\ \\ \\ \\ \\+ \\ \\ \\~< < < < < < < <@    +   b$ b$ b$ b$ b$. b$ b$ b$J- - - - - 0 - - -`
7 
7 
7 
7 
7r#   