
    -Ph$                     z    d dl mZmZ d dlmZ  ej        d          Zd Z	 	 	 	 	 	 	 ddZ G d de	          Z
dS )    )
exceptionsoptional_imports)
graph_objspandasc                 t    ddt          |           g}t          |          |vrt          j        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   PlotlyError)
table_textfont_colorsfont_colors_len_optionss      \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/figure_factory/_table.pyvalidate_tabler      sK      !!S__5
;666$O
 
 	
 76    NF ?   nonec                    ||n
ddgddgddgg}||ng d}t          | |           t          | |||||fi |                                }	t          | |||||fi |                                }
t	          dd	|	d
|d|d|}|g}t	          |
t          |	          |z  dz   t	          dddd          t	          ddddddd          t	          dddddd                    }t          j        ||          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   #ffffff)r   #000000r   heatmapg      ?F)typezopacity
colorscale	showscale	hoverinfo2   )tbrlreversed   r   )	autorangezeroline	gridwidthticksdticktick0showticklabelsg      )r)   r*   r+   r,   r-   r.   )annotationsheightmarginyaxisxaxis)datalayout )r   _Tableget_table_matrixmake_table_annotationsdictr
   r   Figure)r   r   r   indexindex_titleannotation_offsetheight_constantr    kwargstable_matrixr/   tracer4   r5   s                 r   create_tablerC      s   ^ ! 	
)nsI.I?  #.4U4U4U  :{+++             
   E 7D<  ?2R7a1Q'''  
 
 
  
 
 
  F, $v6666r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )r7   z<
    Refer to TraceFactory.create_table() for docstring
    c                    t           rt          |t           j                  r|j                                        }|j                                        }	|j                                        }|                    d|           |rW|	                    d|           t          t          |                    D ]$}
||
                             d|	|
                    %|| _
        || _        || _        || _        || _        t          t          |d                             | _        t          t          |                    | _        d S )Nr   )pd
isinstance	DataFramecolumnstolistr<   valuesinsertranger
   r   r   r   r>   xy)selfr   r   r   r<   r=   r>   r@   headerstable_text_indexis              r   __init__z_Table.__init__   s.     	A*Z66 	A (//11G)/6688#*1133Ja))) A '';777s:// A AAqM((,<Q,?@@@@$$&
!2s:a=))**s:''r   c                    dgt          | j        d                   z  }dgt          | j        d                   z  }dgt          | j        d                   z  }dgt          | j                  z  }||d<   t          dt          | j                  d          D ]}|||<   t          dt          | j                  d          D ]}|||<   | j        r
|D ]}d|d<   |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   rM   r<   )rP   headerodd_roweven_rowrA   rS   arrays          r   r8   z_Table.get_table_matrix   s     s4?1-...%#doa01113T_Q/000vDO 4 44 Qq#do..22 	& 	&A%LOOq#do..22 	' 	'A&LOO: 	%  ar   c                    t          | j                  dk    r| j        t          | j                  z  }nt          | j                  dk    rt          t	          t          | j                                      }| j        d         |d<   t	          dt          | j                  d          D ]}| j        d         ||<   t	          dt          | j                  d          D ]}| j        d         ||<   nJt          | j                  t          | j                  k    r| j        }ndgt          | j                  z  }|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   listrM   )rP   all_font_colorsrS   s      r   get_table_font_colorz_Table.get_table_font_color   s9    t  A%%".T_1E1EEOO!""a''"5T_)=)=#>#>??O!%!1!!4OA1c$/22A66 9 9%)%5a%8""1c$/22A66 9 9%)%5a%8""9!""c$/&:&:::".OO(kC,@,@@Or   c                 P   t                               |           }t                               |           }g }t          | j                  D ]\  }}t          |          D ]\  }}|dk    s| j        r|dk     rdt          |          z   dz   nt          |          }| j        r|dk    r| j        d         n||         }	|                    t          j
                            || j        |         | j        z
  | j        |         ddddt          |	          d	
	  	                   ƌ|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)	textrN   rO   xrefyrefalignxanchorfont	showarrow)r7   r8   r]   	enumerater   r<   strr   appendr   r5   
AnnotationrN   r>   rO   r:   )
rP   rA   r\   r/   nrowmvalformat_text
font_colors
             r   r9   z_Table.make_table_annotations   sQ    ..t44 55d;;00 	 	FAs#C..  3 AvvvA CHH$v--S  ,0:X!q&&D$Q''oVWFX  ""%00(&)d&<<&)!!$ &!
333"' 1 
 
   0 r   N)__name__
__module____qualname____doc__rT   r8   r]   r9   r6   r   r   r7   r7      sZ         ( ( (6  *  4# # # # #r   r7   )NNFr   r   r   r   )plotlyr   r   plotly.graph_objsr   
get_modulerF   r   rC   objectr7   r6   r   r   <module>r|      s    / / / / / / / / ( ( ( ( ( (  **
 
 
( 
K7 K7 K7 K7\r r r r rV r r r r rr   