Skip to content

Sequence Diagram

code_video.SequenceDiagram

A sequence diagram built using a DSL

add_objects(self, *names)

Add objects to draw interactions between

Parameters:

Name Type Description Default
names str

A list of display names for the actor objects

()
Source code in code_video/sequence.py
def add_objects(self, *names: str) -> List[Actor]:
    """
    Add objects to draw interactions between

    Args:
        names: A list of display names for the actor objects
    """
    for name in names:
        actor = Actor(self, name)
        if not self.actors:
            actor.to_edge(LEFT)
        else:
            actor.next_to(list(self.actors.values())[-1])
        actor.to_edge(UP)
        self.actors[name] = actor
        self.add(actor)

    start_x = list(self.actors.values())[0].get_x(LEFT)
    actor_width = max(max(actor.get_width() + 0.5 for actor in self.actors.values()), 5)
    for idx, actor in enumerate(self.actors.values()):
        left_x = start_x + actor_width * idx
        actor.set_x(left_x + (actor_width - actor.get_width()) / 2, LEFT)

    return self.actors.values()

get_interactions(self)

Gets the pre-programmed interactions for display

Source code in code_video/sequence.py
def get_interactions(self) -> Iterable[Interaction]:
    """
    Gets the pre-programmed interactions for display
    """
    scale = getattr(self, "_overall_scale_factor", 1)
    last: Interaction = None
    for interaction in [item for item in self.interactions]:
        interaction.scale(scale)
        if not last:
            interaction.set_y(list(self.actors.values())[0].block.get_y(DOWN) - MED_SMALL_BUFF, direction=UP)
        else:
            interaction.set_y(last.get_y(DOWN) - MED_LARGE_BUFF * scale, direction=UP)

        yield interaction
        last = interaction

code_video.Actor

A sequence diagram actor that can be interacted with

note(self, message)

Adds a note to the right of the actor

Parameters:

Name Type Description Default
message str

The text of the note

required
Source code in code_video/sequence.py
def note(self, message: str):
    """
    Adds a note to the right of the actor

    Args:
        message: The text of the note
    """
    note_interaction = Note(self, message, RIGHT)
    self.diagram.add_interaction(note_interaction)
    return self

to(self, target, message=None)

Adds an arrow to the next target. If the next target is the same as the source, render a self arrow

Parameters:

Name Type Description Default
target Actor

The target actor

required
message Optional[str]

The arrow text

None
Source code in code_video/sequence.py
def to(self, target: Actor, message: Optional[str] = None):
    """
    Adds an arrow to the next target. If the next target is the same as the source,
    render a self arrow

    Args:
        target: The target actor
        message: The arrow text
    """

    if self == target:
        interaction = SelfArrow(self, message)
    else:
        interaction = ActorArrow(self, target, message if message else "")
    self.diagram.add_interaction(interaction)
    return self

code_video.Interaction