Skip to content
Snippets Groups Projects
Commit 2078c4ec authored by Hans-Jörg's avatar Hans-Jörg
Browse files

Fix pgf output of visualizer, crate context compat mode

parent 2a424add
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ args_parser.add_argument(
"--pre-schedules",
metavar="FILE",
dest="schedules",
help="The pre-schedulers as files. As many as there are logics given",
help="The pre-schedules as files. As many as there are logics given.",
nargs="*",
default=["schedule.csv"],
type=file_path,
......@@ -78,7 +78,8 @@ if __name__ == "__main__":
dir = args.template.parent
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(dir), autoescape=jinja2.select_autoescape(["html", "xml"])
loader=jinja2.FileSystemLoader(dir),
autoescape=jinja2.select_autoescape(["html", "xml"]),
)
template = env.get_template(args.template.name)
......
......@@ -17,16 +17,6 @@ args_parser.add_argument(
type=float,
help="Total time available to the schedules in seconds.",
)
args_parser.add_argument(
"-s",
"--pre-schedules",
metavar="FILE",
dest="schedules",
help="The pre-schedulers as files. As many as there are logics given",
nargs="*",
default=["schedule.csv"],
type=file_path,
)
args_parser.add_argument(
"-a",
"--shorthands",
......@@ -42,6 +32,19 @@ args_parser.add_argument(
help="Write visualization as a pgf for usage in tex.",
type=new_file_path,
)
args_parser.add_argument(
"-c",
dest="context",
action="store_true",
help="Produce a ConTeX, instead of Latex, compatible PGF file.",
)
args_parser.add_argument(
metavar="PRE-SCHEDULE",
dest="schedules",
help="The pre-schedules as files.",
nargs="*",
type=file_path,
)
# Graphics parameters
......@@ -59,6 +62,8 @@ color_background = "#FFFFFF"
color_highlight_1 = "#D4D1BE"
color_highlight_2 = "#ACBFBA"
font_cmd = "\\tiny\\sf"
def name_strategies(schedule, shorthands, max_id, names):
for (time, s) in schedule:
......@@ -99,7 +104,7 @@ def print_strat_table(
if width < 0.5:
node_str = ""
else:
node_str = f"\\tiny\\sf {id}"
node_str = f"{font_cmd} {id}"
if not highlight:
output_file.write(
f"\\node[orig,minimum width={width}cm] at ({x},{y}) {{{node_str}}};\n"
......@@ -112,6 +117,9 @@ def print_strat_table(
def print_tiks(table_width, total_time, row, output_file):
if total_time < 10:
total_time = total_time * 10
total_time = int(total_time)
delta = table_width / total_time
y = row * 0.5
for i in range(0, total_time + 1):
......@@ -123,9 +131,9 @@ def print_tiks(table_width, total_time, row, output_file):
def print_times(table_width, total_time, row, output_file):
y = row * 0.5 - 0.18
output_file.write(f"\\node at (0,{y}) {{\\tiny\\sf 0}};\n")
output_file.write(f"\\node at ({table_width},{y}) {{\\tiny\\sf {total_time}}};\n")
y = row * 0.5 - 0.23
output_file.write(f"\\node at (0,{y}) {{{font_cmd} 0}};\n")
output_file.write(f"\\node at ({table_width},{y}) {{{font_cmd} {total_time}}};\n")
def render_markings(total_time, canvas):
......@@ -226,8 +234,14 @@ if __name__ == "__main__":
if args.pgf:
message(f"Writing {args.pgf}.", [])
with open(args.pgf, "w") as output_file:
startstr = "begin{tikzpicture}"
stopstr = "end{tikzpicture}"
if args.context:
font_cmd = "\\ss\\tfxx"
startstr = "starttikzpicture"
stopstr = "stoptikzpicture"
output_file.write(
"\\begin{tikzpicture}[x=1cm, y=-1cm, node distance=0 cm,outer sep = 0pt,inner sep=0]\n"
f"\\{startstr}[x=1cm, y=-1cm, node distance=0 cm,outer sep = 0pt,inner sep=0]\n"
)
output_file.write(
"\\tikzstyle{orig}=[draw,rectangle,minimum width=0,minimum height=0.5cm,anchor=north west]\n"
......@@ -236,13 +250,15 @@ if __name__ == "__main__":
"\\tikzstyle{highlight}=[draw,rectangle,fill=black!30,minimum width=0,minimum height=0.5cm,anchor=north west]\n"
)
width = 12
row = 0
for schedule in schedules:
print_strat_table(
schedule, names, shorthands, width, total_time, row, output_file
)
row = row + 1
print_tiks(width, total_time, 0, output_file)
print_times(width, total_time, 0, output_file)
output_file.write("\\end{tikzpicture}\n")
output_file.write(f"\\{stopstr}\n")
exit(0)
top = tkinter.Tk()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment