Pular para conteúdo

animaflow.Timeline

O motor de orquestração temporal de animações, pacotes e streams de partículas.

animaflow.core.timeline.Timeline dataclass

Sequence of animated actions describing the narrative.

Source code in src/animaflow/core/timeline.py
@dataclass
class Timeline:
    """Sequence of animated actions describing the narrative."""

    actions: List[TimelineAction] = field(default_factory=list)

    def reveal_sequence(self, delay_per_item: float = 0.3) -> "Timeline":
        self.actions.append(
            TimelineAction(
                action_type=ActionType.REVEAL_SEQUENCE,
                duration=delay_per_item,
            )
        )
        return self

    def reveal_all(self, duration: float = 0.8) -> "Timeline":
        self.actions.append(
            TimelineAction(
                action_type=ActionType.REVEAL_ALL,
                duration=duration,
            )
        )
        return self

    def send_packet(
        self,
        from_node: Any,
        to_node: Any,
        label: Optional[str] = None,
        duration: float = 1.0,
    ) -> "Timeline":
        src_id = from_node.id if hasattr(from_node, "id") else str(from_node)
        tgt_id = to_node.id if hasattr(to_node, "id") else str(to_node)
        self.actions.append(
            TimelineAction(
                action_type=ActionType.SEND_PACKET,
                target_id=src_id,
                secondary_id=tgt_id,
                payload=label,
                duration=duration,
            )
        )
        return self

    def stream_packets(
        self,
        from_node: Optional[Any] = None,
        to_node: Optional[Any] = None,
        count: int = 5,
        speed: float = 0.65,
        duration: float = 2.5,
        color: Optional[str] = None,
    ) -> "Timeline":
        """Animates a continuous, periodic stream of particle balls flowing across an edge (or all edges)."""
        src_id = (
            (from_node.id if hasattr(from_node, "id") else str(from_node)) if from_node else None
        )
        tgt_id = (to_node.id if hasattr(to_node, "id") else str(to_node)) if to_node else None
        self.actions.append(
            TimelineAction(
                action_type=ActionType.STREAM_PACKETS,
                target_id=src_id,
                secondary_id=tgt_id,
                duration=duration,
                params={
                    "count": count,
                    "speed": speed,
                    "color": color,
                },
            )
        )
        return self

    def highlight_node(
        self,
        node: Any,
        status: str = "active",
        duration: float = 0.8,
    ) -> "Timeline":
        n_id = node.id if hasattr(node, "id") else str(node)
        self.actions.append(
            TimelineAction(
                action_type=ActionType.HIGHLIGHT_NODE,
                target_id=n_id,
                duration=duration,
                params={"status": status},
            )
        )
        return self

    def wait(self, seconds: float = 1.0) -> "Timeline":
        self.actions.append(
            TimelineAction(
                action_type=ActionType.WAIT,
                duration=seconds,
            )
        )
        return self

    def to_dict(self) -> Dict[str, Any]:
        return {
            "actions": [a.to_dict() for a in self.actions],
        }

actions: List[TimelineAction] = field(default_factory=list) class-attribute instance-attribute

__init__(actions: List[TimelineAction] = list()) -> None

reveal_sequence(delay_per_item: float = 0.3) -> Timeline

Source code in src/animaflow/core/timeline.py
def reveal_sequence(self, delay_per_item: float = 0.3) -> "Timeline":
    self.actions.append(
        TimelineAction(
            action_type=ActionType.REVEAL_SEQUENCE,
            duration=delay_per_item,
        )
    )
    return self

reveal_all(duration: float = 0.8) -> Timeline

Source code in src/animaflow/core/timeline.py
def reveal_all(self, duration: float = 0.8) -> "Timeline":
    self.actions.append(
        TimelineAction(
            action_type=ActionType.REVEAL_ALL,
            duration=duration,
        )
    )
    return self

send_packet(from_node: Any, to_node: Any, label: Optional[str] = None, duration: float = 1.0) -> Timeline

Source code in src/animaflow/core/timeline.py
def send_packet(
    self,
    from_node: Any,
    to_node: Any,
    label: Optional[str] = None,
    duration: float = 1.0,
) -> "Timeline":
    src_id = from_node.id if hasattr(from_node, "id") else str(from_node)
    tgt_id = to_node.id if hasattr(to_node, "id") else str(to_node)
    self.actions.append(
        TimelineAction(
            action_type=ActionType.SEND_PACKET,
            target_id=src_id,
            secondary_id=tgt_id,
            payload=label,
            duration=duration,
        )
    )
    return self

stream_packets(from_node: Optional[Any] = None, to_node: Optional[Any] = None, count: int = 5, speed: float = 0.65, duration: float = 2.5, color: Optional[str] = None) -> Timeline

Animates a continuous, periodic stream of particle balls flowing across an edge (or all edges).

Source code in src/animaflow/core/timeline.py
def stream_packets(
    self,
    from_node: Optional[Any] = None,
    to_node: Optional[Any] = None,
    count: int = 5,
    speed: float = 0.65,
    duration: float = 2.5,
    color: Optional[str] = None,
) -> "Timeline":
    """Animates a continuous, periodic stream of particle balls flowing across an edge (or all edges)."""
    src_id = (
        (from_node.id if hasattr(from_node, "id") else str(from_node)) if from_node else None
    )
    tgt_id = (to_node.id if hasattr(to_node, "id") else str(to_node)) if to_node else None
    self.actions.append(
        TimelineAction(
            action_type=ActionType.STREAM_PACKETS,
            target_id=src_id,
            secondary_id=tgt_id,
            duration=duration,
            params={
                "count": count,
                "speed": speed,
                "color": color,
            },
        )
    )
    return self

highlight_node(node: Any, status: str = 'active', duration: float = 0.8) -> Timeline

Source code in src/animaflow/core/timeline.py
def highlight_node(
    self,
    node: Any,
    status: str = "active",
    duration: float = 0.8,
) -> "Timeline":
    n_id = node.id if hasattr(node, "id") else str(node)
    self.actions.append(
        TimelineAction(
            action_type=ActionType.HIGHLIGHT_NODE,
            target_id=n_id,
            duration=duration,
            params={"status": status},
        )
    )
    return self

wait(seconds: float = 1.0) -> Timeline

Source code in src/animaflow/core/timeline.py
def wait(self, seconds: float = 1.0) -> "Timeline":
    self.actions.append(
        TimelineAction(
            action_type=ActionType.WAIT,
            duration=seconds,
        )
    )
    return self

to_dict() -> Dict[str, Any]

Source code in src/animaflow/core/timeline.py
def to_dict(self) -> Dict[str, Any]:
    return {
        "actions": [a.to_dict() for a in self.actions],
    }