
    lj                    z   d Z ddlmZ g dZddlZddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)  G d de!          Z* G d de*          Z+ G d de*          Z, G d de*          Z- G d de*          Z.dS )a  Mobjects representing tables.

Examples
--------

.. manim:: TableExamples
    :save_last_frame:

    class TableExamples(Scene):
        def construct(self):
            t0 = Table(
                [["First", "Second"],
                ["Third","Fourth"]],
                row_labels=[Text("R1"), Text("R2")],
                col_labels=[Text("C1"), Text("C2")],
                top_left_entry=Text("TOP"))
            t0.add_highlighted_cell((2,2), color=GREEN)
            x_vals = np.linspace(-2,2,5)
            y_vals = np.exp(x_vals)
            t1 = DecimalTable(
                [x_vals, y_vals],
                row_labels=[MathTex("x"), MathTex("f(x)")],
                include_outer_lines=True)
            t1.add(t1.get_cell((2,2), color=RED))
            t2 = MathTable(
                [["+", 0, 5, 10],
                [0, 0, 5, 10],
                [2, 2, 7, 12],
                [4, 4, 9, 14]],
                include_outer_lines=True)
            t2.get_horizontal_lines()[:3].set_color(BLUE)
            t2.get_vertical_lines()[:3].set_color(BLUE)
            t2.get_horizontal_lines()[:3].set_z_index(1)
            cross = VGroup(
                Line(UP + LEFT, DOWN + RIGHT),
                Line(UP + RIGHT, DOWN + LEFT))
            a = Circle().set_color(RED).scale(0.5)
            b = cross.set_color(BLUE).scale(0.5)
            t3 = MobjectTable(
                [[a.copy(),b.copy(),a.copy()],
                [b.copy(),a.copy(),a.copy()],
                [a.copy(),b.copy(),b.copy()]])
            t3.add(Line(
                t3.get_corner(DL), t3.get_corner(UR)
            ).set_color(RED))
            vals = np.arange(1,21).reshape(5,4)
            t4 = IntegerTable(
                vals,
                include_outer_lines=True
            )
            g1 = Group(t0, t1).scale(0.5).arrange(buff=1).to_edge(UP, buff=1)
            g2 = Group(t2, t3, t4).scale(0.5).arrange(buff=1).to_edge(DOWN, buff=1)
            self.add(g1, g2)
    )annotations)Table	MathTableMobjectTableIntegerTableDecimalTableN)CallableIterableSequence)Line)Polygon)BackgroundRectangle)DecimalNumberInteger)MathTex)	Paragraph   )	Animation)AnimationGroup)CreateWrite)FadeIn)VGroupVMobject)BLACKPURE_YELLOW
ManimColorParsableManimColor   )get_vectorized_mobject_classc                      e Zd ZdZdddddddedeei i i fdL fdZdMd ZdNd#ZdOd%Z	dPd&Z
dPd'ZdQd(ZdQd)ZdQd*ZdQd+ZdRd.ZdRd/Z	 dSdTd3Z	 dSdTd4ZdQd5ZdQd6ZdQd7ZefdUd9ZdVdWd=Zd:efdXd?Zd:efdYd@ZdAeeeefdZdIZd[ fdKZ  xZ!S )\r   a  A mobject that displays a table on the screen.

    Parameters
    ----------
    table
        A 2D array or list of lists. Content of the table has to be a valid input
        for the callable set in ``element_to_mobject``.
    row_labels
        List of :class:`~.VMobject` representing the labels of each row.
    col_labels
        List of :class:`~.VMobject` representing the labels of each column.
    top_left_entry
        The top-left entry of the table, can only be specified if row and
        column labels are given.
    v_buff
        Vertical buffer passed to :meth:`~.Mobject.arrange_in_grid`, by default 0.8.
    h_buff
        Horizontal buffer passed to :meth:`~.Mobject.arrange_in_grid`, by default 1.3.
    include_outer_lines
        ``True`` if the table should include outer lines, by default False.
    add_background_rectangles_to_entries
        ``True`` if background rectangles should be added to entries, by default ``False``.
    entries_background_color
        Background color of entries if ``add_background_rectangles_to_entries`` is ``True``.
    include_background_rectangle
        ``True`` if the table should have a background rectangle, by default ``False``.
    background_rectangle_color
        Background color of table if ``include_background_rectangle`` is ``True``.
    element_to_mobject
        The :class:`~.Mobject` class applied to the table entries. by default :class:`~.Paragraph`. For common choices, see :mod:`~.text_mobject`/:mod:`~.tex_mobject`.
    element_to_mobject_config
        Custom configuration passed to :attr:`element_to_mobject`, by default {}.
    arrange_in_grid_config
        Dict passed to :meth:`~.Mobject.arrange_in_grid`, customizes the arrangement of the table.
    line_config
        Dict passed to :class:`~.Line`, customizes the lines of the table.
    kwargs
        Additional arguments to be passed to :class:`~.VGroup`.

    Examples
    --------

    .. manim:: TableExamples
        :save_last_frame:

        class TableExamples(Scene):
            def construct(self):
                t0 = Table(
                    [["This", "is a"],
                    ["simple", "Table in \\n Manim."]])
                t1 = Table(
                    [["This", "is a"],
                    ["simple", "Table."]],
                    row_labels=[Text("R1"), Text("R2")],
                    col_labels=[Text("C1"), Text("C2")])
                t1.add_highlighted_cell((2,2), color=YELLOW)
                t2 = Table(
                    [["This", "is a"],
                    ["simple", "Table."]],
                    row_labels=[Text("R1"), Text("R2")],
                    col_labels=[Text("C1"), Text("C2")],
                    top_left_entry=Star().scale(0.3),
                    include_outer_lines=True,
                    arrange_in_grid_config={"cell_alignment": RIGHT})
                t2.add(t2.get_cell((2,2), color=RED))
                t3 = Table(
                    [["This", "is a"],
                    ["simple", "Table."]],
                    row_labels=[Text("R1"), Text("R2")],
                    col_labels=[Text("C1"), Text("C2")],
                    top_left_entry=Star().scale(0.3),
                    include_outer_lines=True,
                    line_config={"stroke_width": 1, "color": YELLOW})
                t3.remove(*t3.get_vertical_lines())
                g = Group(
                    t0,t1,t2,t3
                ).scale(0.7).arrange_in_grid(buff=1)
                self.add(g)

    .. manim:: BackgroundRectanglesExample
        :save_last_frame:

        class BackgroundRectanglesExample(Scene):
            def construct(self):
                background = Rectangle(height=6.5, width=13)
                background.set_fill(opacity=.5)
                background.set_color([TEAL, RED, YELLOW])
                self.add(background)
                t0 = Table(
                    [["This", "is a"],
                    ["simple", "Table."]],
                    add_background_rectangles_to_entries=True)
                t1 = Table(
                    [["This", "is a"],
                    ["simple", "Table."]],
                    include_background_rectangle=True)
                g = Group(t0, t1).scale(0.7).arrange(buff=0.5)
                self.add(g)
    Ng?g?Ftable*Iterable[Iterable[float | str | VMobject]]
row_labelsIterable[VMobject] | None
col_labelstop_left_entryVMobject | Nonev_bufffloath_buffinclude_outer_linesbool$add_background_rectangles_to_entriesentries_background_colorr   include_background_rectanglebackground_rectangle_colorelement_to_mobject,Callable[[float | str | VMobject], VMobject]element_to_mobject_configdictarrange_in_grid_configline_configc                   || _         || _        || _        t          |          | _        t          |d                   | _        || _        || _        || _        || _	        t          |	          | _        |
| _        t          |          | _        || _        || _        || _        || _        |D ]7}t          |          t          |d                   k    r)t%          d           t'                      j        di | |                     |          }t-          t/          j        |  | _        |                     |          }|                     |           t-          t/          j        |  | _        t          | j        d                                                   dk    r%| j                            | j        d                    |                     | j                   |                                   || _!        | "                                 | #                                 | j	        r| $                    | j                   | j        r| %                    | j                   d S d S )Nr   z+Not all rows in table have the same length.color )&r$   r&   r'   lenrow_dimcol_dimr)   r+   r,   r.   r   r/   r0   r1   r2   r4   r6   r7   
ValueErrorsuper__init___table_to_mob_tabler   itchainelements_without_labels_add_labels_organize_mob_tableelementsget_all_pointsremoveaddcenter	mob_table_add_horizontal_lines_add_vertical_linesadd_background_to_entriesadd_background_rectangle)selfr"   r$   r&   r'   r)   r+   r,   r.   r/   r0   r1   r2   r4   r6   r7   kwargsrowrM   	__class__s                      N/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/table.pyrA   zTable.__init__   sJ   , %$,5zz58}}#6 4X1(23K(L(L%,H)*45O*P*P'"4)B&&<#& 	P 	PC3xx3uQx==(( !NOOO""6""",,U33	'-rx/C'D$$$Y//	  +++) 45t}Q..0011Q66M  q!1222"""$$$  """4 	P**1N*OOO, 	Q))0O)PPPPP	Q 	Q    returnlistc                       fd|D             S )a  Initializes the entries of ``table`` as :class:`~.VMobject`.

        Parameters
        ----------
        table
            A 2D array or list of lists. Content of the table has to be a valid input
            for the callable set in ``element_to_mobject``.

        Returns
        --------
        List
            List of :class:`~.VMobject` from the entries of ``table``.
        c                ,    g | ]}fd |D             S )c                6    g | ]} j         |fi j        S r;   r2   r4   ).0itemrR   s     rV   
