Graphviz –具有HTML标签的节点没有端口

时间:2019-02-09 21:31:04

标签: graphviz

我有Mrecord节点,每个节点都有许多使用HTML标签指定的字段。我的表中有TD,每个TD都有一个port =“ ...”属性。但是,当我指定边缘的头端端口和尾端端口以使用这些端口名称时,总是会收到警告,提示该端口无法识别:

ex: Warning: node departments, port dept_no unrecognized

,但我100%确定确实存在这样的端口。这是html的一个简单例子:

<table><tr><td>departments</td></tr><tr><td port="dept_no">dept_no</td></tr></table>

已将其设置为节点的标签,我假设该节点将具有一个dept_no端口,但没有。

-

现在更多信息:我正在使用C API构造此图并进行布局等。布局后,每个节点都有一个标签,其中html布尔值为true,但标签本身没有html数据,也没有端口等。

令人困惑。我不知道为什么节点没有端口。

#include <stdio.h>
#include <gvc.h>
#include <gvplugin.h>


extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_core_LTX_library;

lt_symlist_t lt_preloaded_symbols[] =
{
    { "gvplugin_dot_layout_LTX_library", &gvplugin_dot_layout_LTX_library},
    { "gvplugin_core_LTX_library", &gvplugin_core_LTX_library},
    { 0, 0}
};



int main(int argc, const char * argv[])
{
    GVC_t * gvc = gvContextPlugins(lt_preloaded_symbols, 0);
    Agraph_t * gvg = agopen("Graph", Agdirected, NULL);

    agattr(gvg, AGRAPH, "dpi",         "72");
    agattr(gvg, AGRAPH, "resolution",  "72"); 
    agattr(gvg, AGRAPH, "sep",         "0.27777"); 
    agattr(gvg, AGRAPH, "rankdir",     "TB");
    agattr(gvg, AGRAPH, "ranksep",     "0.5");
    agattr(gvg, AGRAPH, "nodesep",     "0.4");
    agattr(gvg, AGRAPH, "pad",         "0.5,0.5");
    agattr(gvg, AGRAPH, "margin",      "0,0");
    agattr(gvg, AGRAPH, "splines",     "spline");

    agattr(gvg, AGNODE, "shape",       "Mrecord");
    agattr(gvg, AGNODE, "width",       "0");
    agattr(gvg, AGNODE, "height",      "0");
    agattr(gvg, AGNODE, "fixedsize",   "false");
    agattr(gvg, AGNODE, "margin",      "0.0,0.0"); 
    agattr(gvg, AGNODE, "penwidth",    "0.0");
    agattr(gvg, AGNODE, "fontsize",    "13");

    agattr(gvg, AGEDGE, "arrowsize",     "0.5");
    agattr(gvg, AGEDGE, "penwidth",      "1.0");
    agattr(gvg, AGEDGE, "labelangle",    "32");
    agattr(gvg, AGEDGE, "labeldistance", "1.8");
    agattr(gvg, AGEDGE, "dir",           "none");
    agattr(gvg, AGEDGE, "headport",      "_");
    agattr(gvg, AGEDGE, "tailport",      "_");


    const char * nodeALabel = "<table id=\"dept_emp\" width=\"140\" height=\"26\"><tr><td height=\"26\">dept_emp</td></tr><tr><td height=\"20\" port=\"emp_no\">emp_no</td></tr><tr><td height=\"20\" port=\"dept_no\">dept_no</td></tr></table>";
    const char * nodeBLabel = "<table id=\"departments\" width=\"140\" height=\"26\"><tr><td height=\"26\">departments</td></tr><tr><td height=\"20\" port=\"dept_no\">dept_no</td></tr><tr><td height=\"20\" port=\"dept_name\">dept_name</td></tr></table>";

    Agnode_t * nodeA = agnode(gvg, "dept_emp", 1);
    Agnode_t * nodeB = agnode(gvg, "departments", 1);

    char * la = agstrdup_html(gvg, (char *)nodeALabel);
    char * lb = agstrdup_html(gvg, (char *)nodeBLabel);
    agsafeset(nodeA, "label", la, "");
    agsafeset(nodeB, "label", lb, "");
    agstrfree(gvg, la);
    agstrfree(gvg, lb);


    // An edge pointing from dept_emp.dept_no ---> departments.dept_no 
    Agedge_t * edge = agedge(gvg, nodeA, nodeB, NULL, 1);

    agsafeset(edge, "dir", "forward", "none");
    agsafeset(edge, "tailport", "dept_no", "_");
    agsafeset(edge, "headport", "dept_no", "_");

    gvLayout(gvc, gvg, "dot");

    //  Warning: node dept_emp, port dept_no unrecognized
    //  Warning: node departments, port dept_no unrecognized



    return 0;
}

1 个答案:

答案 0 :(得分:0)

尽管呈现HTML令人困惑,但是无法识别端口,但是基于记录的节点和类似HTML的标签不应混用。它们具有冲突的标签架构和重叠的功能。正如Graphviz的一位作者所证实的那样,它们在设计上是不兼容的,完全没想到人们会尝试将两者结合起来。因此,解决方案是将Mrecord替换为none。有关详细信息,请参见https://gitlab.com/graphviz/graphviz/issues/1491