
    c!                         d dl m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mZmZmZmZmZmZ 	 d dlmZ n# e$ r	 d dlmZ Y nw xY wd Zd Zd Zd	 Zd
 Zd Zd Z 	 	 	 	 ddZ!ddZ"dS )    )absolute_importN)
exceptions)DEFAULT_PLOTLY_COLORSPLOTLY_SCALEScolor_parsercolorscale_to_colorscolorscale_to_scaleconvert_to_RGB_255find_intermediate_color
hex_to_rgb	label_rgbn_colorsunconvert_from_RGB_255unlabel_rgbvalidate_colorsvalidate_colors_dictvalidate_colorscalevalidate_scale_values)Sequencec                 X    t          | t                    ot          | t                     S N)
isinstancer   str)objs    ;lib/python3.11/site-packages/plotly/figure_factory/utils.pyis_sequencer      s$    c8$$AZS-A-A)AA    c                 6   ddl m t          | d                   r1t          fd| D                       st	          j        d          dS t          | d         t                    r-t          d | D                       st	          j        d          dS dS )z
    Validates if a list contains all numbers or all strings

    :raises: (PlotlyError) If there are any two items in the list whose
        types differ
    r   Numberc              3   8   K   | ]}t          |          V  d S r   r   .0itemr    s     r   	<genexpr>z!validate_index.<locals>.<genexpr>-   s-      CC:dF++CCCCCCr   z^Error in indexing column. Make sure all entries of each column are all numbers or all strings.c              3   @   K   | ]}t          |t                    V  d S r   r   r   r$   r%   s     r   r&   z!validate_index.<locals>.<genexpr>6   s,      @@T:dC((@@@@@@r   Nnumbersr    r   allr   PlotlyErrorr   )
index_valsr    s    @r   validate_indexr/   #   s     *Q-(( CCCC
CCCCC 	(  	 	 
JqM3	'	' @@Z@@@@@ 	(   	 	r   c                 :   ddl m | D ]}t          |d                   r0t          fd|D                       st	          j        d          Ht          |d         t                    r-t          d |D                       st	          j        d          dS )z
    Validates all strings or numbers in each dataframe column

    :raises: (PlotlyError) If there are any two items in any list whose
        types differ
    r   r   c              3   8   K   | ]}t          |          V  d S r   r"   r#   s     r   r&   z%validate_dataframe.<locals>.<genexpr>J   s-      CCDz$//CCCCCCr   zWError in dataframe. Make sure all entries of each column are either numbers or strings.c              3   @   K   | ]}t          |t                    V  d S r   r(   r)   s     r   r&   z%validate_dataframe.<locals>.<genexpr>R   s,      @@z$,,@@@@@@r   Nr*   )arrayvectorr    s     @r   validate_dataframer5   ?   s       fQi(( 	CCCCFCCCCC  ,*   q	3'' 	@@@@@@@  ,*   r   c                      t          | d                   t          fd| D                       rt          j        d          dS )z
    Validates that data lists or ndarrays are the same length.

    :raises: (PlotlyError) If any data lists are not the same length.
    r   c              3   >   K   | ]}t          |          k    V  d S r   )len)r$   lstlengths     r   r&   z(validate_equal_length.<locals>.<genexpr>b   s.      
.
.#3s88v
.
.
.
.
.
.r   z<Oops! Your data lists or ndarrays should be the same length.N)r8   anyr   r-   )argsr:   s    @r   validate_equal_lengthr=   [   s[     a\\F

.
.
.
.
.
.
... 
$M
 
 	

 
r   c                      |                                  D ]e\  }}	 |dk    r#t          d                    ||                    0# t          $ r) t	          j        d                    ||                    w xY wdS )z
    Validates that all values given in key/val pairs are positive.

    Accepts kwargs to improve Exception messages.

    :raises: (PlotlyError) If any value is < 0 or raises.
    r   z{} must be > 0, got {}z{} must be a number, got {}N)items
ValueErrorformat	TypeErrorr   r-   )kwargskeyvals      r   validate_positive_scalarsrF   h   s     LLNN Y YS	Yax L !9!@!@c!J!JKKKL 	Y 	Y 	Y()F)M)McSV)W)WXXX	Y	Y Ys   )A3A8c                 `    	 d | D             S # t           $ r t          j        d          w xY w)z
    Uses list comprehension to flatten array

    :param (array): An iterable to flatten
    :raises (PlotlyError): If iterable is not nested.
    :rtype (list): The flattened list.
    c                     g | ]	}|D ]}|
S  rI   )r$   sublistr%   s      r   
<listcomp>zflatten.<locals>.<listcomp>   s%    >>>g>>d>>>>r   z\Your data array could not be flattened! Make sure your data is entered as lists or ndarrays!)rB   r   r-   )r3   s    r   flattenrL   x   sP    
>>E>>>> 
 
 
$,
 
 	

s    -c                    t          |           }t          | t                    s)t          | t                    st	          j        d          | D ]+}t          |t                    rt	          j        d          ,t          |dz
            D ]+}| |         | |dz            k    rt	          j        d          ,g }|                    t          d          | d         g           t          |dz
            D ]R}g }|                    | |                    |                    | |dz                       |                    |           S|                    | |dz
           t          d          g           |S )a  
    Returns a list of intervals for categorical colormaps

    Accepts a list or tuple of sequentially increasing numbers and returns
    a list representation of the mathematical intervals with these numbers
    as endpoints. For example, [1, 6] returns [[-inf, 1], [1, 6], [6, inf]]

    :raises: (PlotlyError) If input is not a list or tuple
    :raises: (PlotlyError) If the input contains a string
    :raises: (PlotlyError) If any number does not increase after the
        previous one in the sequence
    zZThe intervals_endpts argument must be a list or tuple of a sequence of increasing numbers.   z-infr   inf)
r8   r   tuplelistr   r-   r   rangeappendfloat)endptsr:   r%   k	intervalsintervals         r   endpts_to_intervalsrY      s    [[Fv'' 
:ft+E+E 
$%
 
 	
   dC   	(  	 6A:  !9q1u% 	(  	 	%--3444vz"" 	' 	'AHOOF1I&&&OOF1q5M***X&&&&&!,eEll;<<<r   colT#0f0f0fc                 z   d|dz
  |z  z
  |z  }|s<d}	d}
|dk    r|dz
  ||z   z  d|z  z   }d}d}nb|dk    r|dz
  ||z   z  d|z  z   }d}d	}nF|dk    rd}	d
}
|dz
  ||z   z  d|z  z   }d}d}n&|dk    r d}
|dz
  ||z   z  d|z  z   }|rd}d}	nd}d}	d}t          ||	|
||ddd| t          d|          
  
        }|S )a#  
    Returns annotation dict for label of n labels of a 1xn or nx1 subplot.

    :param (str) text: the text for a label.
    :param (int) lane: the label number for text. From 1 to n inclusive.
    :param (int) num_of_lanes: the number 'n' of rows or columns in subplot.
    :param (float) subplot_spacing: the value for the horizontal_spacing and
        vertical_spacing params in your plotly.tools.make_subplots() call.
    :param (str) row_col: choose whether labels are placed along rows or
        columns.
    :param (bool) flipped: flips text by 90 degrees. Text is printed
        horizontally if set to True and row_col='row', or if False and
        row_col='col'.
    :param (bool) right_side: only applicable if row_col is set to 'row'.
    :param (str) text_color: color of the text.
    rN   centermiddlerZ   g      ?g{Gz?r   rowZ   bottomg      ?i  leftg{GzrightFpaper   )sizecolor)
	textanglexanchoryanchorxy	showarrowxrefyreftextfont)dict)rp   lanenum_of_lanessubplot_spacingrow_colflipped
right_side
text_colorlri   rj   rk   rl   rh   annotation_dicts                  r   annotation_dict_for_labelr|      so   4 
lQ/1	1lCA e 	a/12S1W<AAII 	a/12S1W<AAIe 	GGa/12S1W<AAII 		Ga/12S1W<A " !I

r,,,  O r   andc                     t          |           dk     rt          j        d          t          |           dz
  dz  dz   |z   dz   |dz  z   } |j        |  S )z
    Returns an English listing of objects seperated by commas ','

    For example, ['foo', 'bar', 'baz'] becomes 'foo, bar and baz'
    if the conjunction 'and' is selected.
       z1Your list or tuple must contain at least 2 items.z{}, z{} z {}.)r8   r   r-   rA   )iterableconjperiodtemplates       r   list_of_optionsr     sm     8}}q 
$?
 
 	
 H!V+e3d:UBVc\QH8?H%%r   )rZ   TTr[   )r}   T)#
__future__r   decimalplotlyr   plotly.colorsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   collections.abcr   ImportErrorcollectionsr   r/   r5   r=   rF   rL   rY   r|   r   rI   r   r   <module>r      s   & & & & & &                                          &%((((((( % % %$$$$$$$$%B B B  8  8

 

 

Y Y Y 
 
 
$2 2 2t D D D DN& & & & & &s   = A
A