Graphvizで凡例付きアクティビティ図(残骸)

Graphvizで凡例付きアクティビティ図を書く。あまり綺麗でない

Graphvizで凡例付きアクティビティ図(残骸)

digraph sample {
  graph [fontname = "monospace", fontsize = 10];
  node  [fontname = "monospace", fontsize = 10];
  edge  [fontname = "monospace", fontsize = 10];

  // node
  node  [shape = circle];
  start [height = 0.3, width = 0.3, style = filled, fillcolor = black, label = ""];
  end   [height = 0.3, width = 0.3, style = filled, fillcolor = black, label = "", peripheries = 2];

  node   [shape = diamond];
  branch [label = ""];
  merge  [label = ""];

  node [shape = box];
  folk [height = 0.01, style = filled, fillcolor = black, label = ""];
  join [height = 0.01, style = filled, fillcolor = black, label = ""];

  node [shape = ellipse];
  process [label = "処理"];
  object  [label = "<<Object>>\nオブジェクト"];

  // edge
  edge [style = solid, arrowhead = vee];
  start   -> branch;
  branch  -> folk;
  branch  -> merge;
  folk    -> process;
  process -> join;
  join    -> merge;
  merge   -> end;

  edge [style = dashed, arrowhead = vee];
  folk   -> object;
  object -> join;

  // alignment

  // legend
  subgraph cluster_legend {
    label = "凡例";
    // node
    node   [shape = none];
    level1 [group = 1, label = "スタート"];
    level2 [group = 1, label = "分岐"];
    level3 [group = 1, label = "フォーク\n(並列処理)"];
    level4 [group = 1, label = "処理"];
    level5 [group = 1, label = "ジョイン"];
    level6 [group = 1, label = "結合"];
    level7 [group = 1, label = "エンド"];

    node     [shape = circle];
    start_ex [height = 0.3, width = 0.3, style = filled, fillcolor = black, label = ""];
    end_ex   [height = 0.3, width = 0.3, style = filled, fillcolor = black, label = "", peripheries = 2];

    node      [shape = diamond];
    branch_ex [label = ""];
    merge_ex  [label = ""];

    node    [shape = box];
    folk_ex [height = 0.01, style = filled, fillcolor = black, label = ""];
    join_ex [height = 0.01, style = filled, fillcolor = black, label = ""];

    node       [shape = ellipse];
    process_ex [label = "処理"];
    object_ex  [label = "<<Object>>\nオブジェクト"];
   
    // edge
    edge             [style = invis];
    level1 -> level2 [weight = 5.0];
    level2 -> level3 [weight = 5.0];
    level3 -> level4 [weight = 5.0];
    level4 -> level5 [weight = 5.0];
    level5 -> level6 [weight = 5.0];
    level6 -> level7 [weight = 5.0];

    edge [style = solid];
    start_ex   -> branch_ex;
    branch_ex  -> folk_ex;
    branch_ex  -> merge_ex;
    folk_ex    -> process_ex [label = "同期"];
    process_ex -> join_ex;
    join_ex    -> merge_ex;
    merge_ex   -> end_ex;

    edge              [style = dashed];
    folk_ex    -> object_ex [label = "非同期"];
    object_ex  -> join_ex;

    // rank
    {rank = same; level1; start_ex}
    {rank = same; level2; branch_ex}
    {rank = same; level3; folk_ex}
    {rank = same; level4; process_ex; object_ex}
    {rank = same; level5; join_ex}
    {rank = same; level6; merge_ex}
    {rank = same; level7; end_ex}
  }
}