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}

산출

여기에 이미지 설명을 입력하세요

관련 정보