0

I applied the following code to draw a feature diagram. I would like to add an Alternative symbol (unfilled angle) to a legend as appears in the image. Can you help with that

\documentclass[border=10pt,tikz,multi]{standalone}
\usetikzlibrary{angles,shadows.blur,positioning,backgrounds}
\usepackage{forest}
\forestset{
  declare count register=disjuncts from,
  disjuncts from'=0,
  declare count register=concrete from,
  concrete from'=2,
  concrete colour/.code={\colorlet{concretecol}{#1}},
  abstract colour/.code={\colorlet{abstractcol}{#1}},
  draw colour/.code={\colorlet{drawcol}{#1}},
  concrete colour=gray,
  abstract colour=white,
  draw colour=black,
  /tikz/mandatory/.style={circle, fill=drawcol, draw=drawcol},
  /tikz/optional/.style={circle, draw=drawcol, fill=white},
  /tikz/concrete/.style={fill=concretecol, draw=drawcol},
  /tikz/abstract/.style={fill=abstractcol, draw=drawcol},
  /tikz/or/.style={},
  mandatory/.style={edge label={node [mandatory] {}}},
  optional/.style={edge label={node [optional] {}}},
  or/.style={for first={disjunct}},
  disjunct/.style={
    tikz+={\path (.parent) coordinate (A) -- (!u.children) coordinate (B) -- (!ul.parent) coordinate (C) pic [fill=drawcol] {angle};}
  },
  disjunction tree/.style={
    where={isodd(n_children())}{
      for n={int((n_children()+1)/2)}{calign with current},
    }{
      calign=midpoint,
    },
    before typesetting nodes={
      for nodewalk={
        filter/.wrap pgfmath arg={{level>=##1}{n_children()>1}}{(disjuncts_from)}
      }{
        or,
      },
      where={level()>=(concrete_from)}{
        concrete,
      }{
        abstract,
      },
      tikz+={
        [font=\sffamily]
        \node (l) [anchor=north west, xshift=10pt] at (current bounding box.north east) {Legend};
        \foreach \i/\j [remember=\i as \k (initially l)] in {mandatory/Mandatory,optional/Optional,or/Or,abstract/Abstract,concrete/Concrete}
        {
          \node (\i) [below=20pt of \k.north, anchor=north, text centered, \i, minimum width=5pt,] {};
          \node (\j) [right=15pt of \i.center -| mandatory.west, anchor=west] {\j};
        };
        \draw [drawcol] (or.south west) coordinate (A) -- (or.north) coordinate (B) -- (or.south east) coordinate (C) pic [fill=drawcol, angle radius=5pt] {angle};
        \foreach \i in {mandatory,optional} \draw [darkgray] (\i.north east) -- +(45:5pt);
        \node (c) [below=0pt of Concrete.south] {};
        \scoped[on background layer]{\node [draw, fill=white, blur shadow, fit=(l) (Mandatory) (Optional) (Or) (Abstract) (Concrete) (c), rounded corners] {};}
      },
    },
    for tree={
      parent anchor=children,
      child anchor=parent,
      l'+=10mm,
      blur shadow,
      rounded corners,
      text height=2ex,
      text depth=.5ex,
      font=\sffamily,
    },
  },
}
\begin{document}
\begin{forest}% addaswyd o gôd Salim Bou: https://tex.stackexchange.com/a/335782/
  disjunction tree,
  disjuncts from'=1,
  concrete from'=1,
  concrete colour=blue!85!cyan!40,
  abstract colour=blue!85!cyan!15,
  draw colour=darkgray,
  [Emergency Response System
    [User interface, mandatory]
    [Inform emergency,  mandatory
      [Inform Earthquake, abstract colour=blue!85!cyan!15]
      [Inform flood]
    ]
    [Display neighbourhood, mandatory
      [Map
        [Display danger zone]
        [Display safe zone]
        [Display path to safe zone]
      ]
      [Textual direction]
    ]
    [Shortcut calls, optional
      [Cops]
      [Ambulance]
      [Fireman]
    ]
  ]
\end{forest}
\end{document}

enter image description here

2
2

I don't know anything about forest, but I do know how to use saveboxes and tikz.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,shadows.blur,positioning,backgrounds,arrows.meta}
\usepackage{forest}
\forestset{
  declare count register=disjuncts from,
  disjuncts from'=0,
  declare count register=concrete from,
  concrete from'=2,
  concrete colour/.code={\colorlet{concretecol}{#1}},
  abstract colour/.code={\colorlet{abstractcol}{#1}},
  draw colour/.code={\colorlet{drawcol}{#1}},
  concrete colour=gray,
  abstract colour=white,
  draw colour=black,
  /tikz/mandatory/.style={circle, fill=drawcol, draw=drawcol},
  /tikz/optional/.style={circle, draw=drawcol, fill=white},
  /tikz/concrete/.style={fill=concretecol, draw=drawcol},
  /tikz/abstract/.style={fill=abstractcol, draw=drawcol},
  /tikz/or/.style={},
  mandatory/.style={edge label={node [mandatory] {}}},
  optional/.style={edge label={node [optional] {}}},
  or/.style={for first={disjunct}},
  disjunct/.style={
    tikz+={\path (.parent) coordinate (A) -- (!u.children) coordinate (B) -- (!ul.parent) coordinate (C) pic [fill=drawcol] {angle};}
  },
  disjunction tree/.style={
    where={isodd(n_children())}{
      for n={int((n_children()+1)/2)}{calign with current},
    }{
      calign=midpoint,
    },
    before typesetting nodes={
      for nodewalk={
        filter/.wrap pgfmath arg={{level>=##1}{n_children()>1}}{(disjuncts_from)}
      }{
        or,
      },
      where={level()>=(concrete_from)}{
        concrete,
      }{
        abstract,
      },
%
    },
    for tree={
      parent anchor=children,
      child anchor=parent,
      l'+=10mm,
      blur shadow,
      rounded corners,
      text height=2ex,
      text depth=.5ex,
      font=\sffamily,
    },
  },
}
\begin{document}
\bgroup
\sbox0{%
\begin{forest}% addaswyd o gôd Salim Bou: https://tex.stackexchange.com/a/335782/
  disjunction tree,
  disjuncts from'=1,
  concrete from'=1,
  concrete colour=blue!85!cyan!40,
  abstract colour=blue!85!cyan!15,
  draw colour=darkgray,
  [Emergency Response System
    [User interface, mandatory]
    [Inform emergency,  mandatory
      [Inform Earthquake, abstract colour=blue!85!cyan!15]
      [Inform flood]
    ]
    [Display neighbourhood, mandatory
      [Map
        [Display danger zone]
        [Display safe zone]
        [Display path to safe zone]
      ]
      [Textual direction]
    ]
    [Shortcut calls, optional
      [Cops]
      [Ambulance]
      [Fireman]
    ]
  ]
\end{forest}}%
%
\sbox1{\begin{tabular}{clclcl}
\tikz{\draw (0,0) node[circle,fill=black,inner sep=.5ex] (A) {} (A.north) -- (0,2ex);} & Mandatory &
\tikz{\draw (0,0) coordinate(A) -- (2ex,2ex) coordinate(B) -- (4ex,0) coordinate(C)
  pic[draw, angle radius=1.5ex] {angle=A--B--C};} & Alternative &
\tikz{\draw[dashed,-latex] (0,0) (0,1ex) -- (2em,1ex);} & Requires \\
\tikz{\draw (0,0) node[circle,draw,inner sep=.5ex] (A) {} (A.north) -- (0,2ex);} & Optional &
\tikz{\draw (0,0) coordinate(A) -- (2ex,2ex) coordinate(B) -- (4ex,0) coordinate(C)
  pic[fill=black, angle radius=1.5ex] {angle=A--B--C};} & Or &
\tikz{\draw[dashed,latex-latex] (0,0) (0,1ex) -- (2em,1ex);} & Excludes \\
\end{tabular}}%
%
\begin{tikzpicture}
  \node (forest){\usebox0};
  \node[below=2ex,draw,rounded corners] at (forest.south) {\usebox1};
\end{tikzpicture}
\egroup
\end{document}

demo

1
  • It may be possible to incorporate a new symbol (or savebox) into a normal legend. At the moment I seem to have lost my pgfplots manual. – John Kormylo Jun 21 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.