
    6Dh$                     x    S SK JrJr  S SKJr  \R
                  " S5      rS r       S	S jr " S S\	5      r
g)
    )
exceptionsoptional_imports)
graph_objspandasc                 j    SS[        U 5      /n[        U5      U;  a  [        R                  " S5      eg)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      N/var/www/html/env/lib/python3.13/site-packages/plotly/figure_factory/_table.pyvalidate_tabler      s>      !!S_5
;66$$O
 	
 7    Nc                    Ub  UO
SS/SS/SS//nUb  UO/ SQn[        X5        [        U UUUUU40 UD6R                  5       n	[        U UUUUU40 UD6R                  5       n
[	        SSU	S	US
US.UD6nU/n[	        U
[        U	5      U-  S-   [	        SSSSS9[	        SS
SSSSS
S9[	        S
SSSSS
S9S9n[        R                  " XS9$ )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()

r   z#00083e      ?z#ededeer   #ffffff)r   #000000r   heatmapg      ?F)typezopacity
colorscale	showscale	hoverinfo2   )tbrlreversed    )	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,   tracer1   r2   s                 r   create_tabler@      sa   ^ ! 	)nsI.I?  #.4U  :+         
 E 7D< ?2R7a1Q'  
  
F, $66r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r4      z4
Refer to TraceFactory.create_table() for docstring
c                 R   [         (       a  [        U[         R                  5      (       a  UR                  R	                  5       nUR
                  R	                  5       n	UR                  R	                  5       nUR                  SU5        U(       aC  U	R                  SU5        [        [        U5      5       H  n
X   R                  SX   5        M     Xl
        X l        X0l        X@l        X`l        [        [        US   5      5      U l        [        [        U5      5      U l        g )Nr   )pd
isinstance	DataFramecolumnstolistr9   valuesinsertranger
   r   r   r   r;   xy)selfr   r   r   r9   r:   r;   r=   headerstable_text_indexis              r   __init___Table.__init__   s     2*Z66 ((//1G)//668#**113Ja) '';7s:/AM((,<,?@ 0$$&
!2s:a=)*s:'r   c                    S/[        U R                  S   5      -  nS/[        U R                  S   5      -  nS/[        U R                  S   5      -  nS/[        U R                  5      -  nXS'   [        S[        U R                  5      S5       H  nX$U'   M	     [        S[        U R                  5      S5       H  nX4U'   M	     U R                  (       a  U H  nSUS'   M
     U$ )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   rK   r9   )rN   headerodd_roweven_rowr>   rQ   arrays          r   r5   _Table.get_table_matrix   s     s4??1-..%#dooa0113T__Q/00vDOO 44 Qq#doo.2A%O 3q#doo.2A&O 3::%a &r   c                    [        U R                  5      S:X  a$  U R                  [        U R                  5      -  nU$ [        U R                  5      S:X  a  [        [	        [        U R                  5      5      5      nU R                  S   US'   [	        S[        U R                  5      S5       H  nU R                  S   X'   M     [	        S[        U R                  5      S5       H  nU R                  S   X'   M     U$ [        U R                  5      [        U R                  5      :X  a  U R                  nU$ S/[        U R                  5      -  nU$ )a  
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   listrK   )rN   all_font_colorsrQ   s      r   get_table_font_color_Table.get_table_font_color   s.    t A%"..T__1EEO  !!"a'"5T__)=#>?O!%!1!1!!4OA1c$//2A6%)%5%5a%8" 71c$//2A6%)%5%5a%8" 7 	 !!"c$//&::"..O   )kC,@@Or   c                 L   [         R                  U 5      n[         R                  U 5      n/ n[        U R                  5       H  u  pE[        U5       H  u  pgUS:X  d  U R
                  (       a  US:  a  S[        U5      -   S-   O
[        U5      nU R
                  (       a  US:X  a  U R                  S   OX$   n	UR                  [        R                  R                  UU R                  U   U R                  -
  U R                  U   SSSS[        U	S9S	S
9	5        M     M     U$ )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)	textrL   rM   xrefyrefalignxanchorfont	showarrow)r4   r5   r]   	enumerater   r9   strr   appendr   r2   
AnnotationrL   r;   rM   r7   )
rN   r>   r\   r,   nrowmvalformat_text
font_colors
             r   r6   _Table.make_table_annotations   s    ..t4 55d;0FA#C. AvA CH$v-S  ,0::!q&D$$Q'oFX  ""%%00(&&)d&<&<<&&)!!$ &!
3"' 1 
 ) 12 r   )r;   r   r   r9   r   rL   rM   N)
__name__
__module____qualname____firstlineno____doc__rR   r5   r]   r6   __static_attributes__r3   r   r   r4   r4      s    (6*4#r   r4   )NNFr$   g?   none)plotlyr   r   plotly.graph_objsr   
get_modulerD   r   r@   objectr4   r3   r   r   <module>r      sL    / (  *
( 
K7\rV rr   