§
    ²[6g76  ã                   óâ   — d dl mZ d dlmZmZ d dlmZ  ej        d¦  «        Z ej        d¦  «        Z	 ej        d¦  «        Z
 ej        d¦  «        Zdd	d	d	d
„ d	d	fd„Z G d„ de¦  «        Zd	S )é    )ÚOrderedDict)Ú
exceptionsÚoptional_imports)Ú
graph_objsÚnumpyÚscipyzscipy.cluster.hierarchyzscipy.spatialÚbottomNc                 ó8   — t                                | d¦  «        S ©NÚcomplete©ÚschÚlinkage©Úxs    ú`/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.pyú<lambda>r      s   € �Ÿš Q¨
Ñ3Ô3€ ó    c           
      ó:  — t           rt          rt          st          d¦  «        ‚| j        }t          |¦  «        dk    rt          j        d¦  «         |€t          j        j	        }t          | |||||||¬¦  «        }	t          j        |	j        |	j        ¬¦  «        S )a[	  
    Function that returns a dendrogram Plotly figure object. This is a thin
    wrapper around scipy.cluster.hierarchy.dendrogram.

    See also https://dash.plot.ly/dash-bio/clustergram.

    :param (ndarray) X: Matrix of observations as array of arrays
    :param (str) orientation: 'top', 'right', 'bottom', or 'left'
    :param (list) labels: List of axis category labels(observation labels)
    :param (list) colorscale: Optional colorscale for the dendrogram tree.
                              Requires 8 colors to be specified, the 7th of
                              which is ignored.  With scipy>=1.5.0, the 2nd, 3rd
                              and 6th are used twice as often as the others.
                              Given a shorter list, the missing values are
                              replaced with defaults and with a longer list the
                              extra values are ignored.
    :param (function) distfun: Function to compute the pairwise distance from
                               the observations
    :param (function) linkagefun: Function to compute the linkage matrix from
                               the pairwise distances
    :param (list[list]) hovertext: List of hovertext for constituent traces of dendrogram
                               clusters
    :param (double) color_threshold: Value at which the separation of clusters will be made

    Example 1: Simple bottom oriented dendrogram

    >>> from plotly.figure_factory import create_dendrogram

    >>> import numpy as np

    >>> X = np.random.rand(10,10)
    >>> fig = create_dendrogram(X)
    >>> fig.show()

    Example 2: Dendrogram to put on the left of the heatmap

    >>> from plotly.figure_factory import create_dendrogram

    >>> import numpy as np

    >>> X = np.random.rand(5,5)
    >>> names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark']
    >>> dendro = create_dendrogram(X, orientation='right', labels=names)
    >>> dendro.update_layout({'width':700, 'height':500}) # doctest: +SKIP
    >>> dendro.show()

    Example 3: Dendrogram with Pandas

    >>> from plotly.figure_factory import create_dendrogram

    >>> import numpy as np
    >>> import pandas as pd

    >>> Index= ['A','B','C','D','E','F','G','H','I','J']
    >>> df = pd.DataFrame(abs(np.random.randn(10, 10)), index=Index)
    >>> fig = create_dendrogram(df, labels=Index)
    >>> fig.show()
    zmFigureFactory.create_dendrogram requires scipy,                             scipy.spatial and scipy.hierarchyé   z X should be 2-dimensional array.N)ÚdistfunÚ
linkagefunÚ	hovertextÚcolor_threshold)ÚdataÚlayout)ÚscpÚscsr   ÚImportErrorÚshapeÚlenr   ÚPlotlyErrorÚdistanceÚpdistÚ_Dendrogramr   ÚFigurer   r   )
ÚXÚorientationÚlabelsÚ
colorscaler   r   r   r   ÚsÚ
dendrograms
             r   Úcreate_dendrogramr-      s´   € õH ð 
•cð 
¥ð 
Ýð?ñ
ô 
ð 	
ð
 	
Œ€AÝ
ˆ1�v„v�‚{€{ÝÔÐAÑBÔBÐBà€Ý”,Ô$ˆåØ	ØØØØØØØ'ð	ñ 	ô 	€Jõ Ô *¤/¸*Ô:KÐLÑLÔLÐLr   c                   ó^   — e Zd ZdZdddej        ej        dddd„ ddfd„Zd„ Zd	„ Zd
„ Z	d„ Z
dS )r%   z9Refer to FigureFactory.create_dendrogram() for docstring.r	   NÚxaxisÚyaxisc                 ó8   — t                                | d¦  «        S r   r   r   s    r   r   z_Dendrogram.<lambda>z   s   € �SŸ[š[¨¨JÑ7Ô7€ r   c           
      ó¶  — || _         || _        || _        || _        g | _        g | _        | j        d| j        di| _        | j        i | j        i i| _        | j         dv rd| j        | j        <   nd| j        | j        <   | j         dv rd| j        | j        <   nd| j        | j        <   |	€t          j	        j
        }	|                      |||	|
||¦  «        \  }}}}}|| _        || _        |                     ¦   «         }|                     ¦   «         }g | _        t          t          |¦  «        ¦  «        D ]=}||         dk    r/||         | j        vr | j                             ||         ¦  «         Œ>t          | j        ¦  «        t          |¦  «        dz   k    r‡t#          t%          | j        ¦  «        ¦  «        }t#          t'          | j        ¦  «        ¦  «        }t          ||dz   t#          ||z
  t          |¦  «        z  ¦  «        ¦  «        }d„ |D ¦   «         | _        | j                             ¦   «          |                      ||¦  «        | _        || _        d S )Né   )Úleftr	   éÿÿÿÿ)Úrightr	   g        c                 ó   — g | ]}|‘ŒS © r8   )Ú.0Úvs     r   ú
<listcomp>z(_Dendrogram.__init__.<locals>.<listcomp>®   s   € Ð<Ð<Ð< A˜aÐ<Ð<Ð<r   )r(   r)   r/   r0   r   ÚleavesÚsignr   r   r#   r$   Úget_dendrogram_tracesÚflattenÚ	zero_valsÚranger!   ÚappendÚintÚminÚmaxÚsortÚset_figure_layout)Úselfr'   r(   r)   r*   ÚwidthÚheightr/   r0   r   r   r   r   Ú	dd_tracesÚxvalsÚyvalsÚordered_labelsr<   Ú
yvals_flatÚ
xvals_flatÚiÚl_borderÚr_borderÚcorrect_leaves_poss                           r   Ú__init__z_Dendrogram.__init__o   sG  € ð 'ˆÔØˆŒØˆŒ
ØˆŒ
ØˆŒ	ØˆŒØ”Z  D¤J°Ð2ˆŒ	Ø”z 2 t¤z°2Ð6ˆŒàÔÐ1Ð1Ð1Ø$%ˆDŒI�d”jÑ!Ð!à$&ˆDŒI�d”jÑ!àÔÐ2Ð2Ð2Ø$%ˆDŒI�d”jÑ!Ð!à$&ˆDŒI�d”jÑ!àˆ?Ý”lÔ(ˆGà<@×<VÒ<VØˆz˜7 J°	¸?ñ=
ô =
Ñ9ˆ�E˜5 .°&ð %ˆŒØˆŒØ—]’]‘_”_ˆ
Ø—]’]‘_”_ˆ
àˆŒå•s˜:‘”Ñ'Ô'ð 	5ð 	5ˆAØ˜!Œ} Ò#Ð#¨
°1¬¸T¼^Ð(KÐ(KØ”×%Ò% j°¤mÑ4Ô4Ð4øåˆtŒ~ÑÔ¥ U¡¤¨a¡Ò/Ð/õ
 �3˜tœ~Ñ.Ô.Ñ/Ô/ˆHÝ�3˜tœ~Ñ.Ô.Ñ/Ô/ˆHÝ!&Ø˜( Q™,­¨X¸Ñ-@ÅCÈÁJÄJÑ,NÑ(OÔ(Oñ"ô "Ðð =Ð<Ð);Ð<Ñ<Ô<ˆDŒNàŒ×ÒÑÔÐØ×,Ò,¨U°FÑ;Ô;ˆŒØˆŒ	ˆ	ˆ	r   c           	      óà  — ddddddddd	œ}t          t          |                     ¦   «         d
„ ¬¦  «        ¦  «        }|€g d¢}n|}t          t	          |                     ¦   «         ¦  «        ¦  «        D ]G}t          |                     ¦   «         ¦  «        |         }|t	          |¦  «        k     r||         ||<   ŒHg d¢}|D ]+\  }}		 ||	         ||<   Œ# t          $ r d|t          <   Y Œ(w xY w|S )zä
        Returns colorscale used for dendrogram tree clusters.

        :param (list) colorscale: Colors to use for the plot in rgb format.
        :rtype (dict): A dict of default colors mapped to the user colorscale.

        ÚredÚgreenÚblueÚcyanÚmagentaÚyellowÚblackÚwhite)ÚrÚgÚbÚcÚmÚyÚkÚwc                 ó   — | d         S )Nr   r8   )Úts    r   r   z,_Dendrogram.get_color_dict.<locals>.<lambda>Î   s
   € ÀQÀqÄT€ r   )ÚkeyN)úrgb(0,116,217)zrgb(35,205,205)zrgb(61,153,112)zrgb(40,35,35)zrgb(133,20,75)zrgb(255,65,54)zrgb(255,255,255)zrgb(255,220,0))
)ÚC0ra   )ÚC1r`   )ÚC2r_   )ÚC3rb   )ÚC4rc   )ÚC5rd   )ÚC6re   )ÚC7r`   )ÚC8r_   )ÚC9rb   rj   )	r   ÚsortedÚitemsrA   r!   ÚkeysÚlistÚKeyErrorÚn)
rH   r*   ÚdÚdefault_colorsÚrgb_colorscalerQ   re   Únew_old_color_mapÚncÚocs
             r   Úget_color_dictz_Dendrogram.get_color_dict´   sO  € ð ØØØØØØð ð
ð 
ˆõ %¥V¨A¯GªG©I¬I¸>¸>Ð%JÑ%JÔ%JÑKÔKˆàÐð	ð 	ð 	ˆNˆNð (ˆNå•s˜>×.Ò.Ñ0Ô0Ñ1Ô1Ñ2Ô2ð 	6ð 	6ˆAÝ�^×(Ò(Ñ*Ô*Ñ+Ô+¨AÔ.ˆAØ•3�~Ñ&Ô&Ò&Ð&Ø$2°1Ô$5�˜qÑ!øð
ð 
ð 
Ðð (ð 	5ð 	5‰FˆB�ð5Ø%3°BÔ%7�˜rÑ"Ð"øÝð 5ð 5ð 5ð %5��qÑ!Ð!Ð!ð	5øøøð Ðs   ÃCÃC+Ã*C+c           	      óˆ  ‡ ‡— dddddddddœ}t          ‰ j        ¦  «        dk    rq‰ j        }‰ j        d	v r‰ j        }|‰ j        vr
i ‰ j        |<   ˆˆ fd
„‰ j        D ¦   «         ‰ j        |         d<   ‰ j        ‰ j        |         d<   d‰ j        |         d<   ‰ j        ‰                              |¦  «         ‰ j        ‰         S )zá
        Sets and returns default axis object for dendrogram figure.

        :param (str) axis_key: E.g., 'xaxis', 'xaxis1', 'yaxis', yaxis1', etc.
        :rtype (dict): An axis_key dictionary with set parameters.

        ÚlinearÚoutsideÚallticksÚtozeroTF)ÚtypeÚticksÚmirrorÚ	rangemodeÚshowticklabelsÚzerolineÚshowgridÚshowliner   )r4   r6   c                 ó0   •— g | ]}|‰j         ‰         z  ‘ŒS r8   )r=   )r9   ÚzvÚaxis_keyrH   s     €€r   r;   z/_Dendrogram.set_axis_layout.<locals>.<listcomp>  s2   ø€ ð 8ð 8ð 8Ø-/��T”Y˜xÔ(Ñ(ð8ð 8ð 8r   ÚtickvalsÚticktextÚarrayÚtickmode)r!   r)   r/   r(   r0   r   r@   Úupdate)rH   r‘   Úaxis_defaultsÚaxis_key_labelss   ``  r   Úset_axis_layoutz_Dendrogram.set_axis_layout  s   øø€ ð ØØ Ø!Ø"ØØØð	
ð 	
ˆõ ˆtŒ{ÑÔ˜qÒ Ð Ø"œjˆOØÔÐ#4Ð4Ð4Ø"&¤*�Ø d¤kÐ1Ð1Ø/1�”˜OÑ,ð8ð 8ð 8ð 8ð 8Ø37´>ð8ñ 8ô 8ˆDŒK˜Ô(¨Ñ4ð 8<´{ˆDŒK˜Ô(¨Ñ4Ø7>ˆDŒK˜Ô(¨Ñ4àŒ�HÔ×$Ò$ ]Ñ3Ô3Ð3àŒ{˜8Ô$Ð$r   c                 ó¸   — | j                              ddd||dœ¦  «         |                      | j        ¦  «         |                      | j        ¦  «         | j         S )zP
        Sets and returns default layout object for dendrogram figure.

        FÚclosest)Ú
showlegendÚautosizeÚ	hovermoderI   rJ   )r   r–   r™   r/   r0   )rH   rI   rJ   s      r   rG   z_Dendrogram.set_figure_layout$  sm   € ð
 	Œ×Òà#Ø!Ø&ØØ ðð ñ	
ô 	
ð 	
ð 	×Ò˜TœZÑ(Ô(Ð(Ø×Ò˜TœZÑ(Ô(Ð(àŒ{Ðr   c                 ó”  —  ||¦  «        } ||¦  «        }t                                || j        | j        d|¬¦  «        }	t                               |	d         ¦  «        }
t                               |	d         ¦  «        }t                               |	d         ¦  «        }t                               |	d         ¦  «        }|                      |¦  «        }g }t          t          |
¦  «        ¦  «        D �]H}| j        dv r	|
|         }n||         }| j        dv r	||         }n|
|         }||         }d}|r||         }t          d	t           
                    | j        | j                 |¦  «        t           
                    | j        | j                 |¦  «        d
t          ||         ¬¦  «        |d¬¦  «        }	 t          | j        d         ¦  «        }n# t          $ r d}Y nw xY w	 t          | j        d         ¦  «        }n# t          $ r d}Y nw xY wd|› �|d<   d|› �|d<   |                     |¦  «         �ŒJ||
|||	d         fS )ao  
        Calculates all the elements needed for plotting a dendrogram.

        :param (ndarray) X: Matrix of observations as array of arrays
        :param (list) colorscale: Color scale for dendrogram tree clusters
        :param (function) distfun: Function to compute the pairwise distance
                                   from the observations
        :param (function) linkagefun: Function to compute the linkage matrix
                                      from the pairwise distances
        :param (list) hovertext: List of hovertext for constituent traces of dendrogram
        :rtype (tuple): Contains all the traces in the following order:
            (a) trace_list: List of Plotly trace objects for dendrogram tree
            (b) icoord: All X points of the dendrogram tree as array of arrays
                with length 4
            (c) dcoord: All Y points of the dendrogram tree as array of arrays
                with length 4
            (d) ordered_labels: leaf labels in the order they are going to
                appear on the plot
            (e) P['leaves']: left-to-right traversal of the leaves

        T)r(   r)   Úno_plotr   ÚicoordÚdcoordÚivlÚ
color_list)Útopr	   NÚscatterÚlines)ÚcolorÚtext)r‡   r   rd   ÚmodeÚmarkerr©   Ú	hoverinfor5   Ú r   r/   rd   r0   r<   )r   r,   r(   r)   Únpr”   r�   rA   r!   ÚdictÚmultiplyr=   r/   r0   rC   Ú
ValueErrorrB   )rH   r'   r*   r   r   r   r   r{   ÚZÚPr¡   r¢   rN   r¤   ÚcolorsÚ
trace_listrQ   ÚxsÚysÚ	color_keyÚhovertext_labelÚtraceÚx_indexÚy_indexs                           r   r>   z!_Dendrogram.get_dendrogram_traces8  sk  € ð0 ˆG�A‰JŒJˆØˆJ�q‰MŒMˆÝ�NŠNØØÔ(Ø”;ØØ+ð ñ 
ô 
ˆõ —’˜!˜Hœ+Ñ&Ô&ˆÝ—’˜!˜Hœ+Ñ&Ô&ˆÝŸš ! E¤(Ñ+Ô+ˆÝ—X’X˜a œoÑ.Ô.ˆ
Ø×$Ò$ ZÑ0Ô0ˆàˆ
å•s˜6‘{”{Ñ#Ô#ð '	%ñ '	%ˆAð ÔÐ#4Ð4Ð4Ø˜A”Y��à˜A”Y�àÔÐ#4Ð4Ð4Ø˜A”Y��à˜A”Y�Ø" 1œˆIØ"ˆOØð /Ø"+¨A¤,�ÝØÝ—+’+˜dœi¨¬
Ô3°RÑ8Ô8Ý—+’+˜dœi¨¬
Ô3°RÑ8Ô8ØÝ &¨Ô"3Ð4Ñ4Ô4Ø$Ø ðñ ô ˆEðÝ˜dœj¨œnÑ-Ô-��øÝð ð ð Ø���ðøøøðÝ˜dœj¨œnÑ-Ô-��øÝð ð ð Ø���ðøøøð + ˜]˜]ˆE�'‰NØ* ˜]˜]ˆE�'‰Nà×Ò˜eÑ$Ô$Ð$Ñ$à˜6 6¨>¸1¸X¼;ÐFÐFs$   Æ;GÇG%Ç$G%Ç)HÈHÈH)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r®   ÚinfrU   r�   r™   rG   r>   r8   r   r   r%   r%   l   s¨   € € € € € ØCÐCð
 ØØØŒfØŒvØØØØ7Ð7ØØðCð Cð Cð CðJKð Kð KðZ!%ð !%ð !%ðFð ð ð(SGð SGð SGð SGð SGr   r%   )Úcollectionsr   Úplotlyr   r   Úplotly.graph_objsr   Ú
get_moduler®   r   r   r   r-   Úobjectr%   r8   r   r   ú<module>rÇ      s  ðØ #Ð #Ð #Ð #Ð #Ð #à /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø (Ð (Ð (Ð (Ð (Ð (ð !ÐÔ  Ñ)Ô)€Ø!ÐÔ! 'Ñ*Ô*€Ø!ÐÔ!Ð";Ñ<Ô<€Ø!ÐÔ! /Ñ2Ô2€ð
 ØØØØ3Ð3ØØð\Mð \Mð \Mð \Mð~_Gð _Gð _Gð _Gð _G�&ñ _Gô _Gð _Gð _Gð _Gr   