-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bf83e7
commit 346b16b
Showing
4 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from mermaid.sequence.element import Actor, Box, Participant | ||
from mermaid.sequence.link import ArrowTypes, Link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from mermaid.sequence.element import Actor, Participant | ||
from typing import Union | ||
|
||
from enum import Enum | ||
|
||
|
||
ARROW_TYPES: dict[str,str] = { | ||
'Solid-line':'->', | ||
'Dotted-line':'-->', | ||
'Solid-arrow':'->>', | ||
'Dotted-arrow':'-->>', | ||
'Solid-cross':'-x', | ||
'Dotted-cross':'--x', | ||
'Solid-async':'-)', | ||
'Dotted-async':'--)' | ||
} | ||
|
||
|
||
|
||
class ArrowTypes(Enum): | ||
SOLID_LINE = '->' | ||
DOTTED_LINE = '-->' | ||
SOLID_ARROW = '->>' | ||
DOTTED_ARROW = '-->>' | ||
SOLID_CROSS = '-x' | ||
DOTTED_CROSS = '--x' | ||
SOLID_ASYNC = '-)' | ||
DOTTED_ASYNC = '--)' | ||
|
||
class Link: | ||
"""Link class for mermaid sequence diagram. | ||
Args: | ||
source (ActorParticipant): Source of the link. | ||
target (ActorParticipant): Target of the link. | ||
type_ (Union[str,ArrowTypes]): Type of the link. | ||
activate_target (bool, optional): Activate the target. Defaults to False. | ||
deactivate_target (bool, optional): Deactivate the target. Defaults to False. | ||
""" | ||
def __init__(self, | ||
source: Union[Actor, Participant], | ||
target: Union[Actor, Participant], | ||
type_: Union[str,ArrowTypes], | ||
activate_target: bool = False, | ||
deactivate_target: bool = False)-> None: | ||
self.source:Union[Actor, Participant] = source | ||
self.target:Union[Actor, Participant] = target | ||
self.type_:Union[str,ArrowTypes] = ARROW_TYPES[type_] if isinstance(type_,str) else type_.value | ||
self.activate_target: bool = activate_target | ||
self.deactivate_target: bool = deactivate_target | ||
|
||
def __str__(self)-> str: | ||
string:str = f'\t{self.source.id_}{self.type_}{self.target.id_}\n' | ||
if self.activate_target: | ||
string += f'activate {self.target.id_}\n' | ||
if self.deactivate_target: | ||
string += f'deactivate {self.target.id_}\n' | ||
|
||
return string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters