
    gq(                         d dl mZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ  ej                  d      Zd Z	 	 	 	 	 	 	 ddZd	 Zd
 Z G d de      Zy)    N)
exceptionsoptional_imports)utils)
graph_objs)ColorscaleValidatornumpyc                    |qt        |t              rat        j                  | |       t	        t        |             D ]4  }t        | |         t        ||         k7  s!t        j                  d       |r/t        |      t        | d         k7  rt        j                  d      |r-t        |      t        |       k7  rt        j                  d      yy)a(  
    Annotated-heatmap-specific validations

    Check that if a text matrix is supplied, it has the same
    dimensions as the z matrix.

    See FigureFactory.create_annotated_heatmap() for params

    :raises: (PlotlyError) If z and text matrices do not  have the same
        dimensions.
    Nz*z and text should have the same dimensionsr   zMoops, the x list that you provided does not match the width of your z matrix zNoops, the y list that you provided does not match the length of your z matrix )
isinstancelistr   validate_equal_lengthrangelenr   PlotlyError)zxyannotation_textlsts        e/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/plotly/figure_factory/_annotated_heatmap.pyvalidate_annotated_heatmapr      s     "z/4'H##A7Q= 	C1S6{c/#"677 ,,C 	 	q6S1Y((*  	q6SV((+   	    c                    ||ng }t        | |||       t               }	|	j                  |      }t        | ||||||fi |j	                         }
|s|r;t        dd| |||||d|}t        |
t        dddd      t        ddd	      
      }n8t        dd| |||d|}t        |
t        dddd      t        ddd      
      }|g}t        j                  ||      S )a  
    **deprecated**, use instead
    :func:`plotly.express.imshow`.

    Function that creates annotated heatmaps

    This function adds annotations to each cell of the heatmap.

    :param (list[list]|ndarray) z: z matrix to create heatmap.
    :param (list) x: x axis labels.
    :param (list) y: y axis labels.
    :param (list[list]|ndarray) annotation_text: Text strings for
        annotations. Should have the same dimensions as the z matrix. If no
        text is added, the values of the z matrix are annotated. Default =
        z matrix values.
    :param (list|str) colorscale: heatmap colorscale.
    :param (list) font_colors: List of two color strings: [min_text_color,
        max_text_color] where min_text_color is applied to annotations for
        heatmap values < (max_value - min_value)/2. If font_colors is not
        defined, the colors are defined logically as black or white
        depending on the heatmap's colorscale.
    :param (bool) showscale: Display colorscale. Default = False
    :param (bool) reversescale: Reverse colorscale. Default = False
    :param kwargs: kwargs passed through plotly.graph_objs.Heatmap.
        These kwargs describe other attributes about the annotated Heatmap
        trace such as the colorscale. For more information on valid kwargs
        call help(plotly.graph_objs.Heatmap)

    Example 1: Simple annotated heatmap with default configuration

    >>> import plotly.figure_factory as ff

    >>> z = [[0.300000, 0.00000, 0.65, 0.300000],
    ...      [1, 0.100005, 0.45, 0.4300],
    ...      [0.300000, 0.00000, 0.65, 0.300000],
    ...      [1, 0.100005, 0.45, 0.00000]]

    >>> fig = ff.create_annotated_heatmap(z)
    >>> fig.show()
    heatmap)typer   r   r   
colorscale	showscalereversescale    topzrgb(0, 0, 0))ticksdtickside	gridcolorz  )r!   r"   
ticksuffix)annotationsxaxisyaxis)r   r   r   r   r   F)r!   r#   r$   showticklabels)r!   r%   r)   )datalayout )r   r   validate_coerce_AnnotatedHeatmapmake_annotationsdictr   Figure)r   r   r   r   r   font_colorsr   r   kwargscolorscale_validatorr&   tracer+   r*   s                 r   create_annotated_heatmapr6   0   s9   j "-!8+bKq!Q8 /0%55jAJ#	1a*k<KQ  	A 	
!%	
 	
 #RquORqT:
  
!%
 
 #uu RDG
 7D$v66r   c                    | j                         } | j                  d      r7| j                  d      j                  d      D cg c]  }t        |       c}S | j                  d      rt	        j
                  |       S |S c c}w )Nrgbzrgba(),#)strip
startswithsplitintclrs
hex_to_rgb)	color_strdefaultvs      r   to_rgb_color_listrD      sm    !IE" ) 9 ? ? DE1AEE			c	"y))	 Fs   Bc                 <    | d   dz  | d   dz  z   | d   dz  z   dkD  S )Nr   gA`"?r   gbX9?   gv/?   r,   )background_colors    r   should_use_black_textrI      sB    e#
1

%	&
1

%	& 		 r   c                   "    e Zd ZdZd Zd Zd Zy)r.   zH
    Refer to TraceFactory.create_annotated_heatmap() for docstring
    c                    || _         |r|| _        nt        t        |d               | _        |r|| _        nt        t        |            | _        ||| _        n| j                   | _        || _        || _        || _        t        rmt        | j                   t        j                        rIt        j                  | j                         | _        t        j                  | j                         | _        nbt!        | j                   D 	
cg c]  }	|	D ]  }
|
  c}
}	      | _        t#        | j                   D 	
cg c]  }	|	D ]  }
|
  c}
}	      | _        |j%                  dd       
|d   | _        |j%                  dd       
|d   | _        | j                  | j                  z   dz  | _        |j%                  dd       |d   | _        y y c c}
}	w c c}
}	w )Nr   zminzmaxrF   zmid)r   r   r   r   r   r   r   r   r2   npr
   ndarrayaminrL   amaxrM   minmaxgetrN   )selfr   r   r   r   r   r2   r   r3   rowrC   s              r   __init__z_AnnotatedHeatmap.__init__   su    DF3qt9%DFDF3q6]DF&#2D #'66D $(&*TVVRZZ0DIDI$&&>3#>QQ>Q>?DI$&&>3#>QQ>Q>?DI::fd#/vDI::fd#/vDIYY*a/	::fd#/vDI 0 ?>s   G
9G
c                 ~   g d}dg}d}d}| j                   r"| j                   d   }| j                   d   }||fS | j                  |v r| j                  r|}|}||fS | j                  |v r|}|}||fS | j                  |v r| j                  r|}|}||fS | j                  |v r|}|}||fS t        | j                  t              rst        | j                  d   d   g d      }t        | j                  d   d   g d      }| j                  r||}}t        |      r|}n|}t        |      r|}||fS |}||fS |}|}||fS )	a  
        Get font color for annotations.

        The annotated heatmap can feature two text colors: min_text_color and
        max_text_color. The min_text_color is applied to annotations for
        heatmap values < (max_value - min_value)/2. The user can define these
        two colors. Otherwise the colors are defined logically as black or
        white depending on the heatmap's colorscale.

        :rtype (string, string) min_text_color, max_text_color: text
            color for annotations for heatmap values <
            (max_value - min_value)/2 and text color for annotations for
            heatmap values >= (max_value - min_value)/2
        )GreysGreensBluesYIGnBuYIOrRdRdBuPicnicJetHot	BlackbodyEarthElectricViridisCividisRedsz#FFFFFFz#000000r   r   )   rj   rj   )r2   r   r   r
   r   rD   rI   )	rV   colorscalescolorscales_reversewhiteblackmin_text_colormax_text_colormin_colmax_cols	            r   get_text_colorz _AnnotatedHeatmap.get_text_color   s    
"  &h!--a0N!--b1ND ~--C __+0A0A"N"N> ~--= __+"N"N8 ~--7 __ 338I8I"N"N2 ~--1 __ 33"N"N, ~--+ .'(:1(=OG'(;A(>PG   #*G$W-!&!&$W-!& ~--	 "' ~-- #N"N~--r   c                    t         j                  |       \  }}g }t        | j                        D ]  \  }}t        |      D ]  \  }}|| j                  k  r|n|}|j                  t        j                  j                  t        | j                  |   |         | j                  |   | j                  |   ddt        |      d               |S )z
        Get annotations for each cell of the heatmap with graph_objs.Annotation

        :rtype (list[dict]) annotations: list of annotations for each cell of
            the heatmap
        x1y1)colorF)textr   r   xrefyreffont	showarrow)r.   rs   	enumerater   rN   appendr   r+   
Annotationstrr   r   r   r0   )	rV   ro   rp   r&   nrW   mval
font_colors	            r   r/   z"_AnnotatedHeatmap.make_annotations  s     *;)I)I$)O&' 	FAs#C. 3/2TYY^N
""%%00 !5!5a!8!;<&&)&&)!!!
3"' 1 
	 r   N)__name__
__module____qualname____doc__rX   rs   r/   r,   r   r   r.   r.      s    $'LI.Vr   r.   )NNNPlasmaNFF)plotly.colorscolorsr?   plotlyr   r   plotly.figure_factoryr   plotly.graph_objsr   plotly.validators.heatmapr   
get_modulerO   r   r6   rD   rI   objectr.   r,   r   r   <module>r      se     / ' ( 9 !  )"N 
c7LM Mr   