Ë
    {�h76  ã                   óê   — 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y	)é    )ÚOrderedDict)Ú
exceptionsÚoptional_imports)Ú
graph_objsÚnumpyÚscipyzscipy.cluster.hierarchyzscipy.spatialÚbottomNc                 ó.   — t         j                  | d«      S ©NÚcomplete©ÚschÚlinkage©Úxs    ú_/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/plotly/figure_factory/_dendrogram.pyú<lambda>r      s   € œŸ™ Q¨
Ó3€ ó    c           
      óN  — t         rt        rt        st        d«      ‚| j                  }t        |«      dk7  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.)Ú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�‚{Ü×ÑÐAÔBà€Ü—,‘,×$Ñ$ˆäØ	ØØØØØØØ'ô	€Jô ×Ñ *§/¡/¸*×:KÑ:KÔLÐLr   c                   óp   — 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
y)r%   z9Refer to FigureFactory.create_dendrogram() for docstring.r	   NÚxaxisÚyaxisc                 ó.   — t         j                  | d«      S r   r   r   s    r   r   z_Dendrogram.<lambda>z   s   € œSŸ[™[¨¨JÓ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                  }	| j                  |||	|
||«      \  }}}}}|| _        || _        |j                  «       }|j                  «       }g | _        t        t        |«      «      D ];  }||   dk(  sŒ||   | j                  vsŒ| j                  j!                  ||   «       Œ= t        | j                  «      t        |«      dz   kD  ryt#        t%        | j                  «      «      }t#        t'        | j                  «      «      }t        ||dz   t#        ||z
  t        |«      z  «      «      }|D �cg c]  }|‘Œ c}| _        | j                  j)                  «        | j+                  ||«      | _        || _        y c c}w )Né   )Úleftr	   éÿÿÿÿ)Úrightr	   g        )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_labelsr7   Ú
