【问题标题】:plantuml - draw note above activity diagramPlantuml - 在活动图上方绘制注释
【发布时间】:2017-07-12 03:52:38
【问题描述】:

我在here 找到了一个很好的活动图,但没有源代码。它如下所示:

我尝试用 plantuml 绘制它,下面是我的代码:

@startuml
skinparam linetype ortho

(*) -down-> "clone repository"
note right
A:git clone url/to/repository
scp -p url/to/hooks/commit_msg repository/.git/hooks
end note
-down->[get an assignment] "coding"
-down-> "commit locally"
note right
B:git add xxx
git commit
end note
-down-> "review"
note right
C:git push origin refs/for/<branch>
end note
if "" then
  -left->[rejected] "rework"
  -up-> "recommit"
'note left
'D:git add xxx
'git commit --amend
'end note
  -right-> "review"
else
  --right-->[approved] "submit"
note right: E:click "submit" on on corresponding gerrit page
  -up-> "update local repository"
note right
F:git pull --rebase
end note
  -left->[get another task(a new cycle)] "coding"
@enduml

输出是:

显然,还是不像原图:

  1. 上面/下面的注释不起作用,不知道怎么做(比如下面应该有E注释)
  2. 中心流不在直线上。
  3. “提交”到“更新本地存储库”已更改 2 次。

我怎样才能像原始输出一样改进它?

【问题讨论】:

  • 要将注释添加到活动的顶部,请在活动之后使用note top。底部使用note bottom。除此之外,使用不同大小的箭头需要反复试验。

标签: plantuml


【解决方案1】:

plantuml 会自动放置节点,如果你想把节点放在精确的位置,TikZ 可能会更好:

\documentclass[convert={outfile=\jobname.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,chains,positioning,shapes,scopes,quotes,decorations.markings,shapes.multipart,shapes.callouts}
\begin{document}

\newcommand{\ann}[3][]
{
  \node[align=center, draw=noteBorderColor,fill=noteBackgroundColor,
        rectangle callout, anchor=pointer,
        callout relative pointer={(#2)},#1] {#3};
}
 \begin{tikzpicture}[>=latex,node distance =8mm,
    every text node part/.style={align=left},
    start chain = going below,
    base/.style = {draw, rounded corners,
                   minimum width=20mm, minimum height=4mm,
                   align=center,
                   inner sep=1mm, outer sep=0mm,
                   },
     box/.style = {base, on chain, join=by {->}},
   start/.style = {box,minimum size=2mm,circle,fill=black},
     end/.style = {box,circle, on chain},
decision/.style = {box, diamond, aspect=1,
                   rounded corners=0pt, minimum size=2mm}
   ]
\definecolor{noteBackgroundColor}{RGB}{251,251,119}
\definecolor{noteBorderColor}{RGB}{168,0,54}

\node[start] (A) {};
\node[box] (B) {clone repository};
\ann[right=9mm of B]{182:8mm}{git clone url/to/repository \\scp -p url/to/hooks/commit\_msg repository/.git/hooks};
\node[box] (C) {coding};
\node[box] (D) {commit locally};
\ann[right=9mm of D]{182:8mm}{git add xxx \\ git commit};
\node[box] (E) {review};
\ann[right=9mm of E]{182:8mm}{git push origin refs/for/branch};
\node[decision] (F) {};
{[start branch]
  \node[box,left=2cm of F] (G) {rework};
  \node[box,on chain=going above] (H) {recommit};
  \ann[above=5mm of H]{270:4mm}{git add xxx \\ git commit --amend};
}
{[start branch]
  \node[box,right=6cm of F] (I) {submit};
  \ann[below=5mm of I]{90:4mm}{click "submit" on corresponding gerrit page};

  \node[base]  (J)  at (I |- C) {update local repository};
  \ann[right=9mm of J]{182:8mm}{git pull --rebase};
}
\draw[->] (H) -- (E);
\draw[->] (F) -- (I);
\draw[->] (J) --node [above] {get another task(new cycle)} (C);
\draw[red,->] (I) edge (J) (J) to (C);
\end{tikzpicture}
\end{document}

输出:

【讨论】:

    【解决方案2】:

    这是你真正需要的吗?

    制作这种图片没有什么神奇的,但要仔细调整箭头的长度。您可以填写“ ”来扩展箭头。

    源代码:

    @startuml
    skinparam linetype ortho
    
    (*) -down-> "clone repository"
    note right
    A:git clone url/to/repository
    scp -p url/to/hooks/commit_msg repository/.git/hooks
    end note
    -down->[get an assignment] "coding"
    -down-> "commit locally"
    note right
    B:git add xxx
    git commit
    end note
    -down-> "review"
    note right
    C:git push origin refs/for/<branch>
    end note
    if "" then
      -left->[ rejected] "rework"
      -up-> "recommit"
    'note left
    'D:git add xxx
    'git commit --amend
    'end note
      -right-> [       ]"review"
    else
      --right-->[                              approved                              ] "submit"
    note right: E:click "submit" on on corresponding gerrit page
      -up-> "update local repository"
    note right
    F:git pull --rebase
    end note
      -left->[              get another task(a new cycle)] "coding"
    @enduml
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-24
      • 2023-04-02
      • 2022-11-23
      • 1970-01-01
      • 2022-08-24
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      相关资源
      最近更新 更多