
    e=                        d dl Z d dlmZ ddlmZmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZ d
dlmZmZ  G d dee          Z G d dee          Z G d dee          Z G d dee          ZdS )    N)attach_streams   )AdjointLayoutEmpty
GridMatrix	GridSpaceHoloMapNdLayout)Store)
wrap_tuple)	Histogram   )CallbackPlotDimensionedPlotGenericAdjointLayoutPlotGenericCompositePlotGenericElementPlotGenericLayoutPlot   )!configure_matching_axes_from_dimsfigure_gridc                       e Zd ZdZ ej        d          Z ej        d          Zg Ze	d             Z
d Zd
dZd
d	ZdS )
PlotlyPlotplotlyi  )defaultc                     | j         d         S )z
        The plotting state that gets updated via the update method and
        used by the renderer to generate output.
        fig)handles)selfs    >lib/python3.11/site-packages/holoviews/plotting/plotly/plot.pystatezPlotlyPlot.state   s     |E""    c                 ^    | j         r|                     |           dS d| _        d| _        dS )z,Triggers update to a plot on a refresh eventN)	top_levelupdatecurrent_keycurrent_frame)r   keys     r    _trigger_refreshzPlotlyPlot._trigger_refresh'   s:    > 	&KK#D!%Dr"   NFc                 H    |                      | j        d         ||          S )Nis_geogenerate_plotkeysr   rangesr-   s      r    initialize_plotzPlotlyPlot.initialize_plot0   s#    !!$)B-!GGGr"   c                 2    |                      |||          S )Nr,   )r/   )r   r(   r2   r-   s       r    update_framezPlotlyPlot.update_frame4   s    !!#vf!===r"   NF)__name__
__module____qualname__backendparamIntegerwidthheightunsupported_geo_style_optspropertyr!   r)   r3   r5    r"   r    r   r      s        GEM#&&&EU]3'''F!## # X#& & &H H H H> > > > > >r"   r   c                        e Zd Z ej        dd          Z ej        dd          Z ej        dd          Z ej        dd          Z	 fd	Z
d
 Zd ZddZddZ xZS )
LayoutPlotx   r   Nr   boundsd      T
        Whether axes ranges should be shared across the layout, if
        disabled switches axiswise normalization option on globally.r   docc                       t                      j        |fi |                      |          \   _         _         _         j        r!                      fdt          g           d S d S )Nc                 0    t          | j        d          S Nr   r   hmapxr   s    r    <lambda>z%LayoutPlot.__init__.<locals>.<lambda>J       N4$C$C r"   )	super__init___init_layoutlayoutsubplotspathsr$   traverser   )r   rY   params	__class__s   `  r    rW   zLayoutPlot.__init__E   s    **6***151B1B61J1J.T]DJ> 	0MMCCCC-.0 0 0 0 0	0 	0r"   c                 N    | j         j        \  }}|| j        z  dz  || j        z  fS )Ng?)rY   shaper=   r>   )r   rowscolss      r    	_get_sizezLayoutPlot._get_sizeM   s-    [&
dDJs"D$444r"   c                 P    d}                     dj                  }                     d d           t           fd j        D                                                       }t          t                    rj        nd }i i i }}} j	        D ]\  }	}
|
                     j        r|
|	fn|	|
fd          \  }}t          |t                    r|nt          |g          }|||	|
f<   |||	|
f<   dddd	}|
                    t          |          d          }t          j        |         d
         }|
                    |	|
fd          \  }}t          t                    r|rt          t!          ||                    }||	|
f         }t          |j        t$                    }|rt          g           }n|dz  }                     ||||rdn|          }|\  }}                     |d          j        }t          |||fi |}|||	|
f<   |r|||<   |||fS )Nr   Fshared_dataidc                 B    g | ]}|                     |          fS rA   compute_ranges.0r(   frame_rangesrY   r   s     r    
<listcomp>z+LayoutPlot._init_layout.<locals>.<listcomp>W   @     : : :(+ "4#6#6vsL#Q#QR : : :r"   )NNSingleDualTriple)r   r   r   	positionsr   )numplot)clonerg   rj   dictr0   
grid_items
isinstancer
   kdimscoordsget	transposer   lenAdjointLayoutPlotlayout_dictzipmainr   _create_subplotslookup_optionsoptions)r   rY   layout_countcollapsed_layoutlayout_itemslayout_dimensionslayout_subplotslayoutsr[   rcr(   viewlayout_lenslayout_typers   
layout_key_objemptysubplot_datarZ   adjoint_layoutplotoptslayout_plotrm   s   ``                       @r    rX   zLayoutPlot._init_layoutQ   s    !<<Efi<HH**64>> : : : : : :/3y: : : ; ;((**,6vx,H,HRFLLd*,b"%K '	> '	>DAq$((4>)M!Q1v|\\IC%dM::U44tf@U@UD"GQFOE!Q$K &H==K%//#d))X>>K *5kB;OI ),,aV\BBMJ&(++ M
 M$(->
)K)K$L$L! 1a&/Csx//E "#B''!00i1BL:?5QQQ\ 1 S SL (4$Hn **488@H+NK^^U]^^K&1OQF# >/= ,%77r"   r   c                 
   i }|                     d|j                  }t          |          }d}	|D ]}
|                    |
d          }|t	          |t
                    r|j        n|j        }t          j	        | j
        j                                     |d          }|                     |d          j        }i }|
dk    r^t          j	                            ||          }|
dk    rt          |	j        ddd	d
gdd          }nt          |	j        dd	dgdd          }t          |fi |}|                    |           |$| j                            d|j        z             8t+          | j                  dk    r|nd} ||f| j        | j        ||d| j        |d|}|||
<   t	          |t                    r&t5          |t6                    r||
         j        ||
<   n||
         j        ||
<   |
dk    r|}	||fS )<  
        Plot all the views contained in the AdjointLayout Object using axes
        appropriate to the layout configuration. All the axes are
        supplied by LayoutPlot - the purpose of the call is to
        invoke subplots with correct options and styles and hide any
        empty axes as necessary.
        Fre   )adjoinedNru   r   rightTrD   yr   )r>   yaxisinvert_axesr=   labelledxticks
show_titletoprS   )r=   xaxisr>   r   yticksr   IPlotly plotting class for %s type not found, object will not be rendered.r   r   )r0   
dimensionsr   r2   subplotuniform
layout_num)rv   rg   rw   r|   ry   r	   typer^   r   registryrendererr:   r   r   r   r>   r=   r%   r;   warningr7   r~   r{   r0   r   r   
issubclassr   rY   rQ   )r   rY   rs   r   r2   rt   rZ   adjoint_clonesubplot_opts	main_plotposelementvtype	plot_typer   	side_optsr   s                    r    r   zLayoutPlot._create_subplots   sg    69EEV,,,	 -	$ -	$Cjjd++G %/w$@$@WGLLgFWEt}'<=AA%NNI**7F;;CHIf}}-6::5)LL	'>> $I,<G15SC5,-%!A !A !AII !%9?%,/3%05!7 !7 !7I I2222HOOL))) 
""35:^DE E E T[))A--##1Ci ,di+/?2C'-t(,	, ,
 #+, ,G $HSM)T** 8z)EY/Z/Z 8%-c]%9c""%-c]%7c"f}}#	&&r"   NFc                    |                      | j        | j        d         d           }d t          | j                  D             }g }| j        D ]\  }| j                            |fd           }||                    |||          }t          fd|D                       }	t          |          dk    r5t          |d         |d         g|d         d gg| j        | j                  }n9t          |          dk    rt          |g| j        | j                  }n|d         }||	z   xx         |gz  cc<   t          t          t          |                    | j        | j                  }
| j        rt%          |
           |
d	                             |                     |          
           d| _        |
| j        d<   | j        d         S )Nr+   c                     g | ]}g S rA   rA   )rl   is     r    rn   z,LayoutPlot.generate_plot.<locals>.<listcomp>       ......r"   r2   r-   c              3   $   K   | ]
}|k    V  d S NrA   )rl   irr   s     r    	<genexpr>z+LayoutPlot.generate_plot.<locals>.<genexpr>   s'      ;;Q"W;;;;;;r"   r   r   r   )column_spacingrow_spacingrY   titleTr   )rj   rY   r0   rangera   r{   rZ   r|   r/   sumr~   r   adjoint_spacinglistreversedhspacingvspacingshared_axesr   r%   _format_titledrawnr   )r   r(   r2   r-   plotsinsert_rowsr   r   rZ   offsetr   r   s              @r    r/   zLayoutPlot.generate_plot   s   $$T[$)B-FF..U49--...K 	/ 	/DAqm''A55G""00VF0SS ;;;;{;;;;;x==1$$)HQK!+E,4QK+>+@9=9M6:6JL L LGG ]]Q&&)8*9=9M6:6JL L LGG 'qkGa&j!!!gY.!!!%!!=
 
 
  	3-c222H4#5#5c#:#:;;;
!U|E""r"   )r   r6   )r7   r8   r9   r;   Numberr   r   r   Booleanr   rW   rc   rX   r   r/   __classcell__r^   s   @r    rC   rC   9   s        u|C	:::Hu|C	:::H"el2i@@@O%- 3H I I IK0 0 0 0 05 5 538 38 38l;' ;' ;' ;'|)# )# )# )# )# )# )# )#r"   rC   c                   2     e Zd Zi Z fdZddZddZ xZS )r   c                     || _         || _        | j        | j                 d         | _         t	                      j        dd|i| d S )Nrs   rZ   rA   )rY   r   r   view_positionsrV   rW   )r   rY   r   rZ   r]   r^   s        r    rW   zAdjointLayoutPlot.__init__   sT    &".t/?@M 	55(5f55555r"   NFc                 H    |                      | j        d         ||          S )r   r+   r,   r.   r1   s      r    r3   z!AdjointLayoutPlot.initialize_plot   s%     !!$)B-!GGGr"   c                     g }dD ]J}| j                             |d           }|r+|                    |                    |||                     K|sd g}|S )N)r   r   r   r   )rZ   r|   appendr/   )r   r(   r2   r-   adjoined_plotsr   r   s          r    r/   zAdjointLayoutPlot.generate_plot
  sz    + 	 	Cm''T22G %%))#fV)LL   6~r"   r6   )r7   r8   r9   r   rW   r3   r/   r   r   s   @r    r   r      si        H6 6 6 6 6H H H H       r"   r   c                        e Zd ZdZ ej        dd          Z ej        dd          Z ej        dd          Z	d fd
	Z
d ZddZd Z xZS )GridPlotz\
    Plot a group of elements in a grid layout based on a GridSpace element
    object.
       rE   rF   TrJ   rK   Nr   c                 J    t          |t                    st          d           t                      j        d|||d| |j        \   _         _                             ||          \   _	         _
         j        r!                      fdt          g           d S d S )Nz GridPlot only accepts GridSpace.)rY   r   r2   c                 0    t          | j        d          S rO   rP   rR   s    r    rT   z#GridPlot.__init__.<locals>.<lambda>0  rU   r"   rA   )ry   r   	ExceptionrV   rW   r`   rb   ra   r   rZ   rY   r$   r\   r   )r   rY   r2   r   r]   r^   s   `    r    rW   zGridPlot.__init__'  s    &),, 	@>??? 	@:.4	@ 	@8>	@ 	@ 	@%|	49%)%:%:66%J%J"t{> 	0MMCCCC-.0 0 0 0 0	0 	0r"   c                     i }                      d |          t           fd j        D                                           dj                  }                    d          D ]_}t          |t                    s|f}j                            |d           }|?t          |t                    r|j
        n|j        }                     |d          j        }nd }i }	t          t                    r"|                    d t           g          rd|	d<   t"          j         j        j                                     |d           }
|
&|" j                            d	|j        z             
 |
|f j        dd j         j        d
t          |fi |	}t          |t4                    r|j        n|j        ||<   |||<   a||fS )Nc                 B    g | ]}|                     |          fS rA   ri   rk   s     r    rn   z-GridPlot._create_subplots.<locals>.<listcomp>7  ro   r"   Fre   T	full_gridru   c                     | S r   rA   )rS   s    r    rT   z+GridPlot._create_subplots.<locals>.<lambda>G  s    1 r"   r   r   )r   r   r   r2   r   r0   )rj   rw   r0   rv   rg   ry   tupledatar|   r	   r   r^   r   r   r   r\   r   r   r   r   r:   r;   r   r7   r   r   r   rY   rQ   )r   rY   r2   rZ   r   coordr   r   optskwargsplotting_classr   rm   s   ``          @r    r   zGridPlot._create_subplots4  s4   **64@@ : : : : : :/3y: : : ; ;!<<Efi<HH[[4[00 	* 	*EeU++=eXU;??5$//D%/g%>%>R		DN**488@ F&*-- 2==yk:: 2,1F=) #^DM,ABFFudSSN%#J&&79>HI I I ). Q$/4940<dl.2iQ Q <@;O;O;O;OQ Q
 /9BV.W.W,=7>>07 !' #*)))r"   Fc           	         |                      | j        | j        d         d           }d t          | j                  D             }t          | j                            d                    D ]\  }}|| j        z  }| j                            t          |          d           }|3|	                    ||          }	||         
                    |	           l||         
                    d            |                     |j        |j                  \  }
}t          || j        | j        dd|
|          }|d                             |                     |                     d| _        || j        d	<   | j        d	         S )
Nr+   c                     g | ]}g S rA   rA   )rl   r   s     r    rn   z*GridPlot.generate_plot.<locals>.<listcomp>_  r   r"   Tr   r   )r   r   share_xaxisshare_yaxisr=   r>   rY   r   r   )rj   rY   r0   r   rb   	enumeraterZ   r|   r   r3   r   rc   r=   r>   r   r   r   r%   r   r   r   )r   r(   r2   r-   r   r   r   r   r   ru   whr   s                r    r/   zGridPlot.generate_plot]  sz   $$T[$)B-FF..U49--...!$+"2"2T"2"B"BCC 	& 	&HAuDIAm''
5(9(94@@G"..fV.LLa%%%%a%%%% ~~gmW^<<1%)-&*m&*&* !!"   	H4#5#5c#:#:;;;
!U|E""r"   c                     t          | j        j                  }d|z  }d|dz
  dz  z   }||z  }| j        j        \  }}||z  |z  ||z  |z  fS )Ng      ?r   g?)maxrY   r`   )	r   r=   r>   max_dimshape_factorexpand_factorscale_factorrb   ra   s	            r    rc   zGridPlot._get_size}  sl    dk'((G|Wq[C//$|3[&
dt#e+t#f,. 	.r"   )Nr   r6   )r7   r8   r9   __doc__r;   r   r   r   r   r   rW   r   r/   rc   r   r   s   @r    r   r     s         
 u|By999Hu|By999H%- 3H I I IK
0 
0 
0 
0 
0 
0&* &* &*R# # # #@	. 	. 	. 	. 	. 	. 	.r"   r   )r;   holoviews.plotting.utilr   corer   r   r   r   r	   r
   core.optionsr   	core.utilr   r   r   ru   r   r   r   r   r   r   utilr   r   r   rC   r   r   rA   r"   r    <module>r     s    2 2 2 2 2 2 R R R R R R R R R R R R R R R R ! ! ! ! ! ! # # # # # #                            A @ @ @ @ @ @ @!> !> !> !> !>, !> !> !>Ju# u# u# u# u#. u# u# u#r# # # # #
$< # # #Nm. m. m. m. m.z/ m. m. m. m. m.r"   