a
    =Dfa                     @  s  U d Z ddlmZ ddlZeeZddlZddl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 ddlmZmZmZ ddl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, dd
l-m.Z. ddl/m0Z0 erddl1m2Z2 dZ3ered Z4edddddddddZ5edddddddddZ5dddddddddZ5edddddddddZ6edddddddddZ6dddddddddZ6ddd dd!dddd"d#d$Z7dd%ddddd&d'd(dd)d*d*d*d+d,d-d.	d/d0Z8ed1dd2dd3d4d5d6Z9ed1dd7dd3d4d8d6Z9ed1dd9dd:d3d;d<d6Z9ed1dd9dd:d3d=d>d6Z9ed1dd9dd:d:d3d?d@d6Z9ed1ddAdd3d4dBd6Z9g dddfddd*d*d3d?dCd6Z9edDe)dEZ:ee;e: e<e: gee)e+df f Z=dFe>dG< dddHdIdJdKdIdLdMdNZ?dOd,dPdQdRZ@edSe$dEZAddTdUdVdWdXdYdZZBdddAd[d\d]d^ZCdid_dd:d7d`dadbZDedcZEddd:dedfdgdhZFdS )jz0 Functions for arranging bokeh layout objects.

    )annotationsN)defaultdict)
TYPE_CHECKINGAnyCallableIterableIteratorLiteralSequenceTypeVarUnionoverload   )LocationLocationTypeSizingModeType)	UndefinedUndefinedType)ColumnCopyToolExamineToolFlexBoxFullscreenToolGridBoxGridPlot	LayoutDOMPlotRowSaveToolSpacerToolToolbar	ToolProxy	UIElement)	dataclass)warn)	TypeAlias)columngridgridplotlayoutrowr   )logoautohideactive_dragactive_inspectactive_scroll
active_tapactive_multi)sizing_modezlist[UIElement]zSizingModeType | Noner   r   )childrenr3   kwargsreturnc                K  s   d S N r4   r3   r5   r8   r8   Z/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/bokeh/layouts.pyr+   V   s    r+   r#   c                 O  s   d S r7   r8   r3   r4   r5   r8   r8   r:   r+   X   s    zUIElement | list[UIElement]c                 O  s8   t |d|ddi}t|| dd tf || d|S )a)   Create a row of Bokeh Layout objects. Forces all objects to
    have the same sizing_mode, which is required for complex layouts to work.

    Args:
        children (list of :class:`~bokeh.models.LayoutDOM` ): A list of instances for
            the row. Can be any of the following - |Plot|,
            :class:`~bokeh.models.Widget`,
            :class:`~bokeh.models.Row`,
            :class:`~bokeh.models.Column`,
            :class:`~bokeh.models.Spacer`.

        sizing_mode (``"fixed"``, ``"stretch_both"``, ``"scale_width"``, ``"scale_height"``, ``"scale_both"`` ): How
            will the items in the layout resize to fill the available space.
            Default is ``"fixed"``. For more information on the different
            modes see :attr:`~bokeh.models.LayoutDOM.sizing_mode`
            description on :class:`~bokeh.models.LayoutDOM`.

    Returns:
        Row: A row of LayoutDOM objects all with the same sizing_mode.

    Examples:

        >>> row(plot1, plot2)
        >>> row(children=[widgets, plot], sizing_mode='stretch_both')
    r4   Nr+   widgetr4   r3   )_parse_children_argpop_handle_child_sizingr   r3   r4   r5   	_childrenr8   r8   r:   r+   [   s    r   c                K  s   d S r7   r8   r9   r8   r8   r:   r'   y   s    r'   c                 O  s   d S r7   r8   r;   r8   r8   r:   r'   {   s    c                 O  s8   t |d|ddi}t|| dd tf || d|S )a;   Create a column of Bokeh Layout objects. Forces all objects to
    have the same sizing_mode, which is required for complex layouts to work.

    Args:
        children (list of :class:`~bokeh.models.LayoutDOM` ): A list of instances for
            the column. Can be any of the following - |Plot|,
            :class:`~bokeh.models.Widget`,
            :class:`~bokeh.models.Row`,
            :class:`~bokeh.models.Column`,
            :class:`~bokeh.models.Spacer`.

        sizing_mode (``"fixed"``, ``"stretch_both"``, ``"scale_width"``, ``"scale_height"``, ``"scale_both"`` ): How
            will the items in the layout resize to fill the available space.
            Default is ``"fixed"``. For more information on the different
            modes see :attr:`~bokeh.models.LayoutDOM.sizing_mode`
            description on :class:`~bokeh.models.LayoutDOM`.

    Returns:
        Column: A column of LayoutDOM objects all with the same sizing_mode.

    Examples:

        >>> column(plot1, plot2)
        >>> column(children=[widgets, plot], sizing_mode='stretch_both')
    r4   Nr'   r<   r>   )r?   r@   rA   r   rB   r8   r8   r:   r'   ~   s    r>   zlist[UIElement] | None)argsr4   r3   r5   r6   c                 O  s    t |d| i}t||fi |S )a   Create a grid-based arrangement of Bokeh Layout objects.

    Args:
        children (list of lists of :class:`~bokeh.models.LayoutDOM` ): A list of lists of instances
            for a grid layout. Can be any of the following - |Plot|,
            :class:`~bokeh.models.Widget`,
            :class:`~bokeh.models.Row`,
            :class:`~bokeh.models.Column`,
            :class:`~bokeh.models.Spacer`.

        sizing_mode (``"fixed"``, ``"stretch_both"``, ``"scale_width"``, ``"scale_height"``, ``"scale_both"`` ): How
            will the items in the layout resize to fill the available space.
            Default is ``"fixed"``. For more information on the different
            modes see :attr:`~bokeh.models.LayoutDOM.sizing_mode`
            description on :class:`~bokeh.models.LayoutDOM`.

    Returns:
        Column: A column of ``Row`` layouts of the children, all with the same sizing_mode.

    Examples:

        >>> layout([[plot_1, plot_2], [plot_3, plot_4]])
        >>> layout(
                children=[
                    [widget_1, plot_1],
                    [slider],
                    [widget_2, plot_2, plot_3]
                ],
                sizing_mode='fixed',
            )

    r4   )r?   _create_grid)r4   r3   rD   r5   rC   r8   r8   r:   r*      s    !r*   ZaboveT)r3   toolbar_locationncolswidthheighttoolbar_optionsmerge_toolszlist[list[UIElement | None]]zLocationType | Nonez
