Skip to content

Commit

Permalink
feat(view): #4 enable graphviz customization
Browse files Browse the repository at this point in the history
  • Loading branch information
rohaquinlop committed Nov 5, 2023
1 parent de25bb3 commit f61221c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 4 additions & 2 deletions automathon/finiteAutomata/dfa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Exceptions module
from __future__ import annotations

from automathon.errors.errors import *
from collections import deque
from graphviz import Digraph
Expand Down Expand Up @@ -218,8 +220,8 @@ def union(self, M: 'DFA') -> 'DFA':

return tmp_nfa.get_dfa()

def view(self, fileName: str):
dot = Digraph(name=fileName, format='png')
def view(self, file_name: str, node_attr: dict[str, str] | None = None, edge_attr: dict[str, str] | None = None):
dot = Digraph(name=file_name, format='png', node_attr=node_attr, edge_attr=edge_attr)

dot.graph_attr['rankdir'] = 'LR'

Expand Down
6 changes: 4 additions & 2 deletions automathon/finiteAutomata/nfa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Exceptions module
from __future__ import annotations

from automathon.errors.errors import *
from collections import deque
from graphviz import Digraph
Expand Down Expand Up @@ -400,8 +402,8 @@ def product(self, M: 'NFA') -> 'NFA':

return nfa

def view(self, file_name: str):
dot = Digraph(name=file_name, format='png')
def view(self, file_name: str, node_attr: dict[str, str] | None = None, edge_attr: dict[str, str] | None = None):
dot = Digraph(name=file_name, format='png', node_attr=node_attr, edge_attr=edge_attr)

dot.graph_attr['rankdir'] = 'LR'

Expand Down
4 changes: 4 additions & 0 deletions tests/test_dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def test_union(self):
self.assertTrue(union_result.accept("00010010"))
self.assertTrue(union_result.accept("0011000"))

def test_view(self):
self.fa.view(file_name="test_dfa_view_attrs", node_attr={'fontsize': '40pt'}, edge_attr={'fontsize': '10pt'})
self.fa.view(file_name="test_dfa_view_no_attrs")


if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions tests/test_nfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,11 @@ def test_renumber(self):
automata_4.renumber()

self.assertTrue(automata_4.is_valid())

def test_view(self):
self.fa.view(file_name="test_nfa_view_attrs", node_attr={'fontsize': '40pt'}, edge_attr={'fontsize': '10pt'})
self.fa.view(file_name="test_nfa_view_no_attrs")


if __name__ == '__main__':
unittest.main()

0 comments on commit f61221c

Please sign in to comment.