0

我正在尝试使用 graphviz 创建状态机图,但无法很好地显示它。

这是用点语言描述的图:

digraph finite_state_machine {
    node [shape = point];
    PWRON

    node [shape=circle];
    PWROFF [fontsize=10]

    PWRON  -> BOOT     [label="start_boot_timer"]

    BOOT   -> HOME   [label="boot_timer_expires"]
    HOME   -> HOME   [label="home to home 1"]
    HOME   -> HOME   [label="home to home 2"]
    HOME   -> HOME   [label="home to home 3"]

    HOME   -> BLEADV [label="short_button_press"]
    BLEADV -> BLECON [label="ble_conn_event"]
    BLECON -> HOME   [label="ble_conn_close"]

    HOME   -> PWROFF [label="power off"]
}

绘制的图表如下所示:

绘制的图是这样的

我是 dot/graphviz 的新手,你能帮我更好地展示它吗?

目前的主要问题是:
* 从家到家的自循环全部重叠
* BLEADV 和 BLECON 的放置不是很好(优先级较低)

4

2 回答 2

0

这使用了一组不同的属性:

digraph finite_state_machine {
    //splines=false // probably not

  subgraph cluster1 { 
    peripheries=0

    PWRON  [shape = point ];
    node [shape=circle];
    //node [shape=rect];  // see if you like a different shape
    PWROFF [fontsize=10]

    PWRON    -> BOOT      [label="start_boot_timer"]

    // changes: ports, headlabels, tail labels, spaces, and newlines
    //          cluster was added to (partially) straighten the column
    BOOT     -> HOME      [label="boot_timer_expires"]
    HOME:w   -> HOME:sw   [headlabel="home to home 1      " ]
    HOME:n   -> HOME:nw   [taillabel="home to home 2     \n\n" ]
    HOME:n   -> HOME:e    [label="home to home 3"]

    HOME:s   -> BLEADV    [label="short_button_press"]
    BLEADV   -> BLECON    [label="ble_conn_event"]
    BLECON   -> HOME:se   [label="ble_conn_close"]

  }
  PWROFF
  HOME:s   -> PWROFF    [label="\npower off  " ]
}

制作这个: 在此处输入图像描述

于 2020-03-24T19:33:38.357 回答
0

要改善 HOME 上的循环,您可以使用罗盘点

HOME:s   -> HOME:n   [label="home to home 1"]
HOME:s   -> HOME:n   [label="home to home 2"]
HOME:s   -> HOME:n   [label="home to home 3"]

不确定你想改进节点的位置,但如果你想在 and 之间有一条垂直的直边HOMEPWROFF只需将它们分配到同一个组(在定义涉及它们的边之前):

HOME[group=a]
PWROFF[group=a]

全部一起:

digraph finite_state_machine {
    node [shape = point];
    PWRON

    node [shape=circle];
    PWROFF [fontsize=10]

    PWRON  -> BOOT     [label="start_boot_timer"]

    HOME[group=a]
    PWROFF[group=a]

    BOOT   -> HOME   [label="boot_timer_expires"]
    HOME:s   -> HOME:n   [label="home to home 1"]
    HOME:s   -> HOME:n   [label="home to home 2"]
    HOME:s   -> HOME:n   [label="home to home 3"]

    HOME   -> BLEADV [label="short_button_press"]
    BLEADV -> BLECON [label="ble_conn_event"]
    BLECON -> HOME:w   [label="ble_conn_close"]


    HOME   -> PWROFF [label="power off"]
}

改进的布局

于 2020-03-24T10:46:29.820 回答