int | Nonez dict[ToolbarOptions, Any] | Noneboolr   )	r4   r3   rF   rG   rH   rI   rJ   rK   r6   c          #   
     sh   du ri  |r(t t|s(td| t| d} |r^tdd | D rPtdtt| |} | sfg } g }g }	t| D ]\}
}t|D ]\}}|du rqqt|t	r|r|
ttdD ]}||j d|_q|dur||_|dur||_|durt|r||_|	||
|f qt|tr*qqtdqqvd	d
dddd}g }|D ]}||j qP|rvt||d}dd |D }dd |D }dd |D }dd |D }dd |D }dd |D }dd |D }td}dddd fdd}||d}||d }||d!}||d"}||d#}||d$} ||d%}!t||||||| |!d&}t|	|||d'}"|"S )(aM	   Create a grid of plots rendered on separate canvases.

    The ``gridplot`` function builds a single toolbar for all the plots in the
    grid. ``gridplot`` is designed to layout a set of plots. For general
    grid layout, use the :func:`~bokeh.layouts.layout` function.

    Args:
        children (list of lists of |Plot|): An array of plots to display in a
            grid, given as a list of lists of Plot objects. To leave a position
            in the grid empty, pass None for that position in the children list.
            OR list of |Plot| if called with ncols.

        sizing_mode (``"fixed"``, ``"stretch_both"``, ``"scale_width"``, ``"scale_height"``, ``"scale_both"`` ): How
            will the items in the layout resize to fill the available space.
            Default is ``"fixed"``. For more information on the different
            modes see :attr:`~bokeh.models.LayoutDOM.sizing_mode`
            description on :class:`~bokeh.models.LayoutDOM`.

        toolbar_location (``above``, ``below``, ``left``, ``right`` ): Where the
            toolbar will be located, with respect to the grid. Default is
            ``above``. If set to None, no toolbar will be attached to the grid.

        ncols (int, optional): Specify the number of columns you would like in your grid.
            You must only pass an un-nested list of plots (as opposed to a list of lists of plots)
            when using ncols.

        width (int, optional): The width you would like all your plots to be

        height (int, optional): The height you would like all your plots to be.

        toolbar_options (dict, optional) : A dictionary of options that will be
            used to construct the grid's toolbar (an instance of
            :class:`~bokeh.models.Toolbar`). If none is supplied,
            Toolbar's defaults will be used.

        merge_tools (``True``, ``False``): Combine tools from all child plots into
            a single toolbar.

    Returns:
        GridPlot:

    Examples:

        >>> gridplot([[plot_1, plot_2], [plot_3, plot_4]])
        >>> gridplot([plot_1, plot_2, plot_3, plot_4], ncols=2, width=200, height=100)
        >>> gridplot(
                children=[[plot_1, plot_2], [None, plot_3]],
                toolbar_location='right'
                sizing_mode='fixed',
                toolbar_options=dict(logo='gray')
            )

    Nz#Invalid value of toolbar_location: r4   c                 s  s   | ]}t |tV  qd S r7   
isinstancelist.0childr8   r8   r:   	<genexpr>      zgridplot.<locals>.<genexpr>z-Cannot provide a nested list when using ncols)typez>Only UIElement and LayoutDOM items can be inserted into a gridz
type[Tool]z
list[Tool]zTool | ToolProxy | None)clsgroupr6   c                 S  s    t | ttttfr|  S d S d S r7   )
issubclassr   r   r   r   )rW   rX   r8   r8   r:   merge,  s    zgridplot.<locals>.merge)rZ   c                 S  s   g | ]
}|j qS r8   )r,   rR   toolbarr8   r8   r:   
<listcomp>:  rU   zgridplot.<locals>.<listcomp>c                 S  s   g | ]
}|j qS r8   )r-   r[   r8   r8   r:   r]   ;  rU   c                 S  s   g | ]
}|j qS r8   )r.   r[   r8   r8   r:   r]   <  rU   c                 S  s   g | ]
}|j qS r8   )r/   r[   r8   r8   r:   r]   =  rU   c                 S  s   g | ]
}|j qS r8   )r0   r[   r8   r8   r:   r]   >  rU   c                 S  s   g | ]
}|j qS r8   )r1   r[   r8   r8   r:   r]   ?  rU   c                 S  s   g | ]
}|j qS r8   )r2   r[   r8   r8   r:   r]   @  rU   Vzlist[V]ToolbarOptionszV | UndefinedType)valuesnamer6   c                   sH   | v r | S t t| }|dkr(tS |dkr@td| d | d S )Nr   r   z-found multiple competing values for 'toolbar.z"' property; using the latest value)lensetr   r%   )r`   ra   nrJ   r8   r:   assert_uniqueC  s    zgridplot.<locals>.assert_uniquer,   r-   r.   r/   r0   r1   r2   )toolsr,   r-   r.   r/   r0   r1   r2   )r4   r\   rF   r3   )hasattrr   
ValueErrorr?   anyrP   _chunks	enumeraterO   r   selectdictr   appendr\   rF   rH   rI   _has_auto_sizingr3   r#   extendrh   group_toolsr   r!   r   )#r4   r3   rF   rG   rH   rI   rJ   rK   Ztoolbarsitemsyr+   xitemZplotrZ   rh   r\   ZlogosZ	autohidesZactive_dragsZactive_inspectsZactive_scrollsZactive_tapsZactive_multisr^   rg   r,   r-   r.   r/   r0   r1   r2   Zgpr8   rf   r:   r)      s    >









r)   .z-list[UIElement | list[UIElement | list[Any]]]r   )r4   r3   r6   c                C  s   d S r7   r8   r>   r8   r8   r:   r(   j  s    r(   zRow | Columnc                C  s   d S r7   r8   r>   r8   r8   r:   r(   l  s    zlist[UIElement | None]int)r4   r3   nrowsr6   c                C  s   d S r7   r8   )r4   r3   ry   r8   r8   r:   r(   n  s    )r4   r3   rG   r6   c                C  s   d S r7   r8   )r4   r3   rG   r8   r8   r:   r(   p  s    )r4   r3   ry   rG   r6   c                C  s   d S r7   r8   )r4   r3   ry   rG   r8   r8   r:   r(   r  s    strc                C  s   d S r7   r8   r>   r8   r8   r:   r(   t  s    c           	        s  t G fdddt G fdddt G dd dt G fddd d	d
 fdd}ttr|dusdurt}du rt|| fddtd|D }n"d!dddfdd}n`ttr6dddddd"dddfdddd}nttrHt	nt
d ||}|dur||_|jD ]}|d }t|rn||_qn|S )#a  
    Conveniently create a grid of layoutable objects.

    Grids are created by using ``GridBox`` model. This gives the most control over
    the layout of a grid, but is also tedious and may result in unreadable code in
    practical applications. ``grid()`` function remedies this by reducing the level
    of control, but in turn providing a more convenient API.

    Supported patterns:

    1. Nested lists of layoutable objects. Assumes the top-level list represents
       a column and alternates between rows and columns in subsequent nesting
       levels. One can use ``None`` for padding purpose.

       >>> grid([p1, [[p2, p3], p4]])
       GridBox(children=[
           (p1, 0, 0, 1, 2),
           (p2, 1, 0, 1, 1),
           (p3, 2, 0, 1, 1),
           (p4, 1, 1, 2, 1),
       ])

    2. Nested ``Row`` and ``Column`` instances. Similar to the first pattern, just
       instead of using nested lists, it uses nested ``Row`` and ``Column`` models.
       This can be much more readable that the former. Note, however, that only
       models that don't have ``sizing_mode`` set are used.

       >>> grid(column(p1, row(column(p2, p3), p4)))
       GridBox(children=[
           (p1, 0, 0, 1, 2),
           (p2, 1, 0, 1, 1),
           (p3, 2, 0, 1, 1),
           (p4, 1, 1, 2, 1),
       ])

    3. Flat list of layoutable objects. This requires ``nrows`` and/or ``ncols`` to
       be set. The input list will be rearranged into a 2D array accordingly. One
       can use ``None`` for padding purpose.

       >>> grid([p1, p2, p3, p4], ncols=2)
       GridBox(children=[
           (p1, 0, 0, 1, 1),
           (p2, 0, 1, 1, 1),
           (p3, 1, 0, 1, 1),
           (p4, 1, 1, 1, 1),
       ])

    c                      s   e Zd ZU ded< dS )zgrid.<locals>.rowlist[row | col]r4   N__name__
__module____qualname____annotations__r8   colr+   r8   r:   r+     s   
r+   c                      s   e Zd ZU ded< dS )zgrid.<locals>.colr{   r4   Nr|   r8   r   r8   r:   r     s   
r   c                   @  s6   e Zd ZU ded< ded< ded< ded< ded< dS )	zgrid.<locals>.Itemr   r*   rx   r0c0r1c1Nr|   r8   r8   r8   r:   Item  s
   
r   c                      s&   e Zd ZU ded< ded< ded< dS )zgrid.<locals>.Gridrx   ry   rG   z
list[Item]rt   Nr|   r8   )r   r8   r:   Grid  s   
r   r   )r6   c              	     s   ddddddddddfdddd	d
ddddd fdd  | }g }|j D ]8}|jd urj||j|j|j|j|j |j|j f qjt|dS )Nrx   )abr6   c                 S  s.   t | t | } }|dkr*|| |  } }q| S Nr   )abs)r   r   r8   r8   r:   gcd  s    z"grid.<locals>.flatten.<locals>.gcd)r   restr6   c                   s    |D ]}| |  | | } q| S r7   r8   )r   r   r   )r   r8   r:   lcm  s    z"grid.<locals>.flatten.<locals>.lcmr   rL   rS   r6   c                 S  s   | j dko| jdkS r   )ry   rG   rS   r8   r8   r:   nonempty  s    z'grid.<locals>.flatten.<locals>.nonemptyzrow | col | LayoutDOM)r*   r6   c           	        s  t | rttt| j}|s0 ddg S dd |D  }tdd |D }g }d}|D ]T}||j }|jD ]4}||j	||j
 |j| ||j |j|  qt||j7 }q` |||S t | rttt| j}|s ddg S tdd |D }dd |D  }g }d}|D ]X}||j }|jD ]6}||j	|j
| ||j |j| ||j  q8||j7 }q$ |||S  dd| ddddgS d S )	Nr   c                 S  s   g | ]
}|j qS r8   ry   rQ   r8   r8   r:   r]     rU   z;grid.<locals>.flatten.<locals>._flatten.<locals>.<listcomp>c                 s  s   | ]}|j V  qd S r7   rG   rQ   r8   r8   r:   rT     rU   z:grid.<locals>.flatten.<locals>._flatten.<locals>.<genexpr>c                 s  s   | ]}|j V  qd S r7   r   rQ   r8   r8   r:   rT     rU   c                 S  s   g | ]
}|j qS r8   r   rQ   r8   r8   r:   r]     rU   r   )rO   rP   filtermapr4   sumry   rt   rp   r*   r   r   r   r   rG   )	r*   r4   ry   rG   rt   offsetrS   Zfactori)r   r   _flattenr   r   r   r+   r8   r:   r     s:    


2

4z'grid.<locals>.flatten.<locals>._flattenrM   )rt   r*   rp   r   r   r   r   r   )r*   r(   r4   r   )r   r   r   r+   )r   r   r   r   r:   flatten  s     *

,zgrid.<locals>.flattenNc                   s    g | ]} ||  qS r8   r8   )rR   r   )r4   rG   r+   r8   r:   r]     rU   zgrid.<locals>.<listcomp>r   zlist[LayoutDOM]rx   )r4   levelc                   s>   t | tr6 d dkrn}| fdd| D S | S d S )N   r   c                   s   g | ]}| d  qS )r   r8   rQ   )r   traverser8   r:   r]   
  rU   z*grid.<locals>.traverse.<locals>.<listcomp>rN   )r4   r   	container)r   r+   r   )r   r:   r     s    
zgrid.<locals>.traverser   rL   r   c                 S  s   t | o| jdkS r   )rq   spacingr   r8   r8   r:   	is_usable  s    zgrid.<locals>.is_usableF)rw   	top_levelc                   sD   t | tr<|s| r<t | tr$ n}|tt| jS | S d S r7   )rO   r   r   rP   r   r4   )rw   r   r   )r   r   r+   r   r8   r:   r     s    T)r   z expected a list, string or model)r   )F)r$   rO   rP   rc   mathceilranger   rz   NotImplementedErrorrj   r3   r4   rq   )	r4   r3   ry   rG   r   Nr*   r(   rS   r8   )r   r   r4   r   r   rG   r+   r   r:   r(   w  s@    1C
$




T)boundr&   MergeFn)rZ   ignorezlist[Tool | ToolProxy]zMergeFn[Tool] | Nonezset[str] | None)rh   rZ   r   r6   c                C  sr  t G dd d}tt}g }|du r.ddh}| D ]P}t|trL|| q2| }|D ]}||v rX||= qX||j ||| q2| D ]\}	}
|dur||	dd |
D }|dur|| q|
r|
^}}|j	g}t|D ]&}|j
|j
kr||j	 |
| q|
| t|dkr0||d	  q|durZ||	| }durZ|| q|t|d
 qq|S )z' Group common tools into tool proxies. c                   @  s   e Zd ZU ded< ded< dS )zgroup_tools.<locals>.ToolEntryr    toolr   propsNr|   r8   r8   r8   r:   	ToolEntry6  s   
r   NoverlayZ	renderersc                 S  s   g | ]
}|j qS r8   )r   )rR   entryr8   r8   r:   r]   M  rU   zgroup_tools.<locals>.<listcomp>r   r   )rh   )r$   r   rP   rO   r"   rp   Zproperties_with_values	__class__rt   r   r   removerc   )rh   rZ   r   r   Zby_typeZcomputedr   r   attrrW   entriesmergedheadtailrX   rw   r8   r8   r:   rs   3  sD    


rs   r   )rw   r6   c                 C  s   | j d u o| jdko| jdkS )Nauto)r3   Zwidth_policyZheight_policy)rw   r8   r8   r:   rq   h  s    rq   LrM   zL | list[L]zlist[L] | Nonezlist[L])rD   r4   r6   c                 G  sL   t |dkr| d urtd| sHt |dkr@|\}t|tr@|S t|S | S )Nr   z;'children' keyword cannot be used with positional argumentsr   )rc   rj   rO   rP   )r4   rD   argr8   r8   r:   r?   l  s    
r?   None)r4   r3   r=   r6   c             	   C  sX   | D ]N}t |trqt |ts<td| d| dt| |d urt|r||_qd S )Nz,Only LayoutDOM items can be inserted into a z. Tried to insert: 	 of type )rO   r#   r   rj   rV   rq   r3   )r4   r3   r=   rw   r8   r8   r:   rA   {  s    

rA   z%Iterable[UIElement | list[UIElement]])iterabler3   layerr6   c                 K  s   g }| D ]}t |tr.|t|||d  qt |trZ|durNt|rN||_|| qt |trp|| qtd| dt	| q|d dkrt
f ||d|S tf ||d|S dS )z)Recursively create grid from input lists.r   NzUOnly LayoutDOM items can be inserted into a layout.
                Tried to insert: r   r   r   r>   )rO   rP   rp   rE   r   rq   r3   r#   rj   rV   r'   r+   )r   r3   r   r5   Zreturn_listrw   r8   r8   r:   rE     s(    


rE   IzSequence[I]zIterator[Sequence[I]])lrG   r6   c                 c  s>   t |tsJ dtdt| |D ]}| |||  V  q"dS )z-Yield successive n-sized chunks from list, l.zncols must be an integerr   N)rO   rx   r   rc   )r   rG   r   r8   r8   r:   rl     s    rl   )r   )G__doc__
__future__r   logging	getLoggerr}   logr   collectionsr   typingr   r   r   r   r   r	   r
   r   r   r   Z
core.enumsr   r   r   Zcore.property.singletonsr   r   modelsr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   Zutil.dataclassesr$   Zutil.warningsr%   Ztyping_extensionsr&   __all__r_   r+   r'   r*   r)   r(   r   rV   rP   r   r   rs   rq   r   r?   rA   rE   r   rl   r8   r8   r8   r:   <module>   s|   
0H	&" *  :*5	