<listcomp>z8Table._table_to_mob_table.<locals>.<listcomp>.<listcomp>  sA        ('OO0NOO  rW   r;   )r^   rT   rR   s     rV   r`   z-Table._table_to_mob_table.<locals>.<listcomp>  sL     
 
 

 	     
 
 
rW   r;   )rR   r"   s   ` rV   rB   zTable._table_to_mob_table   s0    "
 
 
 

 
 
 
 	
rW   Iterable[Iterable[VMobject]]r   c                <   t                      }t          |          D ];\  }}t          |          D ]&\  }}|                    ||         |                    '< |j        dt	          |          t	          |d                   | j        | j        fd| j         |S )at  Arranges the :class:`~.VMobject` of ``table`` in a grid.

        Parameters
        ----------
        table
            A 2D iterable object with :class:`~.VMobject` entries.

        Returns
        --------
        :class:`~.VGroup`
            The :class:`~.VMobject` of the ``table`` in a :class:`~.VGroup` already
            arranged in a table-like grid.
        r   )rowscolsbuffr;   )r   	enumeraterK   arrange_in_gridr<   r+   r)   r6   )rR   r"   
help_tableirT   j_s          rV   rG   zTable._organize_mob_table  s     XX
&& 	, 	,FAs!# , ,1uQx{++++,"
" 	
UU1X+t{+	
 	
 )		
 	
 	
 rW   rM   c                   | j         >t          t          | j                             D ]}| j         |         g||         z   ||<   | j        | j         f| j        '| j        g| j        z   }|                    d|           nS t                                  }|g| j        z   }|                    d|           n|                    d| j                   |S )a#  Adds labels to an in a grid arranged :class:`~.VGroup`.

        Parameters
        ----------
        mob_table
            An in a grid organized class:`~.VGroup`.

        Returns
        --------
        :class:`~.VGroup`
            Returns the ``mob_table`` with added labels.
        Nr   )r$   ranger<   r&   r'   insertr    )rR   rM   kr&   dummy_mobjects        rV   rF   zTable._add_labels/  s     ?&3t//00 C C $ 23ilB	!?&*&2"&"5!6!HJ$$Q
3333 %C$@$B$B$D$DM"/4?!BJ$$Q
3333  DO444rW   c                   |                                  d         d| j        z  z
  }|                                 d         d| j        z  z   }t                      }| j        r |                                 d                                         d         d| j        z  z   }t          ||dg||dgfi | j	        }|
                    |           | 
                    |           |                                 d                                         d         d| j        z  z
  }t          ||dg||dgfi | j	        }|
                    |           | 
                    |           t          t          | j                  dz
            D ]}|                                 |dz                                            d         d|                                 |                                         d         |                                 |dz                                            d         z
  z  z   }t          ||dg||dgfi | j	        }|
                    |           | 
                    |           || _        | S )z'Adds the horizontal lines to the table.r         ?r   )get_leftr+   	get_rightr   r,   get_rowsget_topr)   r   r7   rK   
get_bottomrm   r<   rM   horizontal_lines)rR   anchor_leftanchor_right
line_groupanchorlinero   s          rV   rN   zTable._add_horizontal_linesN  sd   mmooa(3+<<~~''*S4;->>XX
# 	]]__Q'//11!4sT[7HHFfa(<*C GKGW D NN4   HHTNNN]]__R(3355a83;LLFfa(<*C GKGW D NN4   HHTNNNs4>**Q.// 	 	A]]__QU+3355a83"--//2T]]__QU5K5S5S5U5UVW5XX< F fa(<*C GKGW D NN4   HHTNNNN *rW   c                >   |                                                                  d         d| j        z  z   }|                                                                  d         d| j        z  z
  }t	                      }| j        r |                                 d                                         d         d| j        z  z
  }t          ||dg||dgfi | j
        }|                    |           |                     |           |                                 d                                         d         d| j        z  z   }t          ||dg||dgfi | j
        }|                    |           |                     |           t          t          | j        d                   dz
            D ]}|                                 |dz                                            d         d|                                 |                                         d         |                                 |dz                                            d         z
  z  z   }t          ||dg||dgfi | j
        }|                    |           |                     |           || _        | S )z$Adds the vertical lines to the tabler   rr   r   rs   )rv   rw   r)   rx   r   r,   get_columnsrt   r+   r   r7   rK   ru   rm   r<   rM   vertical_lines)rR   
anchor_topanchor_bottomr|   r}   r~   ro   s          rV   rO   zTable._add_vertical_linesl  s   ]]__,,..q1C$+4EE
2244Q7#:KKXX
# 	%%''*3355a83;LLFQ'&-)C GKGW D NN4   HHTNNN%%''+5577:S4;=NNFQ'&-)C GKGW D NN4   HHTNNNs4>!,--122 		 		A%%''A.7799!<s  ""1%//11!4""$$QU+4466q9:@ F *VZ,C GKGW D NN4   HHTNNNN(rW   c                    | j         S )a  Return the horizontal lines of the table.

        Returns
        --------
        :class:`~.VGroup`
            :class:`~.VGroup` containing all the horizontal lines of the table.

        Examples
        --------

        .. manim:: GetHorizontalLinesExample
            :save_last_frame:

            class GetHorizontalLinesExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    table.get_horizontal_lines().set_color(RED)
                    self.add(table)
        )ry   rR   s    rV   get_horizontal_lineszTable.get_horizontal_lines  s    0 $$rW   c                    | j         S )a  Return the vertical lines of the table.

        Returns
        --------
        :class:`~.VGroup`
            :class:`~.VGroup` containing all the vertical lines of the table.

        Examples
        --------

        .. manim:: GetVerticalLinesExample
            :save_last_frame:

            class GetVerticalLinesExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    table.get_vertical_lines()[0].set_color(RED)
                    self.add(table)
        )r   r   s    rV   get_vertical_lineszTable.get_vertical_lines  s    0 ""rW   c           	     x     t           fdt          t           j        d                             D              S )a  Return columns of the table as a :class:`~.VGroup` of :class:`~.VGroup`.

        Returns
        --------
        :class:`~.VGroup`
            :class:`~.VGroup` containing each column in a :class:`~.VGroup`.

        Examples
        --------

        .. manim:: GetColumnsExample
            :save_last_frame:

            class GetColumnsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    table.add(SurroundingRectangle(table.get_columns()[1]))
                    self.add(table)
        c              3  N   K   | ]t          fd j        D              V  dS )c              3  (   K   | ]}|         V  d S Nr;   )r^   rT   ri   s     rV   	<genexpr>z.Table.get_columns.<locals>.<genexpr>.<genexpr>  s'      ::CQ::::::rW   Nr   rM   )r^   ri   rR   s    @rV   r   z$Table.get_columns.<locals>.<genexpr>  sT         ::::4>:::;     rW   r   )r   rm   r<   rM   r   s   `rV   r   zTable.get_columns  sO    0    s4>!#45566  
 	
rW   c                2    t          d | j        D              S )a  Return the rows of the table as a :class:`~.VGroup` of :class:`~.VGroup`.

        Returns
        --------
        :class:`~.VGroup`
            :class:`~.VGroup` containing each row in a :class:`~.VGroup`.

        Examples
        --------

        .. manim:: GetRowsExample
            :save_last_frame:

            class GetRowsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    table.add(SurroundingRectangle(table.get_rows()[1]))
                    self.add(table)
        c              3  (   K   | ]}t          | V  d S r   )r   )r^   rT   s     rV   r   z!Table.get_rows.<locals>.<genexpr>  s&      ????????rW   r   r   s    rV   rv   zTable.get_rows  s     0 ?????@@rW   colorsIterable[ParsableManimColor]c                    |                                  }t          ||d          D ]\  }}|                    |           | S )a  Set individual colors for each column of the table.

        Parameters
        ----------
        colors
            An iterable of colors; each color corresponds to a column.

        Examples
        --------

        .. manim:: SetColumnColorsExample
            :save_last_frame:

            class SetColumnColorsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")]
                    ).set_column_colors([RED,BLUE], GREEN)
                    self.add(table)
        Fstrict)r   zip	set_color)rR   r   columnsr:   columns        rV   set_column_colorszTable.set_column_colors  sS    0 ""$$ ??? 	$ 	$ME6U####rW   c                    |                                  }t          ||d          D ]\  }}|                    |           | S )a  Set individual colors for each row of the table.

        Parameters
        ----------
        colors
            An iterable of colors; each color corresponds to a row.

        Examples
        --------

        .. manim:: SetRowColorsExample
            :save_last_frame:

            class SetRowColorsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")]
                    ).set_row_colors([RED,BLUE], GREEN)
                    self.add(table)
        Fr   )rv   r   r   )rR   r   rc   r:   rT   s        rV   set_row_colorszTable.set_row_colors  sM    0 }}fd5999 	! 	!JE3MM%    rW   posSequence[int] | NoneVMobject | VGroupc                :   || j         M| j        F| j        ?t          | j        d                   |d         dz
  z  |d         z   dz
  }| j        |         S t          | j        d                   |d         dz
  z  |d         z   dz
  }| j        |         S | j        S )a  Return the individual entries of the table (including labels) or one specific entry
        if the parameter, ``pos``,  is set.

        Parameters
        ----------
        pos
            The position of a specific entry on the table. ``(1,1)`` being the top left entry
            of the table.

        Returns
        -------
        Union[:class:`~.VMobject`, :class:`~.VGroup`]
            :class:`~.VGroup` containing all entries of the table (including labels)
            or the :class:`~.VMobject` at the given position if ``pos`` is set.

        Examples
        --------

        .. manim:: GetEntriesExample
            :save_last_frame:

            class GetEntriesExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    ent = table.get_entries()
                    for item in ent:
                        item.set_color(random_bright_color())
                    table.get_entries((2,2)).rotate(PI)
                    self.add(table)
        Nr   r   r   )r$   r&   r'   r<   rM   rH   rR   r   indexs      rV   get_entrieszTable.get_entries2  s    L ?+O/'/DN1-..#a&1*=AFJ}U++DN1-..#a&1*=AFJ}U++= rW   c                l    |,| j         |d         dz
  z  |d         z   dz
  }| j        |         S | j        S )aK  Return the individual entries of the table (without labels) or one specific entry
        if the parameter, ``pos``, is set.

        Parameters
        ----------
        pos
            The position of a specific entry on the table. ``(1,1)`` being the top left entry
            of the table (without labels).

        Returns
        -------
        Union[:class:`~.VMobject`, :class:`~.VGroup`]
            :class:`~.VGroup` containing all entries of the table (without labels)
            or the :class:`~.VMobject` at the given position if ``pos`` is set.

        Examples
        --------

        .. manim:: GetEntriesWithoutLabelsExample
            :save_last_frame:

            class GetEntriesWithoutLabelsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    ent = table.get_entries_without_labels()
                    colors = [BLUE, GREEN, YELLOW, RED]
                    for k in range(len(colors)):
                        ent[k].set_color(colors[k])
                    table.get_entries_without_labels((2,2)).rotate(PI)
                    self.add(table)
        Nr   r   )r>   rE   r   s      rV   get_entries_without_labelsz Table.get_entries_without_labelsf  sC    N ?LCFQJ/#a&81<E/66//rW   c                    t          | j         S )a  Return the row labels of the table.

        Returns
        -------
        :class:`~.VGroup`
            :class:`~.VGroup` containing the row labels of the table.

        Examples
        --------

        .. manim:: GetRowLabelsExample
            :save_last_frame:

            class GetRowLabelsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    lab = table.get_row_labels()
                    for item in lab:
                        item.set_color(random_bright_color())
                    self.add(table)
        )r   r$   r   s    rV   get_row_labelszTable.get_row_labels      4 t''rW   c                    t          | j         S )a  Return the column labels of the table.

        Returns
        --------
        :class:`~.VGroup`
            VGroup containing the column labels of the table.

        Examples
        --------

        .. manim:: GetColLabelsExample
            :save_last_frame:

            class GetColLabelsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    lab = table.get_col_labels()
                    for item in lab:
                        item.set_color(random_bright_color())
                    self.add(table)
        )r   r&   r   s    rV   get_col_labelszTable.get_col_labels  r   rW   c                    t                      }| j        |                    | j                   | j        | j        fD ]}|
 |j        |  |S )aH  Returns the labels of the table.

        Returns
        --------
        :class:`~.VGroup`
            :class:`~.VGroup` containing all the labels of the table.

        Examples
        --------

        .. manim:: GetLabelsExample
            :save_last_frame:

            class GetLabelsExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    lab = table.get_labels()
                    colors = [BLUE, GREEN, YELLOW, RED]
                    for k in range(len(colors)):
                        lab[k].set_color(colors[k])
                    self.add(table)
        )r   r'   rK   r&   r$   )rR   label_grouplabels      rV   
get_labelszTable.get_labels  s_    6 hh*OOD/000ot7 	( 	(E ''rW   r:   c                z    |                                  D ]%}|                    t          |                     &| S )zGAdds a black :class:`~.BackgroundRectangle` to each entry of the table.r9   )r   rQ   r   )rR   r:   mobs      rV   rP   zTable.add_background_to_entries  sF    ##%% 	B 	BC((z%/@/@(AAAArW   r   r   Sequence[int]r   c                
   |                                  |d         dz
           }|                                 |d         dz
           }|                                d         | j        dz  z
  |                                d         | j        dz  z   dg}|                                d         | j        dz  z   |                                d         | j        dz  z   dg}|                                d         | j        dz  z
  |                                d         | j        dz  z
  dg}|                                d         | j        dz  z   |                                d         | j        dz  z
  dg}t          ||||fi |}	|	S )a  Returns one specific cell as a rectangular :class:`~.Polygon` without the entry.

        Parameters
        ----------
        pos
            The position of a specific entry on the table. ``(1,1)`` being the top left entry
            of the table.
        kwargs
            Additional arguments to be passed to :class:`~.Polygon`.

        Returns
        -------
        :class:`~.Polygon`
            Polygon mimicking one specific cell of the Table.

        Examples
        --------

        .. manim:: GetCellExample
            :save_last_frame:

            class GetCellExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    cell = table.get_cell((2,2), color=RED)
                    self.add(table, cell)
        r   r   r   )	rv   r   rt   r+   rw   r)   ru   rx   r   )
rR   r   rS   rT   coledge_ULedge_URedge_DLedge_DRrecs
             rV   get_cellzTable.get_cell  si   @ mmooc!fqj)  Q!,LLNN1a/KKMM!t{Q.
 MMOOAq0KKMM!t{Q.
 LLNN1a/NNQ$+/1
 MMOOAq0NNQ$+/1

 gwCCFCC
rW   r   c                h    |                      |          }t          |fdt          |          i|}|S )a  Returns a :class:`~.BackgroundRectangle` of the cell at the given position.

        Parameters
        ----------
        pos
            The position of a specific entry on the table. ``(1,1)`` being the top left entry
            of the table.
        color
            The color used to highlight the cell.
        kwargs
            Additional arguments to be passed to :class:`~.BackgroundRectangle`.

        Examples
        --------

        .. manim:: GetHighlightedCellExample
            :save_last_frame:

            class GetHighlightedCellExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    highlight = table.get_highlighted_cell((2,2), color=GREEN)
                    table.add_to_back(highlight)
                    self.add(table)
        r:   )r   r   r   )rR   r   r:   rS   cellbg_cells         rV   get_highlighted_cellzTable.get_highlighted_cell-  s=    F }}S!!%dNN*U2C2CNvNNrW   c                     | j         |fdt          |          i|}|                     |           |                     |          }||_        | S )a  Highlights one cell at a specific position on the table by adding a :class:`~.BackgroundRectangle`.

        Parameters
        ----------
        pos
            The position of a specific entry on the table. ``(1,1)`` being the top left entry
            of the table.
        color
            The color used to highlight the cell.
        kwargs
            Additional arguments to be passed to :class:`~.BackgroundRectangle`.

        Examples
        --------

        .. manim:: AddHighlightedCellExample
            :save_last_frame:

            class AddHighlightedCellExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")])
                    table.add_highlighted_cell((2,2), color=GREEN)
                    self.add(table)
        r:   )r   r   add_to_backr   background_rectangle)rR   r   r:   rS   r   entrys         rV   add_highlighted_cellzTable.add_highlighted_cellT  s`    D ,$+CSSz%7H7HSFSS!!!  %%%,"rW   r   	lag_ratioline_animation(Callable[[VMobject | VGroup], Animation]label_animationelement_animationentry_animationr   c                    |t          | j        | j                  fi | || j                            d          fi |g}|                                 r| ||                                 fi |gz  }|                                 r-| j        D ]%}	 | ||j        fi |gz  }# t          $ r Y "w xY wt          |d|iS )a\  Customized create-type function for tables.

        Parameters
        ----------
        lag_ratio
            The lag ratio of the animation.
        line_animation
            The animation style of the table lines, see :mod:`~.creation` for examples.
        label_animation
            The animation style of the table labels, see :mod:`~.creation` for examples.
        element_animation
            The animation style of the table elements, see :mod:`~.creation` for examples.
        entry_animation
            The entry animation of the table background, see :mod:`~.creation` for examples.
        kwargs
            Further arguments passed to the creation animations.

        Returns
        -------
        :class:`~.AnimationGroup`
            AnimationGroup containing creation of the lines and of the elements.

        Examples
        --------

        .. manim:: CreateTableExample

            class CreateTableExample(Scene):
                def construct(self):
                    table = Table(
                        [["First", "Second"],
                        ["Third","Fourth"]],
                        row_labels=[Text("R1"), Text("R2")],
                        col_labels=[Text("C1"), Text("C2")],
                        include_outer_lines=True)
                    self.play(table.create())
                    self.wait()
        r   r   )
r   r   ry   rE   set_z_indexr   r   r   AttributeErrorr   )	rR   r   r   r   r   r   rS   
animationsr   s	            rV   createzTable.create|  s=   ` Nt*D,ABB   d:FFqIITTVTT+

 ?? 	 1 1<<V<< J  
	5 	 	'!6 $ # JJ &   H z?Y???s   B''
B43B4scale_factorc                |    | xj         |z  c_         | xj        |z  c_         t                      j        |fi | | S r   )r+   r)   r@   scale)rR   r   rS   rU   s      rV   r   zTable.scale  sH     	|#|#l--f---rW   )r"   r#   r$   r%   r&   r%   r'   r(   r)   r*   r+   r*   r,   r-   r.   r-   r/   r   r0   r-   r1   r   r2   r3   r4   r5   r6   r5   r7   r5   )r"   r#   rX   rY   )r"   ra   rX   r   )rM   r   rX   r   )rX   r   )rX   r   )r   r   rX   r   r   )r   r   rX   r   )r:   r   rX   r   )r   )r   r   rX   r   )r   r   r:   r   rX   r   )r   r   r:   r   rX   r   )r   r*   r   r   r   r   r   r   r   r   rX   r   )r   r*   )"__name__
__module____qualname____doc__r   r   rA   rB   rG   rF   rN   rO   r   r   r   rv   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   r   __classcell__rU   s   @rV   r   r   V   s       b bN 1504*.$)5:7<-29> *,')'?Q ?Q ?Q ?Q ?Q ?Q ?QB
 
 
 
2   4   >   <   >% % % %4# # # #4
 
 
 
>A A A A4   :   > %)2! 2! 2! 2! 2!l %)+0 +0 +0 +0 +0Z( ( ( (8( ( ( (8! ! ! !F EJ     7 7 7 7 7v $$/% % % % %R $$/& & & & &T CIDIFLDJH@ H@ H@ H@ H@T         rW   r   c                  (     e Zd ZdZefd fdZ xZS )r   a  A specialized :class:`~.Table` mobject for use with LaTeX.

    Examples
    --------

    .. manim:: MathTableExample
        :save_last_frame:

        class MathTableExample(Scene):
            def construct(self):
                t0 = MathTable(
                    [["+", 0, 5, 10],
                    [0, 0, 5, 10],
                    [2, 2, 7, 12],
                    [4, 4, 9, 14]],
                    include_outer_lines=True)
                self.add(t0)
    r"   Iterable[Iterable[float | str]]r2   !Callable[[float | str], VMobject]c                @     t                      j        |fd|i| dS )a*  
        Special case of :class:`~.Table` with `element_to_mobject` set to :class:`~.MathTex`.
        Every entry in `table` is set in a Latex `align` environment.

        Parameters
        ----------
        table
            A 2d array or list of lists. Content of the table have to be valid input
            for :class:`~.MathTex`.
        element_to_mobject
            The :class:`~.Mobject` class applied to the table entries. Set as :class:`~.MathTex`.
        kwargs
            Additional arguments to be passed to :class:`~.Table`.
        r2   Nr@   rA   rR   r"   r2   rS   rU   s       rV   rA   zMathTable.__init__  sD    ( 		
 	
1	
 	
 	
 	
 	
 	
rW   r"   r   r2   r   )r   r   r   r   r   rA   r   r   s   @rV   r   r     sS         , AH
 
 
 
 
 
 
 
 
 
 
rW   r   c                  *     e Zd ZdZd fd fdZ xZS )	r   a[  A specialized :class:`~.Table` mobject for use with :class:`~.Mobject`.

    Examples
    --------

    .. manim:: MobjectTableExample
        :save_last_frame:

        class MobjectTableExample(Scene):
            def construct(self):
                cross = VGroup(
                    Line(UP + LEFT, DOWN + RIGHT),
                    Line(UP + RIGHT, DOWN + LEFT),
                )
                a = Circle().set_color(RED).scale(0.5)
                b = cross.set_color(BLUE).scale(0.5)
                t0 = MobjectTable(
                    [[a.copy(),b.copy(),a.copy()],
                    [b.copy(),a.copy(),a.copy()],
                    [a.copy(),b.copy(),b.copy()]]
                )
                line = Line(
                    t0.get_corner(DL), t0.get_corner(UR)
                ).set_color(RED)
                self.add(t0, line)
    c                    | S r   r;   )ms    rV   <lambda>zMobjectTable.<lambda>  s    q rW   r"   ra   r2   Callable[[VMobject], VMobject]c                @     t                      j        |fd|i| dS )a2  
        Special case of :class:`~.Table` with ``element_to_mobject`` set to an identity function.
        Here, every item in ``table`` must already be of type :class:`~.Mobject`.

        Parameters
        ----------
        table
            A 2D array or list of lists. Content of the table must be of type :class:`~.Mobject`.
        element_to_mobject
            The :class:`~.Mobject` class applied to the table entries. Set as ``lambda m : m`` to return itself.
        kwargs
            Additional arguments to be passed to :class:`~.Table`.
        r2   Nr   r   s       rV   rA   zMobjectTable.__init__  s0    & 	PP3EPPPPPPrW   )r"   ra   r2   r   )r   r   r   r   rA   r   r   s   @rV   r   r     s_         < >I[Q Q Q Q Q Q Q Q Q Q QrW   r   c                  (     e Zd ZdZefd fdZ xZS )r   ai  A specialized :class:`~.Table` mobject for use with :class:`~.Integer`.

    Examples
    --------

    .. manim:: IntegerTableExample
        :save_last_frame:

        class IntegerTableExample(Scene):
            def construct(self):
                t0 = IntegerTable(
                    [[0,30,45,60,90],
                    [90,60,45,30,0]],
                    col_labels=[
                        MathTex(r"\frac{ \sqrt{0} }{2}"),
                        MathTex(r"\frac{ \sqrt{1} }{2}"),
                        MathTex(r"\frac{ \sqrt{2} }{2}"),
                        MathTex(r"\frac{ \sqrt{3} }{2}"),
                        MathTex(r"\frac{ \sqrt{4} }{2}")],
                    row_labels=[MathTex(r"\sin"), MathTex(r"\cos")],
                    h_buff=1,
                    element_to_mobject_config={"unit": r"^{\circ}"})
                self.add(t0)
    r"   r   r2   r   c                @     t                      j        |fd|i| dS )a!  
        Special case of :class:`~.Table` with `element_to_mobject` set to :class:`~.Integer`.
        Will round if there are decimal entries in the table.

        Parameters
        ----------
        table
            A 2d array or list of lists. Content of the table has to be valid input
            for :class:`~.Integer`.
        element_to_mobject
            The :class:`~.Mobject` class applied to the table entries. Set as :class:`~.Integer`.
        kwargs
            Additional arguments to be passed to :class:`~.Table`.
        r2   Nr   r   s       rV   rA   zIntegerTable.__init__J  s0    ( 	PP3EPPPPPPrW   r   )r   r   r   r   r   rA   r   r   s   @rV   r   r   0  s^         8 AHQ Q Q Q Q Q Q Q Q Q QrW   r   c                  .     e Zd ZdZeddifd fd
Z xZS )r   at  A specialized :class:`~.Table` mobject for use with :class:`~.DecimalNumber` to display decimal entries.

    Examples
    --------

    .. manim:: DecimalTableExample
        :save_last_frame:

        class DecimalTableExample(Scene):
            def construct(self):
                x_vals = [-2,-1,0,1,2]
                y_vals = np.exp(x_vals)
                t0 = DecimalTable(
                    [x_vals, y_vals],
                    row_labels=[MathTex("x"), MathTex("f(x)=e^{x}")],
                    h_buff=1,
                    element_to_mobject_config={"num_decimal_places": 2})
                self.add(t0)
    num_decimal_placesr   r"   r   r2   r   r4   r5   c                B     t                      j        |f||d| dS )a  
        Special case of :class:`~.Table` with ``element_to_mobject`` set to :class:`~.DecimalNumber`.
        By default, ``num_decimal_places`` is set to 1.
        Will round/truncate the decimal places based on the provided ``element_to_mobject_config``.

        Parameters
        ----------
        table
            A 2D array, or a list of lists. Content of the table must be valid input
            for :class:`~.DecimalNumber`.
        element_to_mobject
            The :class:`~.Mobject` class applied to the table entries. Set as :class:`~.DecimalNumber`.
        element_to_mobject_config
            Element to mobject config, here set as {"num_decimal_places": 1}.
        kwargs
            Additional arguments to be passed to :class:`~.Table`.
        r]   Nr   )rR   r"   r2   r4   rS   rU   s        rV   rA   zDecimalTable.__init__v  sG    0 		
1&?	
 	
 		
 	
 	
 	
 	
rW   )r"   r   r2   r   r4   r5   )r   r   r   r   r   rA   r   r   s   @rV   r   r   a  s[         . AN+?*C	
 
 
 
 
 
 
 
 
 
 
rW   r   )/r   
__future__r   __all__	itertoolsrC   collections.abcr	   r
   r   manim.mobject.geometry.liner   manim.mobject.geometry.polygramr   %manim.mobject.geometry.shape_matchersr   manim.mobject.text.numbersr   r   manim.mobject.text.tex_mobjectr   manim.mobject.text.text_mobjectr   animation.animationr   animation.compositionr   animation.creationr   r   animation.fadingr    mobject.types.vectorized_mobjectr   r   utils.colorr   r   r   r   utilsr    r   r   r   r   r   r;   rW   rV   <module>r      sg  5 5n # " " " " "       8 8 8 8 8 8 8 8 8 8 , , , , , , 3 3 3 3 3 3 E E E E E E = = = = = = = = 2 2 2 2 2 2 5 5 5 5 5 5 + + + + + + 2 2 2 2 2 2 . . . . . . . . % % % % % % ? ? ? ? ? ? ? ? L L L L L L L L L L L L / / / / / /v v v v vF v v vr,
 ,
 ,
 ,
 ,
 ,
 ,
 ,
^/Q /Q /Q /Q /Q5 /Q /Q /Qd.Q .Q .Q .Q .Q5 .Q .Q .Qb2
 2
 2
 2
 2
5 2
 2
 2
 2
 2
rW   