U
    Y»{jþ$  ã                   @   sX   d dl mZ d dlmZmZ d dlmZ e d¡Zdd„ Z	ddd„Z
G dd„ deƒZdS )é    )Úabsolute_import)Ú
exceptionsÚoptional_imports)Ú
graph_objsZpandasc                 C   s(   ddt | ƒg}t |ƒ|kr$t d¡‚dS )zï
    Table-specific validations

    Check that font_colors is supplied correctly (1, 3, or len(text)
        colors).

    :raises: (PlotlyError) If font_colors is supplied incorretly.

    See FigureFactory.create_table() for params
    é   é   z>Oops, font_colors should be a list of length 1, 3 or len(text)N)Úlenr   ZPlotlyError)Ú
table_textÚfont_colorsZfont_colors_len_options© r   ú[/var/www/html/bwave/python/venv/lib/python3.8/site-packages/plotly/figure_factory/_table.pyÚvalidate_table	   s
    ÿr   NFÚ çÍÌÌÌÌÌÜ?é   Únonec                 K   sò   |dk	r|nddgddgddgg}|dk	r.|ndddg}t | |ƒ t| |||||f|Ž ¡ }	t| |||||f|Ž ¡ }
tf d	|	d
|d|dœ|—Ž}|g}t|
t|	ƒ| d tddddd�tdddddddd�tddddddd�d�}tj||d�S )a†
  
    Function that creates data tables.

    See also the plotly.graph_objects trace
    :class:`plotly.graph_objects.Table`

    :param (pandas.Dataframe | list[list]) text: data for table.
    :param (str|list[list]) colorscale: Colorscale for table where the
        color at value 0 is the header color, .5 is the first table color
        and 1 is the second table color. (Set .5 and 1 to avoid the striped
        table effect). Default=[[0, '#66b2ff'], [.5, '#d9d9d9'],
        [1, '#ffffff']]
    :param (list) font_colors: Color for fonts in table. Can be a single
        color, three colors, or a color for each row in the table.
        Default=['#000000'] (black text for the entire table)
    :param (int) height_constant: Constant multiplied by # of rows to
        create table height. Default=30.
    :param (bool) index: Create (header-colored) index column index from
        Pandas dataframe or list[0] for each list in text. Default=False.
    :param (string) index_title: Title for index column. Default=''.
    :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 Plotly Table

    >>> from plotly.figure_factory import create_table

    >>> text = [['Country', 'Year', 'Population'],
    ...         ['US', 2000, 282200000],
    ...         ['Canada', 2000, 27790000],
    ...         ['US', 2010, 309000000],
    ...         ['Canada', 2010, 34000000]]

    >>> table = create_table(text)
    >>> table.show()

    Example 2: Table with Custom Coloring

    >>> from plotly.figure_factory import create_table
    >>> text = [['Country', 'Year', 'Population'],
    ...         ['US', 2000, 282200000],
    ...         ['Canada', 2000, 27790000],
    ...         ['US', 2010, 309000000],
    ...         ['Canada', 2010, 34000000]]
    >>> table = create_table(text,
    ...                      colorscale=[[0, '#000000'],
    ...                                  [.5, '#80beff'],
    ...                                  [1, '#cce5ff']],
    ...                      font_colors=['#ffffff', '#000000',
    ...                                 '#000000'])
    >>> table.show()

    Example 3: Simple Plotly Table with Pandas

    >>> from plotly.figure_factory import create_table
    >>> import pandas as pd
    >>> df = pd.read_csv('http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt', sep='	')
    >>> df_p = df[0:25]
    >>> table_simple = create_table(df_p)
    >>> table_simple.show()

    Nr   z#00083eç      à?z#ededeer   z#ffffffú#000000Zheatmapg      è?F)ÚtypeÚzZopacityÚ
colorscaleZ	showscaleÚ	hoverinfoé2   )ÚtÚbÚrÚlÚreversedé   r   )Z	autorangeÚzerolineÚ	gridwidthÚticksÚdtickÚtick0Úshowticklabelsg      à¿)r   r    r!   r"   r#   r$   )ÚannotationsÚheightÚmarginZyaxisZxaxis)ÚdataÚlayout)r   Ú_TableÚget_table_matrixÚmake_table_annotationsÚdictr   r   ZFigure)r	   r   r
   ÚindexÚindex_titleÚannotation_offsetZheight_constantr   ÚkwargsÚtable_matrixr%   Útracer(   r)   r   r   r   Úcreate_table   sz    Oÿýÿ
úù	úù
úù
ù	úór4   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )r*   z<
    Refer to TraceFactory.create_table() for docstring
    c                 K   s²   t rpt|t jƒrp|j ¡ }|j ¡ }	|j ¡ }| d|¡ |rp|	 d|¡ tt	|ƒƒD ]}
||
  d|	|
 ¡ qV|| _
|| _|| _|| _|| _tt	|d ƒƒ| _tt	|ƒƒ| _d S )Nr   )ÚpdÚ
isinstanceZ	DataFrameÚcolumnsÚtolistr.   ÚvaluesÚinsertÚranger   r	   r   r
   r0   ÚxÚy)Úselfr	   r   r
   r.   r/   r0   r1   ÚheadersZtable_text_indexÚir   r   r   Ú__init__®   s     



z_Table.__init__c                 C   s°   dgt | jd ƒ }dgt | jd ƒ }dgt | jd ƒ }dgt | jƒ }||d< tdt | jƒdƒD ]}|||< qftdt | jƒdƒD ]}|||< q†| jr¬|D ]}d|d< qž|S )zº
        Create z matrix to make heatmap with striped table coloring

        :rtype (list[list]) table_matrix: z matrix to make heatmap with striped
            table coloring.
        r   r   r   Nr   )r   r	   r;   r.   )r>   ÚheaderZodd_rowZeven_rowr2   r@   Úarrayr   r   r   r+   É   s    


z_Table.get_table_matrixc                 C   sÌ   t | jƒdkr | jt | jƒ }n¨t | jƒdkrœttt | jƒƒƒ}| jd |d< tdt | jƒdƒD ]}| jd ||< q`tdt | jƒdƒD ]}| jd ||< q†n,t | jƒt | jƒkr¸| j}ndgt | jƒ }|S )aP  
        Fill font-color array.

        Table text color can vary by row so this extends a single color or
        creates an array to set a header color and two alternating colors to
        create the striped table pattern.

        :rtype (list[list]) all_font_colors: list of font colors for each row
            in table.
        r   r   r   r   r   )r   r
   r	   Úlistr;   )r>   Úall_font_colorsr@   r   r   r   Úget_table_font_colorÞ   s    z_Table.get_table_font_colorc           
      C   sÌ   t  | ¡}t  | ¡}g }t| jƒD ]¤\}}t|ƒD ]’\}}|dksP| jr`|dk r`dt|ƒ d nt|ƒ}| jr€|dkr€| jd n|| }	| t	j
j|| j| | j | j| ddddt|	d�d	d
�	¡ q2q"|S )zœ
        Generate annotations to fill in table text

        :rtype (list) annotations: list of annotations for each cell of the
            table.
        r   r   z<b>z</b>Úx1Úy1Úleft)ÚcolorF)	Útextr<   r=   ZxrefZyrefÚalignZxanchorZfontZ	showarrow)r*   r+   rF   Ú	enumerater	   r.   Ústrr
   Úappendr   r)   Z
Annotationr<   r0   r=   r-   )
r>   r2   rE   r%   ÚnÚrowÚmÚvalZformat_textZ
font_colorr   r   r   r,   ø   s:    

ÿÿÿýÿ÷ÿz_Table.make_table_annotationsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rA   r+   rF   r,   r   r   r   r   r*   ©   s
   r*   )NNFr   r   r   r   )Ú
__future__r   Zplotlyr   r   Zplotly.graph_objsr   Z
get_moduler5   r   r4   Úobjectr*   r   r   r   r   Ú<module>   s   
       ø
 