5

I haven't found any example of using TikZ for drawing Harel's statecharts notation. There are numerous examples of finite-state automata, but that cannot be applied for statecharts for two reasons: no hierarchy and no orthogonality. Can anyone suggest me please what is the best way to draw something as simple as this:

(A) --> (B(D) | C(E)),

where there are two top-level states: A and B|C (state with two orthogonal regions B and C, divided by a dashed line in the middle of state); B has a nested state D, whereas C has a nested state E; interlevel connections should be possible, i.e. a directed connection between A and C.

Edited: here's the picture

enter image description here

3
  • 1
    Welcome to TeX.sx!
    – lockstep
    Oct 18, 2012 at 14:02
  • I could not see exactly what you are asking for. Could you put a picture that shows what you want? can be done in any editor. But I think you can not add the sample directly into the post, then let it anywhere on the internet and bring the link to us. =)
    – tcpaiva
    Oct 18, 2012 at 14:06
  • 1
    Welcome to LaTeX! As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again until you get more rep points.
    – percusse
    Oct 18, 2012 at 14:07

1 Answer 1

6

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{fit,arrows,calc}

\begin{document}

\begin{tikzpicture}
[   round/.style={rounded corners=1.5mm,minimum width=1cm,inner sep=2mm,above right,draw,align=left,text width=7mm}
]
    \node[round] (D) at (0,0) {D};
    \node[round] (E) at (2,0) {E};
    \node[above right,inner sep=2mm] (B) at (0,1) {B};
    \node[above right,inner sep=2mm] (C) at (2,1) {C};
    \node[round,fit=(B)(C)(D)(E)] (BC) {};
        \draw[densely dashed] (BC.north) -- (BC.south);
    \node[round] (A) at (2.5,2.5) {A};
    \draw[-latex] (A) to[out=180, in=90] (D);
    \draw[-latex] ($(BC.north east)+(-0.3,-0.3)$) coordinate (temp) to[out=180,in=90] (E);
        \fill (temp) circle (0.05);
\end{tikzpicture}

\end{document}

Output

enter image description here

4
  • wow, thats looks very nice.
    – Thomas
    Oct 18, 2012 at 16:10
  • Thanks, the fit library is very nice for such things. Oct 18, 2012 at 16:12
  • Tom, thank you very much! Looks very nice indeed:)Would you be so kind to explain me how the semantic relationship between the orthogonal states and their substates is expressed, e.g. between B and D. I can clearly see the realtionship between BC and substates defined using fit library, but not the former.
    – Vitaly
    Oct 18, 2012 at 16:21
  • I used absolute positions, so B is placed at (0,1) and D is placed at (0,0). So B is simply put (manually) above D. You can also have a look at the positioning library for relative positioning, for e.g. \node[above right,inner sep=2mm,above of=1cm of D] (B) {B};. Oct 18, 2012 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .