Skip to content

Commit bc7a291

Browse files
committed
style(plot): indent properly op-node template
1 parent ea91c44 commit bc7a291

File tree

2 files changed

+91
-71
lines changed

2 files changed

+91
-71
lines changed

graphtik/plot.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -407,46 +407,46 @@ class Style:
407407
textwrap.dedent(
408408
"""\
409409
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
410-
{{- {
411-
'BORDER': penwidth | ee,
412-
'COLOR': color | ee,
413-
'BGCOLOR': fillcolor | ee
414-
} | xmlattr }}
415-
><TR><TD BORDER="1" SIDES="b" ALIGN="left"
416-
{{- {
417-
'TOOLTIP': op_tooltip | truncate | eee,
418-
'HREF': op_url | hrefer | ee,
419-
'TARGET': op_link_target | e
420-
} | xmlattr }}
410+
{{- {
411+
'BORDER': penwidth | ee,
412+
'COLOR': color | ee,
413+
'BGCOLOR': fillcolor | ee
414+
} | xmlattr -}}>
415+
<TR>
416+
<TD BORDER="1" SIDES="b" ALIGN="left"
417+
{{- {
418+
'TOOLTIP': op_tooltip | truncate | eee,
419+
'HREF': op_url | hrefer | ee,
420+
'TARGET': op_link_target | e
421+
} | xmlattr }}
421422
>
422-
{%- if fontcolor -%}
423-
<FONT COLOR="{{ fontcolor }}">
424-
{%- endif -%}
425-
{{ '<B>OP:</B> <I>%s</I>' % op_name |ee if op_name }}
426-
{%- if fontcolor -%}
427-
</FONT>
428-
{%- endif -%}
429-
</TD></TR
430-
>
423+
{%- if fontcolor -%}<FONT COLOR="{{ fontcolor }}">{%- endif -%}
424+
{{- '<B>OP:</B> <I>%s</I>' % op_name |ee if op_name -}}
425+
{%- if fontcolor -%}</FONT>{%- endif -%}
426+
</TD>
427+
</TR>
431428
{%- if fn_name -%}
432-
<TR><TD ALIGN="left" {{- {
433-
'TOOLTIP': fn_tooltip | truncate | eee,
434-
'HREF': fn_url | hrefer | ee,
435-
'TARGET': fn_link_target | e
436-
} | xmlattr }}
437-
>
438-
{%- if fontcolor -%}
429+
<TR>
430+
<TD ALIGN="left"
431+
{{- {
432+
'TOOLTIP': fn_tooltip | truncate | eee,
433+
'HREF': fn_url | hrefer | ee,
434+
'TARGET': fn_link_target | e
435+
} | xmlattr }}
436+
>
437+
{%- if fontcolor -%}
439438
<FONT COLOR="{{ fontcolor }}">
440-
{%- endif -%}
441-
<B>FN:</B> {{ fn_name | eee }}
442-
{%- if fontcolor -%}
439+
{%- endif -%}
440+
<B>FN:</B> {{ fn_name | eee }}
441+
{%- if fontcolor -%}
443442
</FONT>
444-
{%- endif -%}
445-
</TD></TR>
443+
{%- endif -%}
444+
</TD>
445+
</TR>
446446
{%- endif %}
447447
</TABLE>>
448448
"""
449-
).strip(),
449+
).strip()
450450
)
451451

452452
##########

