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 if item.target]:
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, value)
Adds a note to the right of the actor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str |
The text of the note |
required |
Source code in code_video/sequence.py
def note(self, value: str):
"""
Adds a note to the right of the actor
Args:
value: The text of the note
"""
note_interaction = Note(self, value, RIGHT)
interaction = self.diagram.interactions[-1]
if not interaction.target:
self.diagram.interactions.insert(-1, note_interaction)
else:
self.diagram.interactions.append(note_interaction)
ret(self, value)
Sets the text on the return interaction
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str |
The label text |
required |
Source code in code_video/sequence.py
def ret(self, value: str):
"""
Sets the text on the return interaction
Args:
value: The label text
"""
interaction = self.diagram.interactions[-1]
if not interaction.target:
interaction = self.diagram.start_interaction(self)
interaction.label = value
return self.cur_interaction
to_self(self, value)
Adds an arrow to itself with a label
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str |
The label text |
required |
Source code in code_video/sequence.py
def to_self(self, value: str):
"""
Adds an arrow to itself with a label
Args:
value: The label text
"""
note_interaction = SelfArrow(self, value)
interaction = self.diagram.interactions[-1]
if not interaction.target:
self.diagram.interactions.insert(-1, note_interaction)
else:
self.diagram.interactions.append(note_interaction)
to_target(self, value, target)
Adds an arrow to the next target
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str |
The arrow text |
required |
target |
Actor |
The target actor |
required |
Source code in code_video/sequence.py
def to_target(self, value: str, target: Actor):
"""
Adds an arrow to the next target
Args:
value: The arrow text
target: The target actor
"""
note_interaction = Interaction(source=self, label=value).finish(target)
interaction = self.diagram.interactions[-1]
if not interaction.target:
self.diagram.interactions.insert(-1, note_interaction)
else:
self.diagram.interactions.append(note_interaction)
code_video.Interaction
An interaction that can be displayed on the screen