yvals_flatÚ
xvals_flatÚiÚl_borderÚr_borderÚcorrect_leaves_posÚvs                            r   Ú__init__z_Dendrogram.__init__o   s'  € ð 'ˆÔØˆŒØˆŒ
ØˆŒ
ØˆŒ	ØˆŒØ—Z‘Z  D§J¡J°Ð2ˆŒ	Ø—z‘z 2 t§z¡z°2Ð6ˆŒà×ÑÐ1Ñ1Ø$%ˆD�I‰I�d—j‘jÒ!à$&ˆD�I‰I�d—j‘jÑ!à×ÑÐ2Ñ2Ø$%ˆD�I‰I�d—j‘jÒ!à$&ˆD�I‰I�d—j‘jÑ!àˆ?Ü—l‘l×(Ñ(ˆGà<@×<VÑ<VØˆz˜7 J°	¸?ó=
Ñ9ˆ�E˜5 .°&ð %ˆŒØˆŒØ—]‘]“_ˆ
Ø—]‘]“_ˆ
àˆŒä”s˜:“Ó'ò 	5ˆAØ˜!‰} Ó#¨
°1©¸T¿^¹^Ò(KØ—‘×%Ñ% j°¡mÕ4ð	5ô ˆt�~‰~Ó¤ U£¨a¡Ò/ô
 œ3˜tŸ~™~Ó.Ó/ˆHÜœ3˜tŸ~™~Ó.Ó/ˆHÜ!&Ø˜( Q™,¬¨X¸Ñ-@ÄCÈÃJÑ,NÓ(Oó"Ðð *<Ö< AšaÒ<ˆDŒNà�‰×ÑÔØ×,Ñ,¨U°FÓ;ˆŒØˆ�	ùò	 =s   È6	J c           	      óŠ  — ddddddddd	œ}t        t        |j                  «       d
„ ¬«      «      }|€g d¢}n|}t        t	        |j                  «       «      «      D ]5  }t        |j                  «       «      |   }|t	        |«      k  sŒ.||   ||<   Œ7 g d¢}|D ]  \  }}		 ||	   ||<   Œ |S # t        $ r d|t        <   Y Œ'w xY w)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   © )Úts    r   r   z,_Dendrogram.get_color_dict.<locals>.<lambda>Î   s
   € ÀQÀqÁT€ r   )Úkey)ú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))
)ÚC0r]   )ÚC1r\   )ÚC2r[   )ÚC3r^   )ÚC4r_   )ÚC5r`   )ÚC6ra   )ÚC7r\   )ÚC8r[   )ÚC9r^   rg   )	r   ÚsortedÚitemsr<   r!   ÚkeysÚlistÚKeyErrorÚn)
rC   r*   ÚdÚdefault_colorsÚrgb_colorscalerL   ra   Únew_old_color_mapÚncÚocs
             r   Úget_color_dictz_Dendrogram.get_color_dict´   sþ   € ð ØØØØØØð ñ
ˆô %¤V¨A¯G©G«I¹>Ô%JÓKˆàÐò	‰Nð (ˆNä”s˜>×.Ñ.Ó0Ó1Ó2ò 	6ˆAÜ�^×(Ñ(Ó*Ó+¨AÑ.ˆAØ”3�~Ó&Ó&Ø$2°1Ñ$5�˜qÒ!ð	6ò
Ðð (ò 	5‰FˆB�ð5Ø%3°BÑ%7�˜rÒ"ð	5ð Ðøô ò 5ð %5�œqÓ!ð	5ús   Â!B-Â-CÃCc           	      ó  — dddddddddœ}t        | j                  «      dk7  r«| j                  }| j                  d	v r| j                  }|| j
                  vri | j
                  |<   | j                  D �cg c]  }|| j                  |   z  ‘Œ c}| j
                  |   d
<   | j                  | j
                  |   d<   d| j
                  |   d<   | j
                  |   j                  |«       | j
                  |   S c c}w )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   ÚtickvalsÚticktextÚarrayÚtickmode)	r!   r)   r/   r(   r0   r   r;   r8   Úupdate)rC   Úaxis_keyÚaxis_defaultsÚaxis_key_labelsÚzvs        r   Úset_axis_layoutz_Dendrogram.set_axis_layout  sý   € ð ØØ Ø!Ø"ØØØñ	
ˆô ˆt�{‰{Ó˜qÒ Ø"Ÿj™jˆOØ×ÑÐ#4Ñ4Ø"&§*¡*�Ø d§k¡kÑ1Ø/1�—‘˜OÑ,à37·>±>ö8Ø-/��T—Y‘Y˜xÑ(Ó(ò8ˆD�K‰K˜Ñ(¨Ñ4ð 8<·{±{ˆD�K‰K˜Ñ(¨Ñ4Ø7>ˆD�K‰K˜Ñ(¨Ñ4à�‰�HÑ×$Ñ$ ]Ô3à�{‰{˜8Ñ$Ð$ùò8s   Á5C<c                 óÈ   — | j                   j                  ddd||dœ«       | j                  | j                  «       | j                  | j                  «       | j                   S )zP
        Sets and returns default layout object for dendrogram figure.

        FÚclosest)Ú
showlegendÚautosizeÚ	hovermoderD   rE   )r   r�   r•   r/   r0   )rC   rD   rE   s      r   rB   z_Dendrogram.set_figure_layout$  sZ   € ð
 	�‰×Ñà#Ø!Ø&ØØ ñô	
ð 	×Ñ˜TŸZ™ZÔ(Ø×Ñ˜TŸZ™ZÔ(à�{‰{Ðr   c                 ó  —  ||«      } ||«      }t         j                  || j                  | j                  d|¬«      }	t        j                  |	d   «      }
t        j                  |	d   «      }t        j                  |	d   «      }t        j                  |	d   «      }| j                  |«      }g }t        t        |
«      «      D �]  }| j                  dv r|
|   }n||   }| j                  dv r||   }n|
|   }||   }d}|r||   }t        d	t        j                  | j                  | j                     |«      t        j                  | j                  | j                     |«      d
t        ||   ¬«      |d¬«      }	 t        | j                  d   «      }	 t        | j                  d   «      }d|› �|d<   d|› �|d<   |j!                  |«       �Œ ||
|||	d   fS # t        $ r d}Y ŒTw xY w# t        $ r d}Y ŒLw xY w)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   r`   ÚmodeÚmarkerr¥   Ú	hoverinfor5   Ú r   r/   r`   r0   r7   )r   r,   r(   r)   ÚnprŽ   r~   r<   r!   ÚdictÚmultiplyr8   r/   r0   r>   Ú
ValueErrorr=   )rC   r'   r*   r   r   r   r   rx   ÚZÚPr�   rž   rI   r    ÚcolorsÚ
trace_listrL   ÚxsÚysÚ	color_keyÚhovertext_labelÚtraceÚx_indexÚy_indexs                           r   r9   z!_Dendrogram.get_dendrogram_traces8  s  € ñ0 �A‹JˆÙ�q‹MˆÜ�N‰NØØ×(Ñ(Ø—;‘;ØØ+ð ó 
ˆô —‘˜!˜H™+Ó&ˆÜ—‘˜!˜H™+Ó&ˆÜŸ™ ! E¡(Ó+ˆÜ—X‘X˜a ™oÓ.ˆ
Ø×$Ñ$ ZÓ0ˆàˆ
ä”s˜6“{Ó#ó '	%ˆAð ×ÑÐ#4Ñ4Ø˜A‘Y‘à˜A‘Y�à×ÑÐ#4Ñ4Ø˜A‘Y‘à˜A‘Y�Ø" 1™ˆIØ"ˆOÙØ"+¨A¡,�ÜØÜ—+‘+˜dŸi™i¨¯
©
Ñ3°RÓ8Ü—+‘+˜dŸi™i¨¯
©
Ñ3°RÓ8ØÜ &¨Ñ"3Ô4Ø$Ø ôˆEðÜ˜dŸj™j¨™nÓ-�ðÜ˜dŸj™j¨™nÓ-�ð  !  	˜]ˆE�'‰NØ   	˜]ˆE�'‰Nà×Ñ˜eÖ$ðO'	%ðR ˜6 6¨>¸1¸X¹;ÐFÐFøô ò Ø’ðûô
 ò Ø’ðús$   Æ GÆG0ÇG-Ç,G-Ç0G>Ç=G>)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rª   ÚinfrQ   r~   r•   rB   r9   rd   r   r   r%   r%   l   sP   „ ÙCð
 ØØØ�f‰fØ�v‰vØØØÙ7ØØóCòJKòZ!%òFó(SGr   r%   )Úcollectionsr   Úplotlyr   r   Úplotly.graph_objsr   Ú
get_modulerª   r   r   r   r-   Úobjectr%   rd   r   r   ú<module>rÃ      sŒ   ðÝ #ç /Ý (ð !Ð× Ñ  Ó)€Ø!Ð×!Ñ! 'Ó*€Ø!Ð×!Ñ!Ð";Ó<€Ø!Ð×!Ñ! /Ó2€ð
 ØØØÙ3ØØó\Mô~_G�&õ _Gr   