U
    Y»{j¸!  ã                   @   sê   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 zd dlmZ W n  ek
r˜   d dlmZ Y nX dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Z ddd„Z!d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                 C   s   t | tƒot | tƒ S ©N)Ú
isinstancer   Ústr)Úobj© r   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/plotly/figure_factory/utils.pyÚis_sequence   s    r   c                    sj   ddl m‰  t| d ˆ ƒr<t‡ fdd„| D ƒƒsft d¡‚n*t| d tƒrftdd„ | D ƒƒsft d¡‚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   s   | ]}t |ˆ ƒV  qd S r   ©r   ©Ú.0Úitemr   r   r   Ú	<genexpr>-   s     z!validate_index.<locals>.<genexpr>z^Error in indexing column. Make sure all entries of each column are all numbers or all strings.c                 s   s   | ]}t |tƒV  qd S r   ©r   r   r   r   r   r   r"   6   s     N©Únumbersr   r   Úallr   ÚPlotlyErrorr   )Z
index_valsr   r   r   Úvalidate_index#   s    ÿÿr(   c                    st   ddl m‰  | D ]^}t|d ˆ ƒrDt‡ fdd„|D ƒƒsnt d¡‚qt|d tƒrtdd„ |D ƒƒst d¡‚q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   s   | ]}t |ˆ ƒV  qd S r   r   r   r   r   r   r"   J   s     z%validate_dataframe.<locals>.<genexpr>zWError in dataframe. Make sure all entries of each column are either numbers or strings.c                 s   s   | ]}t |tƒV  qd S r   r#   r   r   r   r   r"   R   s     Nr$   )ÚarrayZvectorr   r   r   Úvalidate_dataframe?   s    ÿÿr*   c                     s0   t | d ƒ‰ t‡ fdd„| D ƒƒr,t 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   s   | ]}t |ƒˆ kV  qd S r   )Úlen)r    Úlst©Úlengthr   r   r"   b   s     z(validate_equal_length.<locals>.<genexpr>z<Oops! Your data lists or ndarrays should be the same length.N)r+   Úanyr   r'   )Úargsr   r-   r   Úvalidate_equal_length[   s
    ÿr1   c               
   K   sZ   |   ¡ D ]L\}}z|dkr*td ||¡ƒ‚W q tk
rR   t d ||¡¡‚Y qX q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Úvalr   r   r   Úvalidate_positive_scalarsh   s    r9   c                 C   s4   zdd„ | D ƒW S  t k
r.   t d¡‚Y nX dS )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                 S   s   g | ]}|D ]}|‘qqS r   r   )r    Zsublistr!   r   r   r   Ú
<listcomp>�   s       zflatten.<locals>.<listcomp>z\Your data array could not be flattened! Make sure your data is entered as lists or ndarrays!N)r5   r   r'   )r)   r   r   r   Úflattenx   s    ÿr;   c                 C   sì   t | ƒ}t| tƒs&t| tƒs&t d¡‚| D ]}t|tƒr*t d¡‚q*t|d ƒD ]"}| | | |d  krPt d¡‚qPg }| t	dƒ| d g¡ t|d ƒD ]2}g }| | | ¡ | | |d  ¡ | |¡ qš| | |d  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   ÚinfN)
r+   r   ÚtupleÚlistr   r'   r   ÚrangeÚappendÚfloat)Zendptsr.   r!   ÚkZ	intervalsÚintervalr   r   r   Úendpts_to_intervalsŠ   s0    ÿ
ÿÿrE   ÚcolTú#0f0f0fc                 C   s  d|d |  | }|std}	d}
|dkrJ|d ||  d|  }d}d}qä|dkrä|d ||  d|  }d}d	}np|dkr¦d}	d
}
|d ||  d|  }d}d}n>|dkräd}
|d ||  d|  }|rØd}d}	nd}d}	d}t ||	|
||ddd| t d|d�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.
    r<   ÚcenterÚmiddlerF   g      à?g{®Gázð?r   ÚrowéZ   Úbottomg      ð?i  Úleftg{®Gáz„¿ÚrightFZpaperé   )ÚsizeÚcolor)
Ú	textangleÚxanchorÚyanchorÚxÚyZ	showarrowZxrefZyrefÚtextZfont)Údict)rW   ZlaneZnum_of_lanesZsubplot_spacingZrow_colZflippedZ
right_sideZ
text_colorÚlrS   rT   rU   rV   rR   Zannotation_dictr   r   r   Úannotation_dict_for_label¿   sP    
örZ   Úandc                 C   sD   t | ƒdk rt d¡‚t | ƒd d d | d |d  }|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 {}Ú.)r+   r   r'   r4   )ÚiterableZconjZperiodÚtemplater   r   r   Úlist_of_options  s    ÿ$r`   )rF   TTrG   )r[   T)#Ú
__future__r   ÚdecimalZplotlyr   Zplotly.colorsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   Úcollections.abcr   ÚImportErrorÚcollectionsr   r(   r*   r1   r9   r;   rE   rZ   r`   r   r   r   r   Ú<module>   s(   H:    ø
G