Beispiel #1
0
extlinks = {
    "gh": ("https://github.com/yahoo/graphkit/issues/%s", "yahoo#"),
    "gg": ("https://github.com/pygraphkit/graphtik/issues/%s", "#"),
}


## Plot graphtik SVGs with links to docs.
#
def _make_py_item_url(fn):
    if not inspect.isbuiltin(fn):
        fn_name = func_name(fn, None, mod=1, fqdn=1, human=0)
        if fn_name:
            return f"../reference.html#{fn_name}"


plotter = plot.get_active_plotter()
plot.set_active_plotter(
    plotter.with_styles(
        kw_op_label={
            **plotter.default_theme.kw_op_label,
            "op_url":
            lambda plot_args: _make_py_item_url(plot_args.nx_item),
            "fn_url":
            lambda plot_args: plot_args.nx_item and _make_py_item_url(
                plot_args.nx_item.fn),
        }))

github_slug = "pygraphkit/graphtik"
try:
    git_commit = sbp.check_output(
        "git rev-parse HEAD".split()).strip().decode()
Beispiel #2
0
def test_node_dot_str1(dot_str_pipeline, monkeypatch):
    ## Test node-hidding & Graph-overlaying.
    #
    overlay = nx.DiGraph()
    hidden_op = dot_str_pipeline.net.find_op_by_name("node")
    overlay.add_node(hidden_op, no_plot=True)
    overlay.graph["graphviz.splines"] = "ortho"

    exp = r"""
    digraph solution_x5_nodes {
    fontname=italic;
    splines=ortho;
    node [fillcolor=white, style=filled];
    subgraph "cluster_after pruning" {
    label=<after pruning>;
    <edge> [fillcolor=wheat, fixedsize=shape, label=<<TABLE CELLBORDER="0" CELLSPACING="0" BORDER="0">
                <TR><TD>edge</TD>
                </TR>
            </TABLE>>, shape=invhouse, style=filled, tooltip="(input)\n(int) 1"];
    <digraph&#58; strict> [fillcolor=wheat, fixedsize=shape, label=<<TABLE CELLBORDER="0" CELLSPACING="0" BORDER="0">
                <TR><TD>digraph: strict</TD>
                </TR>
            </TABLE>>, shape=invhouse, style=filled, tooltip="(input)\n(int) 2"];
    <&lt;graph&gt;> [fillcolor=SkyBlue, fixedsize=shape, label=<<TABLE CELLBORDER="0" CELLSPACING="0" BORDER="0">
                <TR><TD><graph></TD>
                </TR>
            </TABLE>>, shape=house, style=filled, tooltip="(output)\n(None)\n(x2 overwrites) 1. 3&#10;  0. None"];
    <cu&#58;sto&#58;m> [label=<<TABLE CELLBORDER="0" CELLSPACING="0" STYLE="rounded" BGCOLOR="wheat">
        <TR>
            <TD BORDER="1" SIDES="b" ALIGN="left" TOOLTIP="FnOp(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="_top"
            ><B>OP:</B> <I>cu:sto:m</I></TD>
            <TD BORDER="1" SIDES="b" ALIGN="right"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="1" CELLPADDING="2" ALIGN="right">
                    <TR>
                        <TD STYLE="rounded" HEIGHT="22" WIDTH="14" FIXEDSIZE="true" VALIGN="BOTTOM" BGCOLOR="#00bbbb" TITLE="computation order" HREF="https://graphtik.readthedocs.io/en/latest/arch.html#term-steps" TARGET="_top"><FONT FACE="monospace" COLOR="white"><B>0</B></FONT></TD>
                    </TR>
                </TABLE></TD>
        </TR>
        <TR>
            <TD COLSPAN="2" ALIGN="left" TOOLTIP="def func(a, b):&#10;    pass" TARGET="_top"
            ><B>FN:</B> test.test_plot.func</TD>
        </TR>
    </TABLE>>, shape=plain, tooltip=<cu:sto:m>];
    }

    <edge> -> <cu&#58;sto&#58;m>  [arrowtail=inv, dir=back, headport=n, tailport=s];
    <digraph&#58; strict> -> <cu&#58;sto&#58;m>  [arrowtail=inv, dir=back, headport=n, tailport=s];
    <cu&#58;sto&#58;m> -> <&lt;graph&gt;>  [color="#ffa9cd", headport=n, tailport=s, tooltip="(null-result)"];
    legend [URL="https://graphtik.readthedocs.io/en/latest/_images/GraphtikLegend.svg", fillcolor=yellow, shape=component, style=filled, target=_blank];
    }
    """

    ## Theme-param.
    #
    sol = dot_str_pipeline.compute({"edge": 1, "digraph: strict": 2})
    dot_str = str(
        sol.plot(
            graph=overlay,
            theme=Theme(
                op_link_target="_self",
                fn_link_target="bad",
            ),
        ))

    print(dot_str)
    assert _striplines(dot_str) == _striplines(exp)
    assert "<node>" not in dot_str

    ## Plotter-param
    #
    dot_str = str(
        sol.plot(
            graph=overlay,
            plotter=get_active_plotter().with_styles(
                op_link_target="_self",
                fn_link_target="bad",
            ),
        ))
    assert _striplines(dot_str) == _striplines(exp)
    assert "<node>" not in dot_str