Skip to content

Commit ea91c44

Browse files
committed
style(plot); reodred template func together
1 parent 85121cd commit ea91c44

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

graphtik/plot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ def _pub_props(*d, **kw) -> None:
241241
return {k: v for k, v in dict(*d, *kw).items() if not str(k).startswith("_")}
242242

243243

244-
def _render_template(tpl: jinja2.Template, **kw) -> str:
245-
"""Ignore falsy values, to skip attributes in template all together. """
246-
return tpl.render(**{k: v for k, v in kw.items() if v})
247-
248-
249244
class NodeArgs(NamedTuple):
250245
"""All the args for :meth:`.Plotter._make_node()` call. """
251246

@@ -314,6 +309,11 @@ def _escape_or_none(context: jinja2.environment.EvalContext, x, escaper):
314309
_jinja2_env.filters["hrefer"] = _drop_gt_lt
315310

316311

312+
def _render_template(tpl: jinja2.Template, **kw) -> str:
313+
"""Ignore falsy values, to skip attributes in template all together. """
314+
return tpl.render(**{k: v for k, v in kw.items() if v})
315+
316+
317317
class Style:
318318
"""
319319
The poor man's css-like :term:`plot styles` applied like a theme.

test/test_plot.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def test_op_label_template_full():
8484
print(got)
8585
exp = """
8686
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded" BORDER="44" COLOR="red" BGCOLOR="wheat"
87-
><TR><TD BORDER="1" SIDES="b" TOOLTIP="&lt;op &quot; &#9; tooltip&gt;" HREF="http://op_url.com_label_" TARGET="_self"
87+
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="&lt;op &quot; &#9; tooltip&gt;" HREF="http://op_url.com_label_" TARGET="_self"
8888
><FONT COLOR="blue"><B>OP:</B> <I>the op</I></FONT></TD></TR
89-
><TR><TD TOOLTIP="&lt;fn&#10;tooltip&gt;" HREF="http://fn_url.com/quoto_and" TARGET="_top"
89+
><TR><TD ALIGN="left" TOOLTIP="&lt;fn&#10;tooltip&gt;" HREF="http://fn_url.com/quoto_and" TARGET="_top"
9090
><FONT COLOR="blue"><B>FN:</B> the fn</FONT></TD></TR>
9191
</TABLE>>
9292
"""
@@ -103,7 +103,7 @@ def test_op_label_template_empty():
103103
print(got)
104104
exp = """
105105
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
106-
><TR><TD BORDER="1" SIDES="b"
106+
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
107107
></TD></TR
108108
>
109109
</TABLE>>
@@ -116,9 +116,9 @@ def test_op_label_template_fn_empty():
116116
print(got)
117117
exp = """
118118
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
119-
><TR><TD BORDER="1" SIDES="b"
119+
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
120120
><B>OP:</B> <I>op</I></TD></TR
121-
><TR><TD
121+
><TR><TD ALIGN="left" TARGET=""
122122
><B>FN:</B> fn</TD></TR>
123123
</TABLE>>
124124
"""
@@ -143,7 +143,7 @@ def test_op_label_template_nones():
143143
print(got)
144144
exp = """
145145
<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
146-
><TR><TD BORDER="1" SIDES="b"
146+
><TR><TD BORDER="1" SIDES="b" ALIGN="left" TARGET=""
147147
></TD></TR
148148
>
149149
</TABLE>>
@@ -420,16 +420,16 @@ def test_node_dot_str0(dot_str_pipeline):
420420
<edge> [shape=rect];
421421
<digraph&#58; strict> [shape=rect];
422422
<node> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
423-
><TR><TD BORDER="1" SIDES="b" TOOLTIP="FunctionalOperation(name=&#x27;node&#x27;, needs=[&#x27;edge&#x27;, &#x27;digraph: strict&#x27;], provides=[&#x27;&lt;graph&gt;&#x27;], fn=&#x27;add&#x27;)"
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=""
424424
><B>OP:</B> <I>node</I></TD></TR
425-
><TR><TD TOOLTIP="&lt;built-in function add&gt;"
425+
><TR><TD ALIGN="left" TOOLTIP="&lt;built-in function add&gt;" TARGET=""
426426
><B>FN:</B> _operator.add</TD></TR>
427427
</TABLE>>, shape=plain, tooltip=<node>];
428428
<&lt;graph&gt;> [shape=rect];
429429
<cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
430-
><TR><TD BORDER="1" SIDES="b" 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;)"
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=""
431431
><B>OP:</B> <I>cu:sto:m</I></TD></TR
432-
><TR><TD TOOLTIP="def func():&#10; pass"
432+
><TR><TD ALIGN="left" TOOLTIP="def func():&#10; pass" TARGET=""
433433
><B>FN:</B> test.test_plot.func</TD></TR>
434434
</TABLE>>, shape=plain, tooltip=<cu:sto:m>];
435435
<edge> -> <node>;
@@ -461,16 +461,16 @@ def test_node_dot_str1(dot_str_pipeline, monkeypatch):
461461
<edge> [shape=rect];
462462
<digraph&#58; strict> [shape=rect];
463463
<node> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
464-
><TR><TD BORDER="1" SIDES="b" 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"
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"
465465
><B>OP:</B> <I>node</I></TD></TR
466-
><TR><TD 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"
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"
467467
><B>FN:</B> _operator.add</TD></TR>
468468
</TABLE>>, shape=plain, tooltip=<node>];
469469
<&lt;graph&gt;> [shape=rect];
470470
<cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded"
471-
><TR><TD BORDER="1" SIDES="b" 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"
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"
472472
><B>OP:</B> <I>cu:sto:m</I></TD></TR
473-
><TR><TD 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"
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"
474474
><B>FN:</B> test.test_plot.func</TD></TR>
475475
</TABLE>>, shape=plain, tooltip=<cu:sto:m>];
476476
<edge> -> <node>;

0 commit comments

Comments
 (0)