Jackson結構化程式圖(格式化樹狀圖)

Jackson結構化程式圖(格式化樹狀圖)

我正在嘗試創建一個傑克森結構化程式設計圖表。這基本上是一個簡單的樹狀圖,但框的右上角可以有一個圓圈 (O) 或一個星號 (*)。我正在使用 TikZ 庫作為圖表,但我不知道如何擴展樣式來實現這一點。這是未完成的圖:

\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows}

\begin{document}
\begin{center}
\begin{tikzpicture}[
    box/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
    circle/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
    %SHOULD CONTAIN THE CIRCLES
    star/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
     %SHOULD CONTAIN THE STARS       
]
\node (State00) [box] {Jackson Diagramm}
 [sibling distance=3cm]
    child {node (a) [box] {int a = 1}}
    child {node (a) [box] {boolean n = true}}
    child {node (a) [box] {boolean z = true}}
    child {[sibling distance=4cm] node (d) [circle] {if (n)}
        child{  [sibling distance=3cm] node (e) [star] {while (z)}
        child {node (f) [box] {n = !z}}
        child {node (g) [box] {a++}}
        child { [sibling distance=4cm] node (h) [circle] {a <= 10}
                child {node (i) [box] {z = true}}
                child {node (j) [box] {System.out.println( "z\(>\)10")}}
            }
        }
        child {node (k) [box] {System.out.println(a)}} 
        child {node (l) [box] {System.out.println(z)}}      
    } 
;
\end{tikzpicture}
\end{center}
\end{document}

電流輸出:

在此輸入影像描述

答案1

您可以使用label={[xshift=-1.25em, yshift=-2.25ex]north east:$\ast$}在節點內放置其他圖形:

在此輸入影像描述

筆記:

  • 我更改了顏色,以便更容易看到特殊節點的位置。

代碼:

\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows}

\begin{document}
\begin{center}
\begin{tikzpicture}[
    box/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue!25, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
    circle/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=green!25, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=black, label={[xshift=-1.25em, yshift=-2.25ex]north east:$\circ$}},
    %SHOULD CONTAIN THE CIRCLES
    star/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=red!25, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=black, label={[xshift=-1.25em, yshift=-2.25ex]north east:$\ast$}},
     %SHOULD CONTAIN THE STARS       
]
\node (State00) [box] {Jackson Diagramm}
 [sibling distance=3cm]
    child {node (a) [box] {int a = 1}}
    child {node (a) [box] {boolean n = true}}
    child {node (a) [box] {boolean z = true}}
    child {[sibling distance=4cm] node (d) [circle] {if (n)}
        child{  [sibling distance=3cm] node (e) [star] {while (z)}
        child {node (f) [box] {n = !z}}
        child {node (g) [box] {a++}}
        child { [sibling distance=4cm] node (h) [circle] {a <= 10}
                child {node (i) [box] {z = true}}
                child {node (j) [box] {System.out.println( "z\(>\)10")}}
            }
        }
        child {node (k) [box] {System.out.println(a)}} 
        child {node (l) [box] {System.out.println(z)}}      
    } 
;
\end{tikzpicture}
\end{center}
\end{document}

答案2

這是一種不同的方法,即path picture金鑰和path picture bounding box偽節點。

我清理了樣式定義並特別重命名了樣式,因為已經存在可能導致混亂的circle形狀。circle

我已將圓直接放在圓角中(當然您可以調整移位以將其進一步移動到節點的中心)。

starred樣式接受一個可選參數(預設值:5),表示角的數量。外角的半徑為1mm,內角的半徑為.5mm

程式碼

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning,shadows}

\begin{document}
\begin{tikzpicture}[
  box/.style={
    shape=rectangle,
    draw=red!50!black!50,
    rounded corners=1mm,
    fill=blue,
    drop shadow,
    minimum width=5em,
    minimum height=3em,
    level distance=10cm,
    text centered,
    anchor=north,
    text=white
    },
  circled/.style={
    box,
    path picture={
      \path[draw=red!50!black!50, fill=blue!50] ([shift={(-1mm,-1mm)}]path picture bounding box.north east) circle[radius = 1mm];
    }
  },
  starred/.style={
    box,
    path picture={
       \path[sharp corners,draw=red!50!black!50, fill=blue!50,] ([shift={(-1.5mm,-1.5mm)}]path picture bounding box.north east) + (1/#1*360+90:1mm) \foreach \i in {1,...,#1} {-- + (\i/#1*360+90:1mm) -- + (\i.5/#1*360+90:.5mm)} -- cycle;
    }
  },
  starred/.default=5,% default number of corners
]
\node (State00) [box] {Jackson Diagramm}
 [sibling distance=3cm]
    child {node (a) [box] {int a = 1}}
    child {node (a) [box] {boolean n = true}}
    child {node (a) [box] {boolean z = true}}
    child {[sibling distance=4cm] node (d) [circled] {if (n)}
        child{  [sibling distance=3cm] node (e) [starred] {while (z)}
        child {node (f) [box] {n = !z}}
        child {node (g) [box] {a++}}
        child { [sibling distance=4cm] node (h) [circled] {a <= 10}
                child {node (i) [box] {z = true}}
                child {node (j) [box] {System.out.println( "z\(>\)10")}}
            }
        }
        child {node (k) [box] {System.out.println(a)}} 
        child {node (l) [box] {System.out.println(z)}}      
    } 
;
\end{tikzpicture}
\end{document}

輸出

在此輸入影像描述

相關內容