test/test_plot.py

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ def test_op_label_template_full():
8383
got = plot._render_template(plot.Style.op_template, **kw)
8484
print(got)
8585
exp = """
86-
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded" BORDER="44" COLOR="red" BGCOLOR="wheat"
87-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="&lt;op &quot; &#9; tooltip&gt;" HREF="http://op_url.com_label_" TARGET="_self"
88-
><FONT COLOR="blue"><B>OP:</B> <I>the op</I></FONT></TD></TR
89-
><TR><TD ALIGN="left" TOOLTIP="&lt;fn&#10;tooltip&gt;" HREF="http://fn_url.com/quoto_and" TARGET="_top"
90-
><FONT COLOR="blue"><B>FN:</B> the fn</FONT></TD></TR>
86+
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded" BORDER="44" COLOR="red" BGCOLOR="wheat">
87+
<TR>
88+
<TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="&lt;op &quot; &#9; tooltip&gt;" HREF="http://op_url.com_label_" TARGET="_self"
89+
><FONT COLOR="blue"><B>OP:</B> <I>the op</I></FONT></TD>
90+
</TR><TR>
91+
<TD ALIGN="left" TOOLTIP="&lt;fn&#10;tooltip&gt;" HREF="http://fn_url.com/quoto_and" TARGET="_top"
92+
><FONT COLOR="blue"><B>FN:</B> the fn</FONT></TD>
93+
</TR>
9194
</TABLE>>
9295
"""
9396

@@ -102,10 +105,11 @@ def test_op_label_template_empty():
102105
got = plot._render_template(plot.Style.op_template)
103106
print(got)
104107
exp = """
105-
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
106-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
107-
></TD></TR
108-
>
108+
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
109+
<TR>
110+
<TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
111+
></TD>
112+
</TR>
109113
</TABLE>>
110114
"""
111115
assert _striplines(got) == _striplines(exp)
@@ -115,11 +119,14 @@ def test_op_label_template_fn_empty():
115119
got = plot._render_template(plot.Style.op_template, op_name="op", fn_name="fn")
116120
print(got)
117121
exp = """
118-
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
119-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
120-
><B>OP:</B> <I>op</I></TD></TR
121-
><TR><TD ALIGN="left" TARGET=""
122-
><B>FN:</B> fn</TD></TR>
122+
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
123+
<TR>
124+
<TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
125+
><B>OP:</B> <I>op</I></TD>
126+
</TR><TR>
127+
<TD ALIGN="left" TARGET=""
128+
><B>FN:</B> fn</TD>
129+
</TR>
123130
</TABLE>>
124131
"""
125132
assert _striplines(got) == _striplines(exp)
@@ -142,10 +149,11 @@ def test_op_label_template_nones():
142149
got = plot._render_template(plot.Style.op_template, **kw)
143150
print(got)
144151
exp = """
145-
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
146-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
147-
></TD></TR
148-
>
152+
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
153+
<TR>
154+
<TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
155+
></TD>
156+
</TR>
149157
</TABLE>>
150158
"""
151159

