Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Show highlights when creating table (#2556)

Kiran-Raj-Dev11da1d1b74c1
diff --git a/manim/mobject/table.py b/manim/mobject/table.py
index 3cddf3b46..40a761777 100644
--- a/manim/mobject/table.py
+++ b/manim/mobject/table.py
@@ -70,8 +70,10 @@ from typing import Callable, Iterable, Sequence
from colour import Color
from .. import config
+from ..animation.animation import Animation
from ..animation.composition import AnimationGroup
-from ..animation.creation import *
+from ..animation.creation import Create, Write
+from ..animation.fading import FadeIn
from ..constants import *
from ..mobject.geometry import Line, Polygon
from ..mobject.numbers import DecimalNumber, Integer
@@ -894,11 +896,11 @@ class Table(VGroup):
def create(
self,
- run_time: float = 1,
lag_ratio: float = 1,
- line_animation: Callable[[VGroup], None] = Create,
- label_animation: Callable[[VGroup], None] = Write,
- element_animation: Callable[[VGroup], None] = Create,
+ line_animation: Callable[[VMobject | VGroup], Animation] = Create,
+ label_animation: Callable[[VMobject | VGroup], Animation] = Write,
+ element_animation: Callable[[VMobject | VGroup], Animation] = Create,
+ entry_animation=FadeIn,
**kwargs,
) -> AnimationGroup:
"""Customized create-type function for tables.
@@ -939,27 +941,31 @@ class Table(VGroup):
self.play(table.create())
self.wait()
"""
- if len(self.get_labels()) > 0:
- animations = [
- line_animation(
- VGroup(self.vertical_lines, self.horizontal_lines),
- run_time=run_time,
- **kwargs,
- ),
- label_animation(self.get_labels(), run_time=run_time, **kwargs),
- element_animation(
- self.elements_without_labels, run_time=run_time, **kwargs
- ),
- ]
- else:
- animations = [
- line_animation(
- VGroup(self.vertical_lines, self.horizontal_lines),
- run_time=run_time,
- **kwargs,
- ),
- element_animation(self.elements, run_time=run_time, **kwargs),
+ animations: Sequence[Animation] = [
+ line_animation(
+ VGroup(self.vertical_lines, self.horizontal_lines),
+ **kwargs,
+ ),
+ element_animation(self.elements_without_labels.set_z_index(2), **kwargs),
+ ]
+
+ if self.get_labels():
+ animations += [
+ label_animation(self.get_labels(), **kwargs),
]
+
+ if self.get_entries():
+ for entry in self.elements_without_labels:
+ try:
+ animations += [
+ entry_animation(
+ entry.background_rectangle,
+ **kwargs,
+ )
+ ]
+ except AttributeError:
+ continue
+
return AnimationGroup(*animations, lag_ratio=lag_ratio)
def scale(self, scale_factor: float, **kwargs):