1
0

Moved tikz options into the painter class.

This commit is contained in:
Jon Michael Aanes 2015-12-17 18:02:07 +01:00
parent 9688172806
commit 4b65c75e21
2 changed files with 13 additions and 10 deletions

View File

@ -7,14 +7,19 @@ REG_STATUS_TO_COLOR = {
"jump": "orange"
}
DEFAULT_OPTIONS = """register_node/.style={rectangle, draw=black!30,
fill=black!5, very thick, minimum size=0.5,
minimum width=20mm}, text_node/.style={}"""
class TikzPainter:
def __init__ (self, registers=None, max_stack_size=8, stack_draw_mode="up"):
def __init__ (self, registers=None, max_stack_size=8, stack_draw_mode="up", options=None):
self.registers = registers if registers else REGISTERS
self.text = []
self.pos_x = 0
self.max_stack_size = max_stack_size
self.stack_draw_mode = stack_draw_mode
self.options = options if options else DEFAULT_OPTIONS
def addText (self, str, *args):
self.text.append(str.format(*args))
@ -106,4 +111,10 @@ class TikzPainter:
x, pos, index)
def __str__ (self):
return "".join(self.text)
PRE = """ \\documentclass{standalone}
\\usepackage{tikz}
\\begin{document}
\\begin{tikzpicture}["""+self.options+"]"
POST = """\\end{tikzpicture}
\\end{document}"""
return PRE + "".join(self.text) + POST

View File

@ -47,11 +47,6 @@ return: leave # Clean up
ret # return m (rax)
"""
OPTIONS = """register_node/.style={rectangle, draw=black!30,
fill=black!5, very thick, minimum size=0.5,
minimum width=20mm}, text_node/.style={}"""
def printf (str, *args):
print(str.format(*args))
@ -74,7 +69,4 @@ if __name__ == "__main__":
printf("fib({}) = {}", a, emu.registers["%rax"])
with open("tikz.tex","w") as f:
f.write("\\documentclass{standalone}\n\n\usepackage{tikz}\\begin{document}\n")
f.write("\\begin{tikzpicture}["+OPTIONS+"]\n")
f.write(str(painter))
f.write("\\end{tikzpicture}\n\\end{document}")