控制位图渲染

发布于 2024-11-03 19:59:35 字数 358 浏览 1 评论 0原文

我正在尝试

  • 生成一个图表,通过 Graphviz 在网站上显示。
  • 使每个节点可通过图像映射(或其他一些工具)单击。

为此,我必须渲染图形

  • 我应该设置什么属性来获取渲染图形的最大宽度/高度?我查看了页面 http://www.graphviz.org/doc/info/attrs。 html 并尝试操作诸如 size 之类的属性,但它似乎对我不起作用。
  • 我应该如何解释节点和边的 pos 属性?

I'm trying to

  • generate a graph to be displayed in a website via Graphviz.
  • make each nodes clickable by imagemap (or some other tools).

To do so, I have to render the graph

  • What attribute should I set to get the max width / height of the rendered graph? I looked into the page http://www.graphviz.org/doc/info/attrs.html and tried to manipulate attributes such as size but it didn't seem to work on me.
  • How should I interpret the pos attributes of nodes and edges?

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

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

发布评论

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

评论(1

枉心 2024-11-10 19:59:36

控制大小

正如您正确假设的那样,这可以通过修改 size 来完成。

以下是一些示例:

digraph {1->2;}

图像尺寸:83*155px。这是默认设置下图表的大小。

digraph {size=1; 1->2;}

图片尺寸:51*96px。图像被缩小以适合 1 英寸见方 (96 dpi)。这是预期的行为,因为文档指出:

如果已定义且绘图较大
比给定的尺寸,绘图是
统一缩小以适合
在给定的尺寸内。

digraph {size=2; 1->2;}

图片尺寸:83*155px。同样符合预期的行为,图表已经小于 2 英寸,不需要缩小。

digraph {size="2!"; 1->2;}

图片尺寸:103*192px。该图已按比例放大,直到其中一个尺寸等于 2 英寸。预期行为,因为文档指出:

如果大小以感叹号结尾
(!),则它被视为
所需的尺寸。在这种情况下,如果两者
图纸尺寸较小
与尺寸相比,绘图是按比例放大的
均匀直到至少一维
大小等于其尺寸。

解释节点和边的 pos 属性

我假设您的意思是 xdot 格式的 pos 值。

图形的 xdot

digraph {1->2;}

如下所示

digraph {
    node [label="\N"];
    graph [bb="0,0,54,108",
        _draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 108 55 108 55 -1 ",
        xdotversion="1.2"];
    1 [pos="27,90", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 27 90 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 27 84 0 7 1 -1 "];
    2 [pos="27,18", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 27 18 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 27 12 0 7 1 -2 "];
    1 -> 2 [pos="e,27,36.413 27,71.831 27,64.131 27,54.974 27,46.417", _draw_="c 9 -#000000ff B 4 27 72 27 64 27 55 27 46 ", _hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 31 46 27 36 24 46 "];
}

节点的 pos 值指定节点位置的中心。由于图的边界框是“0,0,54,108”,因此节点位置“27,18”和“27,90”完全水平居中。

对于边缘,我猜 pos 包含边缘段的点,而 _draw_ 包含 B-Spline 控制点(但我对此不太确定)。

Controlling the size

As you correctly assumed, this can be done by modifying size.

Here are some examples:

digraph {1->2;}

Image dimensions: 83*155px. This is the size of the graph with default settings.

digraph {size=1; 1->2;}

Image dimensions: 51*96px. The image got scaled down to fit in a 1 inch square (96 dpi). This is expected behavior because the documentation states:

If defined and the drawing is larger
than the given size, the drawing is
uniformly scaled down so that it fits
within the given size.

digraph {size=2; 1->2;}

Image dimensions: 83*155px. Again expected behavior, the graph is already smaller than 2 inches and does not need to be scaled down.

digraph {size="2!"; 1->2;}

Image dimensions: 103*192px. The graph was scaled up to until one of the dimensions equals 2 inches. Expected behavior because the documentation states:

If size ends in an exclamation point
(!), then it is taken to be the
desired size. In this case, if both
dimensions of the drawing are less
than size, the drawing is scaled up
uniformly until at least one dimension
equals its dimension in size.

Interpreting pos attributes of nodes and edges

I'm assuming you mean to pos values of the xdot format.

The xdot of the graph

digraph {1->2;}

is the following

digraph {
    node [label="\N"];
    graph [bb="0,0,54,108",
        _draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 108 55 108 55 -1 ",
        xdotversion="1.2"];
    1 [pos="27,90", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 27 90 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 27 84 0 7 1 -1 "];
    2 [pos="27,18", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 27 18 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 27 12 0 7 1 -2 "];
    1 -> 2 [pos="e,27,36.413 27,71.831 27,64.131 27,54.974 27,46.417", _draw_="c 9 -#000000ff B 4 27 72 27 64 27 55 27 46 ", _hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 31 46 27 36 24 46 "];
}

The pos values of the nodes designate the center of the node position. Since the bounding box of the graph is "0,0,54,108", the node positions "27,18" and "27,90" are perfectly centered horizontally.

For edges, I guess the pos contains the points of the edge segments, whereas _draw_ contains the B-Spline control points (but I'm not really sure about that).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文