Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plantuml - draw note above activity diagram

Tags:

plantuml

I found a good activity diagram at here but no source code.it looks like below: enter image description here

I try to draw it with plantuml, below is my code:

@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

The output is: enter image description here

Obviously, still not as original diagram:

  1. Notes above/below doesn't work, not sure how to do it (such as E note should below)
  2. The center flow not in straight line.
  3. The "submit" to "update local repository" has changed 2 times.

How can I improve it just the same as original output?

like image 881
beetlej Avatar asked Jul 12 '17 03:07

beetlej


People also ask

How do I add a note in PlantUML?

It is possible to put notes on message using the note left or note right keywords just after the message. You can have a multi-line note using the end note keywords. It is also possible to place notes relative to participant with note left of , note right of or note over keywords.

How do you align components in PlantUML?

If we want to have our text left aligned we use \l instead of \n . And to right align the text we use \r . Written with PlantUML 1.2017. 16.

How do I change the color of my PlantUML notes?

You can change colors and font of the drawing using the skinparam command.

How do you make a box in PlantUML?

It is possible to draw a box around some participants, using box and end box commands. You can add an optional title or a optional background color, after the box keyword. It is also possible to nest boxes - to draw a box within a box - when using the teoz rendering engine, for example: 🎉 Copied!


2 Answers

plantuml will place node automatically, if you want to put node on precise position, TikZ can probably do better:

\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}

Output:

enter image description here

like image 133
lucky1928 Avatar answered Nov 06 '22 22:11

lucky1928


Is this what you need actuelly? enter image description here

There is no magic to create this kind of pic but to adjust the length of arrow carefully. You can fullfill " " to extend the arrows.

source code:

@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
like image 43
Zhi Yuan Avatar answered Nov 06 '22 22:11

Zhi Yuan