从 dot 文件生成 xdot 文件的 PHP 库

发布于 2024-10-15 13:56:02 字数 1744 浏览 1 评论 0原文

提前致歉,因为我误用了术语,欢迎指正。我对有向图着迷,但我从来没有数学/计算机背景来了解它们真正的内容,我只是喜欢这项技术,因为它可以制作有用的图表。

我”我正在尝试创建一个 Web 应用程序功能,该功能将向浏览器呈现动态有向图。我最近发现了 Canviz,这是一个基于 cavas 的 xdot 渲染器,我想使用它。

Canviz 很棒,但它呈现 xdot 文件,这些文件(看起来?)包含所有复杂的定位逻辑

/* example xdot file */
digraph abstract {
    graph [size="6,6"];
    node [label="\N"];
    graph [bb="0,0,1250,612",
        _draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 612 1251 612 1251 -1 ",
        xdotversion="1.2"];
    S1 [pos="464,594", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 464 594 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 464 588 0 15 2 -S1 "];
    10 [pos="409,522", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 409 522 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 409 516 0 15 2 -10 "];

    S1 -> 10 [pos="e,421.43,538.27 451.52,577.66 444.49,568.46 435.57,556.78 427.71,546.5", _draw_="c 9 -#000000ff B 4 452 578 444 568 436 557 428 546 ", _hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 430 544 421 538 425 548 "];
}

我用应用程序生成的文件是 dot 文件,它不包含任何定位逻辑

digraph g {

    ranksep=6
    node [
        fontsize = "16"
        shape = "rectangle"
        width =3
        height =.5
    ];
    edge [
    ];

    S1 -> 10
}    

我正在寻找一个 PHP 库,可以将我的 dot 文件转换为可由 Canviz 使用的 xdot 文件。我意识到命令行程序 dot 可以做到这一点,但这是针对可再发行的 PHP Web 应用程序,我希望避免任何二进制文件作为依赖项。

我的核心问题:我正在基于简单的有向关系生成 dot 文件,并且我想在浏览器中向最终用户显示可视化图形。我想这样做而不必依赖服务器上特定二进制程序的存在。我认为最好的解决方案是 Canviz+PHP 生成 xdot 文件。我正在寻找一个可以做到这一点的 PHP 库。然而,我对其他解决方案持开放态度。

Apologies in advance is I'm misusing terminology, and corrections are appreciated. I'm fascinated by directed graphs, but I never has the math/cs background to know what they're really about, I just like the tech because it makes useful diagrams.

I'm trying to create a web application feature that will render a dynamic directed graph to the browser. I recently discovered Canviz, which is a cavas based xdot renderer, which I'd like to use.

Canviz is awesome, but it renders xdot files, which (appear?) to contain all the complicated positioning logic

/* example xdot file */
digraph abstract {
    graph [size="6,6"];
    node [label="\N"];
    graph [bb="0,0,1250,612",
        _draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 612 1251 612 1251 -1 ",
        xdotversion="1.2"];
    S1 [pos="464,594", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 464 594 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 464 588 0 15 2 -S1 "];
    10 [pos="409,522", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 409 522 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 409 516 0 15 2 -10 "];

    S1 -> 10 [pos="e,421.43,538.27 451.52,577.66 444.49,568.46 435.57,556.78 427.71,546.5", _draw_="c 9 -#000000ff B 4 452 578 444 568 436 557 428 546 ", _hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 430 544 421 538 425 548 "];
}

The files I'm generating with my application are dot files, which contain none of this positioning logic

digraph g {

    ranksep=6
    node [
        fontsize = "16"
        shape = "rectangle"
        width =3
        height =.5
    ];
    edge [
    ];

    S1 -> 10
}    

I'm looking for a PHP library that can convert my dot file into an xdot file that can be consumed by Canviz. I realize that the command line program dot can do this, but this is for a redistributable PHP web application, and I'd prefer to avoid any binaries as dependencies.

My core problem: I'm generating dot files based on simple directed relationships, and I want to display the visual graph to end users in a browser. I'd like to do this without having to rely on the presence of a particular binary program on the server. I think the best solution for this is Canviz+PHP to generate xdot files. I'm looking for a PHP library that can do this. However, I'm more than open to other solutions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清眉祭 2024-10-22 13:56:02

您看过 Image_GraphViz 吗?它实际上只是二进制文件的包装器,但从外观来看,我认为您不会找到更好的东西,这至少使您不必从 PHP 脚本进行直接命令行调用。

 $dot_obj = new Image_GraphViz();
 $dot_obj -> load('path/to/graph.gv');
 $xdot = $dot_obj -> fetch('xdot');

Have you looked at Image_GraphViz ? It's really just a wrapper for the binary, but from the look of things, I don't think you'll find something better and this at least keeps you from having to do direct command line calls from your PHP script.

 $dot_obj = new Image_GraphViz();
 $dot_obj -> load('path/to/graph.gv');
 $xdot = $dot_obj -> fetch('xdot');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文