Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display NFA or DFA as svg File #56

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ More information about the graphviz attributes [here](https://www.graphviz.org/d
# Default styling
automata.view("DFA Visualization")

# You can decide between png and svg file formats
# If you want to add custom styling, you can use the following

automata.view(
file_name="DFA Custom Styling",
file_format="png" or "svg",
node_attr={'fontsize': '20'},
edge_attr={'fontsize': '20pt'}
)
Expand Down Expand Up @@ -200,10 +202,12 @@ not_automata.accept("000001") #True
# Default styling
automata.view("NFA Visualization")

# You can decide between png and svg file formats
# If you want to add custom styling, you can use the following

automata.view(
file_name="NFA Custom Styling",
file_format="png" or "svg",
node_attr={'fontsize': '20'},
edge_attr={'fontsize': '20pt'}
)
Expand Down
6 changes: 5 additions & 1 deletion automathon/finite_automata/dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from typing import (
Callable,
)
from typing import (
Literal
)
import itertools


Expand Down Expand Up @@ -385,12 +388,13 @@ def __define_group_ith_element(
def view(
self,
file_name: str,
file_format: Literal["svg", "png"] = "png",
node_attr: dict[str, str] | None = None,
edge_attr: dict[str, str] | None = None,
) -> None:
dot = Digraph(
name=file_name,
format="png",
format=file_format,
node_attr=node_attr,
edge_attr=edge_attr,
)
Expand Down
7 changes: 6 additions & 1 deletion automathon/finite_automata/nfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
Digraph,
)

from typing import (
Literal
)


@dataclass
class NFA:
Expand Down Expand Up @@ -679,12 +683,13 @@ def product(self, m: "NFA") -> "NFA":
def view(
self,
file_name: str,
file_format: Literal["svg", "png"] = "png",
node_attr: dict[str, str] | None = None,
edge_attr: dict[str, str] | None = None,
) -> None:
dot = Digraph(
name=file_name,
format="png",
format=file_format,
node_attr=node_attr,
edge_attr=edge_attr,
)
Expand Down
3 changes: 2 additions & 1 deletion docs/dfa.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ Example:
```python
automata.view("DFA Visualization")

# Add custom styling
# Add custom styling or change the file format

automata.view(file_name="DFA Custom Styling",
file_format="png" or "svg",
node_attr={'fontsize': '20'},
edge_attr={'fontsize': '20pt'})
```
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ not_automata.accept("000001") #True
# Default styling
automata.view("NFA Visualization")

# You can decide between png and svg file formats
# If you want to add custom styling, you can use the following

automata.view(
file_name="NFA Custom Styling",
file_format="png" or "svg",
node_attr={'fontsize': '20'},
edge_attr={'fontsize': '20pt'}
)
Expand Down
3 changes: 2 additions & 1 deletion docs/nfa.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ automata.
```python
automata.view("NFA Visualization")

# Add custom styling
# Add custom styling or change the file format

automata.view(
file_name="NFA Custom Styling",
file_format="png" or "svg",
node_attr={'fontsize': '20'},
edge_attr={'fontsize': '20pt'}
)
Expand Down
Loading