
    e4                        d dl Z d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlZd dlZd dl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 d d	lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 d d
l2m3Z3m4Z4 d dl5m6Z6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZC ddlDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZT ddlUmVZV ddlWmXZX  eCejY                  ZZeZ eCd          k    Z[eZ eCd          k    Z\eZ eCd          k    Z]i de1j^        de1j^        de1j^        d e1j_        d!e1j_        d"e1j`        d#e1j`        d$e1j`        d%e1ja        d&e1ja        d'e1ja        d(e1jb        d)e1jb        d*e1jb        d+e1jc        d,e1jc        d-e1jd        i d.e1je        d/e1je        d0e1je        d1e1jf        d2e1jg        d3e1jh        d4e1jh        d5e1jh        d6e1ji        d7e1j-        d8e1jj        d9e1jk        d:e1jl        d;e1jm        d<e1jn        d=e1jo        d>e1jp        e1jq        e1jr        d?Zsd@ ZtdA ZudB ZvdC ZwdD Zx	 dodEZydodFZzdG Z{dpdIZ|edJ             Z}dK Z~dL ZdM Z	 	 dqdPZdQ ZdrdTZdU ZdV ZdW ZdodXZdY ZdZ Zedsd[            Zd\ Zd] Zd^ Z G d_ d`          Zda Zdb ZdodcZdd Zde Zdf Zdg Zdh Zdi Zdj Zdk Zdl Zdm Zdn ZdS )t    N)defaultdict)contextmanagersuppress)permutations)serialize_json)Datetimesilence)ColumnRowgroup_tools)CategoricalAxisCopyToolCustomJSDataRange1dDatetimeAxisExamineToolFactorRangeFullscreenToolGridBoxGridPlot	LayoutDOM
LinearAxisLogAxisMercatorAxisModelPlotRange1dSaveToolSpacerTabsToolbartools)PrintfTickFormatterTickFormatter)CategoricalScaleLinearScaleLogScale)	DataTableDiv)figure)built_in_themes)Theme)Version   )Layout)	NdMapping)	NdOverlayOverlay)
DynamicMapget_nested_dmaps)arraylike_typescallable_namecftime_to_timestampcftime_types	isnumericunique_array)warn   )dim_axis_labelz3.2z3.3z3.4panxpanypan
xwheel_pan
ywheel_pan
wheel_zoomxwheel_zoomywheel_zoomzoom_inxzoom_inyzoom_inzoom_out	xzoom_out	yzoom_outclicktap	crosshair
box_selectxbox_selectybox_selectpoly_selectlasso_selectbox_zoom	xbox_zoom	ybox_zoomhoversaveundoredoresethelpbox_edit
point_draw	poly_draw)	poly_editfreehand_drawc                     t           j                            | dz  t           j        j                  }t          j        |                    d                    S )z3
    Converts bokehJS timestamp to datetime64.
      )tzN)tzinfo)dtdatetimefromtimestamptimezoneutcnp
datetime64replace)	timestamprh   s     =lib/python3.11/site-packages/holoviews/plotting/bokeh/util.pyconvert_timestamprq   l   sG     {((4BKO(LLH=)))66777    c                 P    | du p"t          | t                    od| v o	| d         du S )z+
    Checks if property value is None.
    Nvalue)
isinstancedict)rt   s    rp   prop_is_nonerw   t   s?     TM )t$$ (E)9 (w4'*rr   c                 .   t          |           r%t          | t                    r| j        j        dk    r| S d | D             }t          | t
          j                  rt          j        |          S t          | t                    rt          |          S |S )zi
    Decodes an array, list or tuple of bytestrings to avoid python 3
    bokeh serialization errors
    Oc                 f    g | ].}t          |t                    r|                    d           n|/S )zutf-8)ru   bytesdecode.0vs     rp   
<listcomp>z decode_bytes.<locals>.<listcomp>   s8    OOOAJq%$8$8?qxx   aOOOrr   )	lenru   r6   dtypekindrl   ndarrayasarraytuple)arraydecodeds     rp   decode_bytesr   }   s    
 JJ :e_== %+BRVYBYBYOOOOOG%$$ z'"""	E5	!	! W~~Nrr   c                    t          t                    t          t                    }}t          |           D ]f\  }}t          |          D ]Q\  }}|J|                    |          \  }}	t	          ||         |          ||<   t	          ||         |	          ||<   Rgg }
t          |           D ]\  }}|
                    g            t          |          D ]\  }}|t          ||         ||                   }n@t          |d          r0|j        dk    r%|j	        dk    r||         |_        ||         |_	        |
|                             |           |
S )zB
    Pads Nones in a list of lists of plots with empty plots.
    Nwidthr   )
r   int	enumerateget_sizemaxappend
empty_plothasattrr   height)plotsrendererwidthsheightsrrowcpr   r   expanded_plotss              rp   layout_paddingr      ss    "#&&C(8(8GFE"" 5 53cNN 	5 	5DAq} ( 1 1! 4 4vq	511q	 V44
		5 NE"" ( (3b!!!cNN 	( 	(DAqyvay'!*55G$$ &A!(a-- )"1:1$$Q''''	( rr   c                    t          | t          t          f          rt          d | j        D             ddg          }|                    d          }|                    d          }t          d |D                       }t          d |D                       }||fS t          | t          t          f          rdS t          | t          t          t          f          r| j        sdS t          | t                    st          | t                    r"| j        dvrt          j        t          j        }}nFt          | t                    rt          j        t          j        }}nt          j        t          j        }}t          d	 | j        D              \  }}	 ||           ||	          fS t          | t                     rP| j        r| j        }n| j        | j        z   | j        z   }| j        r| j        }n| j        | j        z   | j        z   }||fS t          | t2          t4          t6          f          r| j        | j        fS dS )
zo
    Computes the size of bokeh models that make up a layout such as
    figures, rows, columns, and Plot.
    c                      i | ]\  }}}||f|S  r   )r~   figyxs       rp   
<dictcomp>z%compute_plot_size.<locals>.<dictcomp>   s$    JJJysAq1vsJJJrr   r   r   )kdimsc                 @    g | ]}t          d  |D                       S )c                 8    g | ]}t          |          d          S )r   compute_plot_sizer~   fs     rp   r   z0compute_plot_size.<locals>.<listcomp>.<listcomp>   s&    ???a+A..q1???rr   r   )r~   cols     rp   r   z%compute_plot_size.<locals>.<listcomp>   s/    QQQSS??3???@@QQQrr   c                 @    g | ]}t          d  |D                       S )c                 8    g | ]}t          |          d          S )   r   r   s     rp   r   z0compute_plot_size.<locals>.<listcomp>.<listcomp>   s&    @@@q,Q//2@@@rr   r   )r~   r   s     rp   r   z%compute_plot_size.<locals>.<listcomp>   s/    RRRcc@@C@@@AARRRrr   )r   r   )rightleftc                 ,    g | ]}t          |          S r   r   r~   childs     rp   r   z%compute_plot_size.<locals>.<listcomp>   s!    TTTU 1% 8 8TTTrr   )ru   r   r   r1   childrengroupbysumr*   r"   r   r   r!   toolbar_locationrl   r   zipr+   r   frame_widthmin_border_rightmin_border_leftr   frame_heightmin_border_bottommin_border_topr   r)   r    )
plot	ndmappingcolsrowsr   r   w_aggh_aggr   r   s
             rp   r   r      s6   
 $(+,, !JJDMJJJSVX[R\]]]	  %%  %%QQDQQQRRRRTRRRSSf}	D3.	)	) t	D3-	.	. })TTdC   	,Zg%>%> 	,4CX`qCqCqFBF5EEd## 	,FBF5EEFBF5ETTdmTTTUuV}}eeGnn,,	D&	!	! : 	TJEE$t'<<t?SSE; 	V[FF&)??$BUUFf}	D4F3	4	4 z4;&&trr   c                    |p|}|p|}|p|}|dk    rd}n|dk    rd}|dnt          ||	z            }| dnt          | |	z            } |dnt          ||	z            }|dnt          ||	z            }|p| }|p|}|d} |d}d}|rd|r|rd}|
r|
                    d           nF|r	d}|rdnd}n;|r	d} |rdnd	}n0d
\  } }|r|dk    rd}n |dk    rd}nd}n|dk    rd}n|dk    rd}nd}|r|o| |o| k    r|
r|
                    d           |rdnd}|r,|r*|r(|dk    rd}np|sd}|
r|
                    d|z             nQ|r|rd}d}|
r|
                    d           n1|r|rd} d}|
r|
                    d           n|dk    rd}n|dk    rd}|dk    r|rd}|
r|
                    d           |dk    r|rd}|
r|
                    d           d}d}d}|r,d}|r|r	|p| |p|}}n|s|sd}n|s|sd} |}|dk    rd}nm|r|}nh|r|rnct          |          r;|r|}nO|r|}t          ||z            }d
\  } }n3t          ||z            }|}d
\  } }n||
r|
                    d           ||||d}|||| d}||fS )a'  
    Utility to compute the aspect, plot width/height and sizing_mode
    behavior.

    Args:
      width (int): Plot width
      height (int): Plot height
      frame_width (int): Plot frame width
      frame_height (int): Plot frame height
      explicit_width (list): List of user supplied widths
      explicit_height (list): List of user supplied heights
      aspect (float): Plot aspect
      data_aspect (float): Scaling between x-axis and y-axis ranges
      responsive (boolean): Whether the plot should resize responsively
      size_multiplier (float): Multiplier for supplied plot dimensions
      logger (param.Parameters): Parameters object to issue warnings on

    Returns:
      Returns two dictionaries one for the aspect and sizing modes,
      and another for the plot dimensions.
    squarer   equalNfixedFzSresponsive mode could not be enabled because fixed width and height were specified.stretch_heightstretch_width)NNr   scale_widthr   scale_height
scale_bothstretch_botha9  Due to internal constraints, when aspect and width/height is set, the bokeh backend uses those values as frame_width/frame_height instead. This ensures the aspect is respected, but means that the plot might be slightly larger than anticipated. Set the frame_width/frame_height explicitly to suppress this warning.data_aspectaspectz%s value was ignored because absolute width and height values were provided. Either supply explicit frame_width and frame_height to achieve desired aspect OR supply a combination of width or height and an aspect value.zSresponsive mode could not be enabled because fixed width and aspect were specified.zTresponsive mode could not be enabled because fixed height and aspect were specified.zMresponsive width mode could not be enabled because a fixed width was defined.zOresponsive height mode could not be enabled because a fixed height was defined.TzUaspect value of type %s not recognized, provide a numeric value, 'equal' or 'square'.)aspect_ratioaspect_scalematch_aspectsizing_mode)r   r   r   r   )r   warningr:   )r   r   r   r   explicit_widthexplicit_heightr   r   
responsivesize_multiplierloggerfixed_widthfixed_heightfixed_aspectactual_widthactual_heightr   aspect_typer   r   r   aspect_infodimension_infos                          rp   compute_layout_propertiesr      s   2 "0[K#3|L([L	7		 ^TTVO-C)D)DFMDDs5+@'A'AE'/44So9U5V5VL%-$$3{?7R3S3SK'%L *FMK - 	-K 	-J -  , - - -  	-F%1G''7GKK 	-E%1F''KK&ME6 -(("/KK8++"0KK".KKw&&,x''.,  ()/K_5Y\IYZZ`fZNN B C C C (3@mm 	)< 	)F 	)    H HNN9 <G	GH H H  	)Z 	)FJ -  , - - -  
	)j 
	)EJ -  , - - - 7""'KK8##(KW
 	ANN @ A A AX,
 	BNN A B B B LLL & 	L 	(3(<ul>TfKK 	 	FF 	 	E"WLL 	"!L
 &, &	6		 & 		'!LL 	'&K|F233L&ME66mF233K(L&ME66			 % 	& 	& 	&
 %$$#	 K $$	 N &&rr   c                    g }| D ]}}|D ]x}t          |t                    rE|                    t          t                              D ]} |j        |j        j                   t          |t                    rd|_	        y~d }|sh d}t                      }|D ]2}|                                D ]}||vr|                    |           3t          t          rt          |||          n|          S )a  
    Merges tools defined on a grid of plots into a single toolbar.
    All tools of the same type are merged unless they define one
    of the disambiguation properties. By default `name`, `icon`, `tags`
    and `description` can be used to prevent tools from being merged.
    )typeNc                 j    t          | t          t          t          t          f          r
 |             S d S N)
issubclassr   r   r   r   )toolgroups     rp   mergezmerge_tools.<locals>.merge  s-    dXxnMNN 	466M4rr   >   iconnametagsdescription)r   ignore)r#   )ru   r   selectrv   r   extendtoolbarr#   r   r   setproperties_with_valuesaddr"   merge_toolsr   )		plot_griddisambiguation_propertiesr#   r   itemr   r   r   r   s	            rp   r   r     s<    E - - 	- 	-D$	** 2Tt___55 2 2A EL1111$)) -(,%	-   % L$K$K$K!UUF  ,,.. 	 	A111

1	 ;aU%GGGG\abbbbrr   c                 f   t          | j                  dk     rdS t          t                    }t	                      }| j        D ]}t          |t                    r|d         }t          |t                    s5|j        D ])}|j	        r ||j	                 
                    |           *|j        r%|                    |j        d         j                   |                    d           t          |          dk    rt          d           dS |sdS ddd	}|                    t#          t%          |                              }d
| d| }|                                D ]L}t)          |d          D ]9\  }	}
|	                    |t-          |t/          |	|
                               :MdS )zThis syncs the legends of all plots in a grid based on their name.

    Parameters
    ----------
    bokeh_layout : bokeh.models.{GridPlot, Row, Column}
        Gridplot to sync legends of.
    r=   Nr   noner   zAClick policy of legends are not the same, no syncing will happen.mutedvisible)mutehidezdst.z = src.)srcdst)codeargs)r   r   r   listr   ru   r   r+   	renderersr   r   legendr   click_policydiscardr<   getnextitervaluesr   js_on_changer   rv   )bokeh_layoutitemsclick_policiesr   r   mappingpolicyr  r   r  r  s              rp   sync_legendsr    s    < !!A%% EUUN$ 	; 	;c5!! 	a&C#v&& 	 	( 	(Av (af$$Q''': 	;sz!}9:::6"""
>QPQQQ  	22G[[d>223344F)&))))D  $T1-- 	 	HCd#3)?)?)?@@@   	 rr   	top_rightc                    |dg}nNt          |t                    r!|rt          t          |                     ng }nt          |t                    r|g}t          | t
                    s| g} t          |           D ]T\  }}t          |t          t          f          s"||v r|	                    d|           >|	                    d           Ut          | t                    r| d         S | S )a   Only displays selected legends in plot layout.

    Parameters
    ----------
    holoviews_layout : Holoviews Layout
        Holoviews Layout with legends.
    figure_index : list[int] | bool | int | None
        Index of the figures which legends to show.
        If None is chosen, only the first figures legend is shown
        If True is chosen, all legends are shown.
    legend_position : str
        Position of the legend(s).
    Nr   T)show_legendlegend_positionF)r  )ru   boolranger   r   r0   r   r2   r3   optsr  )holoviews_layoutfigure_indexr  ir   s        rp   select_legendsr!    s    s	L$	'	' &7CKuS!122333	L#	&	& &$~&// .,--.. ) )4$G 455 	II$IHHHHII%I(((("D)) #""rr   c               '      K   | D ]}t          |           	 dV  | D ]}t          |d           dS # | D ]}t          |d           w xY w)zB
    Context manager for silencing bokeh validation warnings.
    NFr	   )warningsr   s     rp   silence_warningsr$    s      
   $ 	$ 	$GGU####	$ 	$x 	$ 	$GGU####	$s	   3 A
c                 $    t          | |          S )zD
    Creates an empty and invisible plot of the specified size.
    r   r   )r    r&  s     rp   r   r     s     f----rr   c                     g d}fd| j         D             | j         dd<   |D ]+}t          | |          }|v r|                               ,dS )z-
    Removes a legend from a bokeh plot.
    )r   r   abovebelowcenterc                     g | ]}|u|	S r   r   )r~   lr	  s     rp   r   z!remove_legend.<locals>.<listcomp>  s    @@@Aarr   N)r	  getattrremove)r   r	  valid_placesplaces    `  rp   remove_legendr1    sz     A@@L@@@@@@@DKN ! !e$$U??LL   ! !rr   c                 b   | t          | t                    sdS ddd}t          j        d|           }t          j        d|           }|r|r|r!|d         dk    rt	          |d                   S |r;|d         |v r3t	          t	          |d                   ||d                  z            S dS dS )	z-
    Convert a fontsize to a pixel value
    N   gUUUUUU?)emptz\d+z[a-z]+r   px)ru   strrefindallr   )sizeconversionsvalunits       rp   font_size_to_pixelsr>    s     |:dC00|6**K
*VT
"
"C:h%%D 9D 9c 9d1goo3q6{{	 9aK''CAKK+d1g"667789 9''rr   F#   c	                    t          t          |j        |                    }t          j        d |D                       }	t          |          }
t          dd          }t          |          }d}t          t          |
          |          }|

                    d	|           i }|r||d
<   |r||d<   t          |          }|d}t          |          }|d}t          j        |          }| dk    r]d}t          |t          j        t          j        |                    |	|z  dz  z  z             |z   |z   }t          d||
|||          }n_|rdnd}t          |t          j        t          j        |                    |	|z  dz  z  z             |z   |z   }t          |||
||          }t#          dd g d|}d|_        d|j        _        | dk    rGd|_        d|j        _        |j        d         } |r$|j        |_        g |_        |j        |j        d d <   n?d|j        _        |j        d         } |r$|j        |_        g |_        |j        |j        d d <   || _        || _        d| _         | j         di | |S )Nc                 ,    g | ]}t          |          S r   )r   r   s     rp   r   zmake_axis.<locals>.<listcomp>)  s    ---SVV---rr   )factorsr   r   )startendz1range.setv({start: 0, end: range.factors.length}))r  )r  r  rC  axis_label_text_font_sizemajor_label_text_font_size   
   r   r*  g=
ףp=?auto)x_axis_typex_axis_labelx_rangey_ranger   r   r   r   )y_axis_labelrL  rM  r   r   )r   r#   rD  Fmiddler   )!r  mappprint_valuerl   r   r   r   r>   r   rv   r  r>  radiansr   abssincosr+   outline_line_alphagridgrid_line_alphaalignyaxisr   xaxisr)  r(  r   r   major_label_orientationmajor_label_text_alignmajor_label_text_baselineupdate)axisr:  rB  dimfliprotation
label_size	tick_sizeaxis_heightncharsrangesranges2
axis_labelr\   customjs
axis_propstick_pxlabel_pxrY  r   r  r   r   s                          rp   	make_axisro  &  s   3s'1122GV--W---..F)))FA1%%%G$$J?ET///e<<<H
***J =2<
./ =3<
/0!),,G":..Hz(##Hs{{[26"&*:*:#;#;g~t+$- - . .078:BCZ"GF     
 +GK"&)9)9":":Wnd*#, , - -/679ABW"4u> > > 	7B77$77AAAFs{{wqz 	!gAGAGAGAAAJwqz 	!fAGAFAGAAAJ#+D "'D%-D"DK*Hrr   c           	           fdt          d          D             \  }}}|j        }t          j        |dz            }|dz  |z
  }|}d|z
  }t          j        |          }t          j        |          }|dz  }t          j        |          }t          j        |          }t          j        |          }t          j        |          }d|t          j        t          j        |          t          j        |          ||g          z  z
  |z  }	t          j        g dg dg d	g d
g dg dg          }
|	|
|         t          j	        t          j
        |                    dddf         f         }|                    |dz             S )z
    Vectorized HSV to RGB conversion, adapted from:
    http://stackoverflow.com/questions/24852345/hsv-to-rgb-color-conversion
    c              3   ,   K   | ]}d |f         V  dS ).Nr   )r~   r   hsvs     rp   	<genexpr>zhsv_to_rgb.<locals>.<genexpr>n  s+      --qs36{------rr   r/   g      @g      ?   r   )r   r/   r   )r=   r   r   )r   r   r/   )r   r=   r   )r/   r   r   )r   r   r=   N)r/   )r  shaperl   int_ravelvstack
zeros_like	ones_liker   arangeprodreshape)rr  hsr   ru  r   r   qtclistorderrgbs   `           rp   
hsv_to_rgbr  i  sk   
 .---E!HH---GAq!GE
"A	"QA	A
1A
A
AqDA
A
A
A
AqBM!,,R\!__QqABBBBAEE HggggggggggggggggggFGGE
a")BGENN33AAAdF;;
<C;;uTz"""rr   333333?333333?c                    t          | t                    r1d | j        D             }t          j        d |D                       }n
t          | t
                    r0d | j        D             }t          j        d |D                       }nt          | t                    rSd | j        D             }t          j        d |D                       }| j        D ]}||_	        t          ||z            }n]t          | t                    r| j	        }t          ||z            | _	        n)t          | t                    r| j	        }n| r| j	        }nd}|S )zi
    Computes the width of a model and sets up appropriate padding
    for Tabs and DataTable types.
    c                 ,    g | ]}t          |          S r   	pad_widthr   s     rp   r   zpad_width.<locals>.<listcomp>       ===U	%  ===rr   c                     g | ]}||S r   r   r}   s     rp   r   zpad_width.<locals>.<listcomp>      999a1====rr   c                 ,    g | ]}t          |          S r   r  r   s     rp   r   zpad_width.<locals>.<listcomp>  r  rr   c                     g | ]}||S r   r   r}   s     rp   r   zpad_width.<locals>.<listcomp>  r  rr   c                 ,    g | ]}t          |          S r   r  )r~   r  s     rp   r   zpad_width.<locals>.<listcomp>  s    111	!111rr   c                     g | ]}||S r   r   r}   s     rp   r   zpad_width.<locals>.<listcomp>  r  rr   r   )ru   r   r   rl   r   r   r   r!   tabsr   r   r)   r*   )modeltable_paddingtabs_paddingvalsr   submodels         rp   r  r    so   
 % ==en===994999::	E6	"	" ==en===994999::	E4	 	  11ej111994999::
 	, 	,H"HNU*++EE	, 
E9	%	% --..	E3		 	 Lrr   c                     g }| D ]B}g }|D ]&}t          |          }|                    |           '|                    |           Cd t          | |          D             } | S )z
    Accepts a grid of bokeh plots in form of a list of lists and
    wraps any DataTable or Tabs in a Column with appropriate
    padding. Required to avoid overlap in gridplot.
    c                 H    g | ]\  }}d  t          ||          D              S )c                 r    g | ]4\  }}t          |t          t          f          rt          ||           n|5S ))r   )ru   r)   r!   r   )r~   r   ws      rp   r   z(pad_plots.<locals>.<listcomp>.<listcomp>  sR     ( ( (!Q %/q9d2C$D$DKfQa    ! ( ( (rr   )r   )r~   r   wss      rp   r   zpad_plots.<locals>.<listcomp>  sQ     K K K,3C( (c2,,( ( ( K K Krr   )r  r   r   )r   r   r   
row_widthsr   r   s         rp   	pad_plotsr    s     F " "
 	% 	%AaLLEe$$$$j!!!!K K7:5&7I7IK K KELrr   c                     t          | t                    rd | D             } n>t          | d          rd| _        n&t          | d          rd | j        D             | _        | S )zi
    Filters out toolboxes out of a list of plots to be able to compose
    them into a larger plot.
    c                 ,    g | ]}t          |          S r   )filter_toolboxes)r~   r   s     rp   r   z$filter_toolboxes.<locals>.<listcomp>  s!    :::D!$'':::rr   r   Nr   c                 V    g | ]&}t          |t                    t          |          'S r   )ru   r"   r  r   s     rp   r   z$filter_toolboxes.<locals>.<listcomp>  s?     = = =e!+E7!;!;=*511 = = =rr   )ru   r  r   r   r   )r   s    rp   r  r    s    
 % =::E:::			"	" =!%	
	#	# == =u~ = = =Lrr   c                    t          |t                    r|g }|j        rc|                    |j                   |j        |j                            d          d         j        k    r|                    |j                   n|                    |j                   n| }d                    |          }n2d                    d t          |j
        |           D                       }|S )zv
    Computes a title for bokeh tabs from the key in the overlay, the
    element and the containing (Nd)Overlay.
    Nexistingr    z | c                 >    g | ]\  }}|                     |          S r   )pprint_value_string)r~   dks      rp   r   z!get_tab_title.<locals>.<listcomp>  s6     5 5 5AA11!44 5 5 5rr   )ru   r3   labelr   r   paramobjectsdefaultjoinr   r   )keyframeoverlaytitles       rp   get_tab_titler    s    
 '7## 6E{ *U[)));%+"5"5j"A"A'"J"RRRLL---U[))))E

 5 5s335 5 5 6 6Lrr   c                     d}|7t          |t                    rt          |         }|                    |           }|                     |          }|j                            | ||          S )z@
    Looks up the default value for a bokeh model property.
    N)ru   r7  r,   
_for_classlookuppropertythemed_default)r  r   theme	overrides
descriptors        rp   get_defaultr    sj     IeS!! 	+#E*E$$U++	d##J--eT9EEErr   c                 \   t          |                                          D ]\  }}t          |t                    rd|v rd|v r#|d         }nt          |t                    sB| |         }	 t          t          |                    dk    r|d         ||<   | |= z# t          $ r Y w xY wdS )z
    Iterates over the data and mapping for a ColumnDataSource and
    replaces columns with repeating values with a scalar. This is
    purely and optimization for scalar types.
    field	transformr   r   N)r  r  ru   rv   r7  r   r;   	Exception)datar  r  r   r  s        rp   filter_batched_datar    s     W]]__%%  1a 	7a<<a'
AAAs## 	a	<''((A--#AY
G 	 	 	D	 s   -.B
B)(B)c                     d | j                                         D             }d                                 D             }fd| j         D             }t          |o|o|o|d         |d         k              S )z
    Determine if the CDS.data requires a full replacement or simply
    needs to be updated. A replacement is required if untouched
    columns are not the same length as the columns being updated.
    c                 h    g | ]/}t          |t          ft          z              t          |          0S r   )ru   r  r6   r   r}   s     rp   r   z&cds_column_replace.<locals>.<listcomp>  sJ     A A A#Aw'>??Ac!ff A A Arr   c                 n    g | ]2}t          |t          t          j        f          #t	          |          3S r   )ru   r  rl   r   r   r}   s     rp   r   z&cds_column_replace.<locals>.<listcomp>  s4    UUUQ:a$
AS3T3TU#a&&UUUrr   c                     g | ]}|v|	S r   r   )r~   r  r  s     rp   r   z&cds_column_replace.<locals>.<listcomp>  s    999q1D=====rr   r   )r  r  r  )sourcer  current_length
new_length	untoucheds    `   rp   cds_column_replacer    s    A Afk&8&8&:&: A A ANUU$++--UUUJ9999FK999I	bnbbq@QU_`aUb@bcccrr   c              #      K   | j         j        }|| j         _        	 dV  |r|s|                                  dS || j         _        dS # |r|s|                                  n|| j         _        w xY w)z@
    Context manager to temporary override the hold policy.
    N)	callbacks
hold_value_holdunhold)documentr  server
old_policys       rp   hold_policyr    s      
 #.J%H2 	2* 	2OO'1H$$$  	2* 	2OO'1H$1111s   A 'A/c                 ~   i }|                                  }|                                D ]\  }}t          |t                    rt	          | |          }t          |          t          |          u r'|                     d          }t          ||           p	 t          | ||           # t          $ r=}t          |t                    rd|v rt          | ||d                    n|Y d}~d}~ww xY w||v r2|||         k    r&t          |t                    rd|v r|d         }|||<    | j
        di | dS )z
    Recursively updates attributes on a model including other
    models. If the type of the new model matches the old model
    properties are simply updated, otherwise the model is replaced.
    F)include_defaultsrt   Nr   )r   r  ru   r   r-  r   recursive_model_updatesetattrr  rv   r_  )	r  propsupdatesvalid_propertiesr  r   nested_modelnested_propses	            rp   r  r    s    G3355  1a 	"5!,,LAww$|,,,, 777OO&|\BBBB E1a((((       !!T**  w!||q!G*5555 65555 
 """q,<Q,?'?'?!T"" w!||gJGAJEL7s   B..
C583C00C5c                       fd}|S )a3  
    Context manager to ensures data sources shared between multiple
    plots are cleared and updated appropriately avoiding warnings and
    allowing empty frames on subplots. Expects a list of
    shared_sources and a mapping of the columns expected columns for
    each source in the plots handles.
    c                    | j                             di           }| j                             dg           }| j        }|D ]8j                                         |r|j        }|j        d d         |_        9 | g|R i |}|D ]|t                             }fd|D             }	|	r0t          j	        j        |	d                  t          j
                  ng fd|D             }
j                            |
           |S )Nsource_colsshared_sourcesc                 &    g | ]}|j         v |S r   r  )r~   r   r  s     rp   r   z:update_shared_sources.<locals>.wrapper.<locals>.<listcomp>O  s%    ===1A,<,<Q,<,<,<rr   r   c                 (    i | ]}|j         v|S r   r  )r~   r   emptyr  s     rp   r   z:update_shared_sources.<locals>.wrapper.<locals>.<dictcomp>Q  s'    HHH!1FK3G3GQ3G3G3Grr   )handlesr  r  r  clearr  _held_eventsidrl   	full_likenanr_  )selfr  kwargsr  r  doc	event_objretexpectedfoundpatchr  r  r   s              @@rp   wrapperz&update_shared_sources.<locals>.wrapperA  s>   l&&}b99))*:B??m$ 	E 	EFK EM	)2)?)D	&a&t&&&v&&$ 	& 	&F"2f::.H=======ECHPBLU1X!6???bEHHHHHxHHHEKu%%%%
rr   r   )r   r  s   ` rp   update_shared_sourcesr  9  s#        & Nrr   c                 D    t          j        fd| D                       S )z
    Uses a Dimension instance to convert an array of values to categorical
    (i.e. string) values and applies escaping for colons, which bokeh
    treats as a categorical suffix.
    c                 :    g | ]}                     |          S r   )rQ  )r~   r   ra  s     rp   r   z$categorize_array.<locals>.<listcomp>]  s'    888QS%%a((888rr   )rl   r   )r   ra  s    `rp   categorize_arrayr  W  s*     88888%888999rr   c                   T    e Zd ZdZd Zed             Zd ZddZd Z	d	 Z
d
 Zd ZdS )periodiczq
    Mocks the API of periodic Thread in hv.core.util, allowing a smooth
    API transition on bokeh server.
    c                 v    || _         d | _        d | _        d | _        d | _        d | _        d | _        d | _        d S r   )r  callbackperiodcountcounter_start_timetimeout_pcb)r  r  s     rp   __init__zperiodic.__init__f  s?     
			rr   c                     | j         d u S r   )r  r  s    rp   	completedzperiodic.completedp  s    |t##rr   c                     t          j                     | _        | j        t          d          | j                            | j        | j                  | _        d S )NzKperiodic was registered to be run on bokehserver but no document was found.)timer  r  RuntimeErroradd_periodic_callback_periodic_callbackr   r  r  s    rp   rC  zperiodic.startt  sW    9;;=   C D D DM778OQUQ\]]			rr   NFc                    t          |t                    r|dk     rt          d          n-t          |          t          d           urt          d          || _        |dz  | _        || _        || _        d| _        | S )Nr   zCount value must be positivez.Count value must be a positive integer or Noneg     @@)	ru   r   
ValueErrorr   r  r   r  r  r  )r  r   r  r  r  blocks         rp   __call__zperiodic.__call__{  s    eS!! 	Oqyy
+I J JJy%[[T

**MNNN Ul
rr   c                 (   |                      | j                   | xj        dz  c_        | j        :t          j                    | j        z
  }|| j        k    r|                                  | j        | j        k    r|                                  d S d S Nr   )r  r  r  r  r  stopr  )r  rg   s     rp   r  zperiodic._periodic_callback  s    dl###<#)++ 00BDL  		<4:%%IIKKKKK &%rr   c                     d | _         d | _        	 | j                            | j                   n# t
          $ r Y nw xY wd | _        d S r   )r  r  r  remove_periodic_callbackr  r  r  s    rp   r  zperiodic.stop  s[    	M2249==== 	 	 	D				s   0 
==c                 R    d| j          d| j         dt          | j                   dS )Nz	periodic(z, ))r   r  r7   r  r  s    rp   __repr__zperiodic.__repr__  s1    W4;WW$*WWdm8T8TWWWWrr   c                      t          |           S r   )reprr  s    rp   __str__zperiodic.__str__  s    Dzzrr   )NF)__name__
__module____qualname____doc__r  r  r	  rC  r  r  r  r  r  r   rr   rp   r  r  `  s         
   $ $ X$^ ^ ^   	 	 	  X X X    rr   r  c                 P      fd} j                             |t          g          S )z=
    Attaches plot refresh to all streams on the object.
    c                 h    t          |           D ] }t          j                  |j        _        !d S r   )r5   r  r  _periodic_util)dmapsubdmapr   s     rp   append_refreshz'attach_periodic.<locals>.append_refresh  s@    '-- 	F 	FG.6t}.E.EG++	F 	Frr   )hmaptraverser4   )r   r'  s   ` rp   attach_periodicr*    s=    F F F F F 9nzl;;;rr   c                    t          | t          j                  r:	 |                                 } n$# t          $ r |                                 } Y nw xY wt          | t          j                  r-|                     d                              t                    S t          | t                    rt          | d          S t          | d          r*t          j        |                                           dz  }nt!          d          |S )a  Converts support date types to milliseconds since epoch

    Attempts highest precision conversion of different datetime
    formats to milliseconds since the epoch (1970-01-01 00:00:00).
    If datetime is a cftime with a non-standard calendar the
    caveats described in hv.core.util.cftime_to_timestamp apply.

    Args:
        date: Date- or datetime-like object

    Returns:
        Milliseconds since 1970-01-01 00:00:00
    zdatetime64[ms]ms	timetuplerd   zDatetime type not recognized)ru   pd	Timestampto_datetime64r  to_datetimerl   rm   astypefloatr9   r8   r   calendartimegmr-  r  )datedt_ints     rp   date_to_integerr8    s     $%% &	&%%''DD 	& 	& 	&##%%DDD	& $&& /{{+,,33E:::	D,	'	' /"4...t[!! 9!1!122477888Ms   1 AAc                 Z     g t                       fd}t           |          S )aU  
    Orders a set of glyph handles using regular sort and an explicit
    sort order. The explicit draw order must take the form of a list
    of glyph names while the keys should be glyph names with a custom
    suffix. The draw order may only match subset of the keys and any
    matched items will take precedence over other entries.
    Nc                       fdD             }|r                     |d                    fnd                                z    fS )Nc                 >    g | ]}                     |          |S r   )
startswith)r~   r   glyphs     rp   r   z1glyph_order.<locals>.order_fn.<locals>.<listcomp>  s,    IIID%2B2B42H2HI4IIIrr   r   g    eA)index)r=  matches
draw_orderkeyss   ` rp   order_fnzglyph_order.<locals>.order_fn  s_    IIIIJIII9@ /!!'!*--u55TZZ&&&.	0rr   )r  )sorted)rA  r@  rB  s   `` rp   glyph_orderrD    sO     
$<<D0 0 0 0 0 0 $H%%%%rr   c                 n   | ddddf                                          }|ddddf                                          }| ddddf                                          }|ddddf                                          }| ddddf                                          }|ddddf                                          }| ddddf                                          }|ddddf                                          }	t          j        |||||g          } t          j        ||||	|g          }| |fS )zY
    Generates line paths for a quadmesh given 2D arrays of X and Y
    coordinates.
    r   r  r   N)rw  rl   column_stack)
XYX1Y1X2Y2X3Y3X4Y4s
             rp   	colormeshrQ    sE   
 
1R42:				B	
1R42:				B	
122qt8				B	
122qt8				B	
122qrr6		B	
122qrr6		B	
1R48				B	
1R48				B
RR,--A
RR,--Aa4Krr   c                    t          | t                    r5| t          v r,t          |          j        d                             |i           S t          | t
                    r!| j        d                             |i           S i S )Nattrs)ru   r7  r,   _jsonr  r-   )r  attrs     rp   theme_attr_jsonrV    su    % %?":":u%+G488rBBB	E5	!	! {7#''b111	rr   c           	           fd j         D             \  }}                                 }g g }}t          |||          D ]z\  }}}d |D             }	d |D             }
t          j        ||g          }t          j        t          j        |ddddf                             d                                        d                    d	         }t          |          rt          j
        ||dz             n|g}g g }}t          t          ||	|
                    D ]o\  }\  }}}|t          |          dz
  k    r
|dd
         }|                    |ddd	f         g|z              |                    |dddf         g|z              p|                    |           |                    |           |||fS )z
    Expands polygon data which contains holes to a bokeh multi_polygons
    representation. Multi-polygons split by nans are expanded and the
    correct list of holes is assigned to each sub-polygon.
    c              3   F   K   | ]}                     |d           V  dS )F)expandedN)dimension_values)r~   kdelements     rp   rs  z&multi_polygons_data.<locals>.<genexpr>   s6      SSrg&&rE&::SSSSSSrr   c                 &    g | ]}d  |D             S )c                 &    g | ]}|d d df         S )Nr   r   r~   r~  s     rp   r   z2multi_polygons_data.<locals>.<listcomp>.<listcomp>  $    &&&A!!!Q$&&&rr   r   r~   holes     rp   r   z'multi_polygons_data.<locals>.<listcomp>  '    >>>4&&&&&>>>rr   c                 &    g | ]}d  |D             S )c                 &    g | ]}|d d df         S r  r   r_  s     rp   r   z2multi_polygons_data.<locals>.<listcomp>.<listcomp>  r`  rr   r   ra  s     rp   r   z'multi_polygons_data.<locals>.<listcomp>  rc  rr   Nr=   r3  r   )r`  r   r  )r   holesr   rl   rF  whereisnanr2  r   r   splitr   r   )r\  xsysrf  xshyshr   r   
multi_holexhsyhsr   splitsarraysmulti_xsmulti_ysr   pathhxhys   `                   rp   multi_polygons_datarx    s    TSSSW]SSSFBMMOOE2CB..  1j>>:>>>>>:>>>A''"(5BQB<#6#6w#?#?@@DD!DLLMMaP.1&kkF%***w(!*3vsC+@+@!A!A 	- 	-A~b"S[[]##CRCyOOT!!!Q$ZLO,,,OOT!!!Q$ZLO,,,,

8

88Orr   c                     | "| t          |           t          |          k    rdS t          | |          D ]*\  }}t          ||          D ]\  }}||
||k    r  dS +dS )a&  Matches dimension specs used to link axes.

    Axis dimension specs consists of a list of tuples corresponding
    to each dimension, each tuple spec has the form (name, label, unit).
    The name and label must match exactly while the unit only has to
    match if both specs define one.
    NFT)r   r   )specs1specs2spec1spec2s1s2s         rp   match_dim_specsr    s     	&.c&kkS[[.H.HuFF++  u%'' 	 	FBzRZRxxuuu 	
 4rr   c                 *   t          | t          t          f          r|dv rt                      S t          | t          t          f          r|dk    rt	                      S t          | t
                    rt                      S t          d|  d          )N)linearrh   mercatorrI  Nlogz'Unable to determine proper scale for: '')ru   r   r   r'   r(   r   r&   r  )range_input	axis_types     rp   	get_scaler  '  s    +W566 S9Hx;x;x}}	K+w!7	8	8 SY%=O=Ozz	K	-	- S!!!Q;QQQRRRrr   c                    | d i fS | dk    r	t           i fS | dk    r	t          i fS | dk    r	t          i fS | dk    rt          t	          |dk    rdnd          fS | d	k    rt          |t                    r	t          i fS t          |t                    r_	 |j	        }t          j        |          r	t           i fS t          j        t                      |           t          i fS # t          $ r Y nw xY wt           i fS t          d
| d          )Nr  r  rh   r  r   lonlat)	dimensionrI  zUnrecognized axis_type: 'r  )r   r   r   r   rv   ru   r   r   r   rC  r   is_timestampvalidater  )r  r  ra  rt   s       rp   get_axis_classr  2  sJ   Rx	h		2~	e		{	j	 	 R	j	 	 TSAXXEE5IIIII	f		k;// 	"B&&W-- 
		#) (// *%r>)!(**e444#R''   2~CYCCCDDDs   #C! 7)C! !
C.-C.c                 v    t          | t                    r|dk    S t          | t                    r|dk    S |dv S )zE
    Ensure the range_type matches the axis model being matched.
    categoricalrh   )rI  r  )ru   r   r   )ax
range_types     rp   match_ax_typer  P  sI     "o&& -]**	B	%	% -Z''_,,rr   c                 d    | D ]}|j         |k    rt          ||          c S  t          d          )z@Apply match_ax_type to the y-axis found by the given range name zNo axis with given range found)y_range_namer  r  )yaxr  
range_namer`  s       rp   match_yaxis_type_to_ranger  \  sI     3 3
** z22222 +
5
6
66rr   c                 R    t          | t                    rnt          |           } | S )zV
    Wraps formatting function or string in
    appropriate bokeh formatter type.
    )format)ru   r%   r$   )	formatterr`  s     rp   wrap_formatterr  d  s/    
 )]++ :'y999	rr   c                     	 ddl m}mm} t	          | ||f          r%fd| j                                        D             } n# t          $ r Y nw xY w| S )zB
    Convert Bokeh's property Field and Value to a dictionary
    r   )FieldUnspecifiedValuec                 (    i | ]\  }}|k    ||S r   r   )r~   r  r   r  s      rp   r   z$property_to_dict.<locals>.<dictcomp>y  s)    III$!Q[8H8HA8H8H8Hrr   )!bokeh.core.property.vectorizationr  r  r  ru   __dict__r  ImportError)r   r  r  r  s      @rp   property_to_dictr  p  s    
OOOOOOOOOOa%(( 	JIIII!*"2"2"4"4IIIA    Hs   AA 
AAc                    t          t                    5  | j        d         j        }|D ]}t          t                    5  |j        j        }|                                D ]<\  }}t          |d          r'|j        j	        dk    r|
                                ||<   =	 d d d            n# 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )Nr   r   U)r   r  r  r  data_sourcer  r  r   r   r   tolist)r   r\  r  r   r  r  r   s          rp   dtype_fix_hookr    sZ    
)		 - -L(2	! 	- 	-H)$$ - -+0 JJLL - -DAqq'** -qw|s/B/B"#((**Q-- - - - - - - - - - - - - - -	-- - - - - - - - - - - - - - - - - -s6   +C AB+C+B//C2B/3CC	C	r   )Nr  )Fr   NNr?  )r  r  )F)r4  rh   rg   r8  r  collectionsr   
contextlibr   r   	itertoolsr   bokehnumpyrl   pandasr.  bokeh.core.json_encoderr   bokeh.core.property.datetimer   bokeh.core.validationr
   bokeh.layoutsr   r   r   bokeh.modelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   bokeh.models.formattersr$   r%   bokeh.models.scalesr&   r'   r(   bokeh.models.widgetsr)   r*   bokeh.plottingr+   bokeh.themesr,   bokeh.themes.themer-   packaging.versionr.   core.layoutr0   core.ndmappingr1   core.overlayr2   r3   core.spacesr4   r5   	core.utilr6   r7   r8   r9   r:   r;   util.warningsr<   utilr>   __version__bokeh_versionbokeh32bokeh33bokeh34PanToolWheelPanToolWheelZoomTool
ZoomInToolZoomOutToolTapToolCrosshairToolBoxSelectToolPolySelectToolLassoSelectToolBoxZoomTool	HoverToolUndoToolRedoTool	ResetToolHelpToolBoxEditToolPointDrawToolPolyDrawToolPolyEditToolFreehandDrawTool
TOOL_TYPESrq   rw   r   r   r   r   r   r  r!  r$  r   r1  r>  ro  r  r  r  r  r  r  r  r  r  r  r  r  r  r*  r8  rD  rQ  rV  rx  r  r  r  r  r  r  r  r  r   rr   rp   <module>r     s        				  # # # # # # / / / / / / / / " " " " " "          2 2 2 2 2 2 1 1 1 1 1 1 ) ) ) ) ) ) 2 2 2 2 2 2 2 2 2 2                                               0 G F F F F F F F G G G G G G G G G G / / / / / / / / ! ! ! ! ! ! ( ( ( ( ( ( $ $ $ $ $ $ % % % % % % ! ! ! ! ! ! ' ' ' ' ' ' . . . . . . . . 7 7 7 7 7 7 7 7                " ! ! ! ! ! ! ! ! ! ! !)**
775>>
)
775>>
)
775>>
)%	5=%
EM% EM% %$	%
 %$% %%% 5&% 5&% u%  %  % !% "% "% U]%  
5=!%" $#% %$ %%%%& 5&'%( 5&)%* 5'+%, E)-%. !/%0 "1%2 "3%4 U_5%6 EN7%8 EN9%: EN;%< U_=%> EN?%@ !A%B %%C%D #E% %F #+I% % %
P8 8 8* * *    2& & &X r' r' r' r'jc c c cD) ) )X" " " "J 
$ 
$ 
$. . .	! 	! 	!9 9 9 >?;=@ @ @ @F# # #<   :  &    .
F 
F 
F 
F  *
d 
d 
d 2 2 2 2  :  <: : :? ? ? ? ? ? ? ?D< < <  @& & & &$  &    4  &S S SE E E<	- 	- 	-7 7 7	 	 	   - - - - -rr   