@@ -419,18 +427,24 @@ def test_node_dot_str0(dot_str_pipeline):
419427
splines=ortho;
420428
<edge> [shape=rect];
421429
<digraph&#58; strict> [shape=rect];
422-
<node> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
423-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;node&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;add&#x27;)" TARGET=""
424-
><B>OP:</B> <I>node</I></TD></TR
425-
><TR><TD ALIGN="left" TOOLTIP="&lt;built-in function add&gt;" TARGET=""
426-
><B>FN:</B> _operator.add</TD></TR>
430+
<node> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
431+
<TR>
432+
<TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;node&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;add&#x27;)" TARGET=""
433+
><B>OP:</B> <I>node</I></TD>
434+
</TR><TR>
435+
<TD ALIGN="left" TOOLTIP="&lt;built-in function add&gt;" TARGET=""
436+
><B>FN:</B> _operator.add</TD>
437+
</TR>
427438
</TABLE>>, shape=plain, tooltip=<node>];
428439
<&lt;graph&gt;> [shape=rect];
429-
<cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
430-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;cu:sto:m&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;func&#x27;)" TARGET=""
431-
><B>OP:</B> <I>cu:sto:m</I></TD></TR
432-
><TR><TD ALIGN="left" TOOLTIP="def func():&#10; pass" TARGET=""
433-
><B>FN:</B> test.test_plot.func</TD></TR>
440+
<cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
441+
<TR>
442+
<TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;cu:sto:m&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;func&#x27;)" TARGET=""
443+
><B>OP:</B> <I>cu:sto:m</I></TD>
444+
</TR><TR>
445+
<TD ALIGN="left" TOOLTIP="def func():&#10; pass" TARGET=""
446+
><B>FN:</B> test.test_plot.func</TD>
447+
</TR>
434448
</TABLE>>, shape=plain, tooltip=<cu:sto:m>];
435449
<edge> -> <node>;
436450
<edge> -> <cu&#58;sto&#58;m>;
@@ -460,18 +474,24 @@ def test_node_dot_str1(dot_str_pipeline, monkeypatch):
460474
splines=ortho;
461475
<edge> [shape=rect];
462476
<digraph&#58; strict> [shape=rect];
463-
<node> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
464-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;node&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;add&#x27;)" HREF="abc#{&#x27;dot_path&#x27;: &#x27;_operator.add&#x27;, &#x27;posix_path&#x27;: &#x27;_operator/add&#x27;}" TARGET="bad"
465-
><B>OP:</B> <I>node</I></TD></TR
466-
><TR><TD ALIGN="left" TOOLTIP="&lt;built-in function add&gt;" HREF="abc#{&#x27;dot_path&#x27;: &#x27;_operator.add&#x27;, &#x27;posix_path&#x27;: &#x27;_operator/add&#x27;}" TARGET="bad"
467-
><B>FN:</B> _operator.add</TD></TR>
477+
<node> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
478+
<TR>
479+
<TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;node&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;add&#x27;)" HREF="abc#{&#x27;dot_path&#x27;: &#x27;_operator.add&#x27;, &#x27;posix_path&#x27;: &#x27;_operator/add&#x27;}" TARGET="bad"
480+
><B>OP:</B> <I>node</I></TD>
481+
</TR><TR>
482+
<TD ALIGN="left" TOOLTIP="&lt;built-in function add&gt;" HREF="abc#{&#x27;dot_path&#x27;: &#x27;_operator.add&#x27;, &#x27;posix_path&#x27;: &#x27;_operator/add&#x27;}" TARGET="bad"
483+
><B>FN:</B> _operator.add</TD>
484+
</TR>
468485
</TABLE>>, shape=plain, tooltip=<node>];
469486
<&lt;graph&gt;> [shape=rect];
470-
<cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
471-
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;cu:sto:m&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;func&#x27;)" HREF="abc#{&#x27;dot_path&#x27;: &#x27;test.test_plot.func&#x27;, &#x27;posix_path&#x27;: &#x27;test/test_plot/func&#x27;}" TARGET="bad"
472-
><B>OP:</B> <I>cu:sto:m</I></TD></TR
473-
><TR><TD ALIGN="left" TOOLTIP="def func():&#10; pass" HREF="abc#{&#x27;dot_path&#x27;: &#x27;test.test_plot.func&#x27;, &#x27;posix_path&#x27;: &#x27;test/test_plot/func&#x27;}" TARGET="bad"
474-
><B>FN:</B> test.test_plot.func</TD></TR>
487+
<cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded">
488+
<TR>
489+
<TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FunctionalOperation(name=&#x27;cu:sto:m&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;func&#x27;)" HREF="abc#{&#x27;dot_path&#x27;: &#x27;test.test_plot.func&#x27;, &#x27;posix_path&#x27;: &#x27;test/test_plot/func&#x27;}" TARGET="bad"
490+
><B>OP:</B> <I>cu:sto:m</I></TD>
491+
</TR><TR>
492+
<TD ALIGN="left" TOOLTIP="def func():&#10; pass" HREF="abc#{&#x27;dot_path&#x27;: &#x27;test.test_plot.func&#x27;, &#x27;posix_path&#x27;: &#x27;test/test_plot/func&#x27;}" TARGET="bad"
493+
><B>FN:</B> test.test_plot.func</TD>
494+
</TR>
475495
</TABLE>>, shape=plain, tooltip=<cu:sto:m>];
476496
<edge> -> <node>;
477497
<edge> -> <cu&#58;sto&#58;m>;

0 commit comments

Comments
 (0)